For center a string in pdf file page is need calculate the coordinates.
In the method TextOut( cString, lNewLine, lUpdatePosX, nAlign ) of WIN_PRN class, the nAlign parameter is the point inside text
rectangle of cString parameter to determine the print coordinates PosX, PosY.
Try this example, I hope that is clearer.-
#include "hbwin.ch"
Procedure Main()
Local nPosX, nPosY, nRow, nCol
Local cString, lNewLine, lUpdatePosX, nAlign
WITH OBJECT Win_Prn():New( "PDFCreator" )
if :Create() .and. :StartDoc()
nPosX := (:LeftMargin + :RightMargin) / 2 // X Page Center
nPosY := (:TopMargin + :BottomMargin) / 2 // Y Page Center
cString := "Te�st"
nAlign := hb_BitOr( WIN_TA_BASELINE, WIN_TA_CENTER ) // Y X Center
:SetPos( nPosX, nPosY ); :TextOut( cString, lNewLine, lUpdatePosX, nAlign )
nRow := nCol := 10
cString := ".Test"
nAlign := hb_BitOr( WIN_TA_BOTTOM, WIN_TA_LEFT ) // Default Normal
:SetPrc( nRow, nCol ); :TextOut( cString, lNewLine, lUpdatePosX, nAlign )
cString := " Te.st"
nAlign := hb_BitOr( WIN_TA_BOTTOM, WIN_TA_CENTER ) // Special
:SetPrc( ++nRow, nCol ); :TextOut( cString, lNewLine, lUpdatePosX, nAlign )
cString := ".Test" // Default
:SetPrc( ++nRow, nCol ); :TextOut( cString )
? "Ok"
else
? "Error"
endif
END
Wait
return
HTH,
Merry Christmas and a Happy New Year.
--
Xavi
El 25/12/2010 21:07, jparada escribi�:
I am not sure but I am using LibHaru for PDF creation and after some
hardwork I now belive that "maybe" it is a better option but I can't really
say that because that may have advantages using your way with pdfcreator.
Please give a look at the nice example you find under
\contrib\hbhpdf\tests
Just an idea...
Qatan
Hi,
#include "hbwin.ch"
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
I understand you.
I have an example of a form that I had to develop and here I will show
you a simple example with some functions created by me to help the task and
reduce some code.
Compile it with hbmk2 example -lhbhpdf -llibhpdf -lpng -w0
It will create a file named example.pdf with some boxes and text (some
centered).
I hope it will help you.
Qatan
[code]
/*
example.prg
*/
#include 'harupdf.ch'
procedure main()
local pdf := HPDF_New()
HPDF_SetCompressionMode( pdf, HPDF_COMP_ALL )
HPDF_Page_SetSize( pdf, 4, 1 ) // A4 Portrait 595x841
HPDF_SetPageMode( pdf, HPDF_PAGE_MODE_USE_OUTLINE )
page := HPDF_AddPage( pdf )
HPDF_Page_SetLineWidth( page, 0.5 )
line( page, 817, 20, 555 )
line( page, 797, 20, 465 )
line( page, 767, 20, 555 )
line( page, 762, 20, 555, .T. )
line( page, 755, 20, 555 )
line( page, 720, 351, 224 )
line( page, 700, 351, 224 )
line( page, 665, 20, 555 )
line( page, 645, 20, 555 )
line( page, 625, 20, 555 )
colu( page, 20, 625, 130 )
colu( page, 260, 665, 90 )
colu( page, 205, 625, 20 )
colu( page, 351, 645, 110 )
colu( page, 390, 625, 20 )
colu( page, 575, 625, 130 )
colu( page, 20, 767, 50 )
colu( page, 198, 767, 30 )
colu( page, 485, 767, 50 )
colu( page, 575, 767, 50 )
HPDF_Page_Rectangle( page, 329, 710, 10, 10 )
HPDF_Page_Stroke( page )
def_font1 := HPDF_GetFont( pdf, "Times-Roman", "WinAnsiEncoding" )
def_font2 := HPDF_GetFont( pdf, "Times-Bold", "WinAnsiEncoding" )
HPDF_Page_BeginText( page )
// 595x841
HPDF_Page_SetFontAndSize( page, def_font2, 10 )
texto( page, 485, 803, '-*-O-*-', 575 ) // centralizing text
HPDF_Page_SetFontAndSize( page, def_font1, 6 )
texto( page, 20, 791, 'TEST TEST' )
texto( page, 198, 791, 'NNNN NNNNNN NNNNNNNNNNN NNNNNN NNN' )
texto( page, 20, 749, 'XHXHXHXHXH XHXHXHXHXHX HXHHXHXHXHXH XH XH' )
texto( page, 351, 714, 'JFJFDJFDJFDJFJFJ FJ FJ FJ FJFJFJFJFJFJFJ FJ F' )
HPDF_Page_SetFontAndSize( page, def_font2, 12 )
texto( page, 260, 745, 'CENTER', 351 )
HPDF_Page_SetFontAndSize( page, def_font1, 8 )
texto( page, 260, 735, 'Center here too ', 351 )
texto( page, 260, 727, 'here a bit more or center', 351 )
texto( page, 270, 714, '1 - Option' )
texto( page, 270, 706, '2 - Other' )
HPDF_Page_SetFontAndSize( page, def_font1, 7 )
texto( page, 351, 689, 'Some centered text to text our little Harbour
program', 575 )
texto( page, 351, 680, 'note that you can create simple functions', 575 )
texto( page, 351, 671, 'to help you do that', 575 )
HPDF_Page_SetFontAndSize( page, def_font1, 6 )
texto( page, 20, 659, 'NKFDKDFKFDK FDKLFDKFDKLDF' )
texto( page, 351, 659, 'XNXNXNX NXNXNXNXNXNXNXNNX NX NXNXNXNX' )
texto( page, 20, 639, 'IUIIUIUIUIUI U IUIUIUIUIUIUIU IUIIU' )
texto( page, 205, 639, 'DKDKDKDKD KDK DK DKDKDKDKDKDKDK D KDK' )
texto( page, 390, 639, 'XXXXXXXXXXXXXXXX' )
HPDF_Page_EndText( page )
HPDF_SaveToFile( pdf, 'example.pdf' )
HPDF_Free( pdf )
return NIL
////////////////////////////////////////////////////////////////////////////
static function line( page, line, ini, tam, picote )
picote := if(picote = NIL, .F., picote)
if picote
HPDF_Page_SetDash(page, {3}, 1, 1)
endif
HPDF_Page_MoveTo( page, ini, line )
HPDF_Page_LineTo( page, ini+tam, line )
HPDF_Page_Stroke(page)
if picote
HPDF_Page_SetDash(page, NIL, 0, 0)
endif
return NIL
////////////////////////////////////////////////////////////////////////////
static function colu( page, col, ini, tam, picote )
picote := if(picote = NIL, .F., picote)
if picote
HPDF_Page_SetDash(page, {3}, 1, 1)
endif
HPDF_Page_MoveTo( page, col, ini )
HPDF_Page_LineTo( page, col, ini+tam )
HPDF_Page_Stroke(page)
if picote
HPDF_Page_SetDash(page, NIL, 0, 0)
endif
return NIL
////////////////////////////////////////////////////////////////////////////
static function texto( page, col, lin, texto, fim, direita )
local tw
direita := if( direita = NIL, .F., direita )
if fim = NIL
col += 2
elseif ! direita
tw := HPDF_Page_TextWidth( page, texto )
col += ( ( fim - col ) / 2 ) - ( tw / 2 )
endif
if direita
tw := HPDF_Page_TextWidth( page, texto )
col -= tw + 4
endif
HPDF_Page_TextOut( page, col, lin, texto )
return NIL
[/code]
Hi,
Thanks for answering
@Xavi
@Qatan
Best Regards,
Javier
> cString := "Te�st"
> El 25/12/2010 21:07, jparada escribi�: