pdf grid

Moderator: Rathinagiri

User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

pdf grid

Post by jairpinho »

I need to do a grid with scales in pdf, I followed an example of harupdf but I can not close the grid border and position it in x, y in pdf I do not know where to modify to happen
samplejpg_Page1.jpg
samplejpg_Page1.jpg (24.69 KiB) Viewed 8414 times

Code: Select all

Function Drawtext1()
Local i
/*
SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
*/
cArquivo:= DiskName()+ ":\"+CurDir() + "\sample"+ ".pdf" 
   SELECT HPDFDOC cArquivo TO lSuccess ORIENTATION HPDF_ORIENT_LANDSCAPE PAPERSIZE HPDF_PAPER_A4
   
   SET HPDFDOC  COMPRESS ALL
   SET HPDFDOC  PAGEMODE TO OUTLINE
   SET HPDFINFO AUTHOR      TO 'Jair Pinho'
   SET HPDFINFO CREATOR     TO 'Jair Pinho'
   SET HPDFINFO TITLE      TO 'Relaório'
   SET HPDFINFO SUBJECT     TO 'Criado com LibHaru/HPDF Library'
   SET HPDFINFO KEYWORDS    TO 'HMG, HPDF, Documentation, LibHaru, Harbour, MiniGUI'
   SET HPDFINFO DATECREATED TO date() TIME time()
   SET HPDFDOC  ENCODING TO "WinAnsiEncoding"
   
START HPDFDOC
    START HPDFPAGE
	SET HPDFDOC PAGEOUTLINE TITLE "Sample" 	    
		//@ 10,10 HPDFPRINT "Rotate Demo"
		//@ 10,10 HPDFPRINT LINE TO  10, 100 PENWIDTH 0.15 COLOR RED 
/*		
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 90 ) 
		HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 180)
        HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 270)
		HPDF_RotateText( 50, 80, "ABCxyz123", Nil, Nil, 0 )
	
	FOR i=100 TO 300 STEP 10
		@i,10 HPDFPRINt "Happy HMG"
	NEXT i

	FOR i=0 To 345 STEP 15
		@ i,_HMG_HPDF_Pixel2MM(150) HPDFPRINT LINE TO  150, 10 PENWIDTH 0.15 COLOR RED 	
		HPDF_RotateText( 150, 150, "Happy HMG", Nil, 10, i )
	NEXT i	

	*/
//print_grid( nRow,nCol, height, width, nSpaceLine_X,nSpaceLine_Y,nSpaceText_X,nSpaceText_Y, nTag_x,nTag_Y )	
	print_grid( 50,150, 160, 200, 5, 5, 20 , 20 , 10 , 10 )
	

    END HPDFPAGE
        

END HPDFDOC
Execute File 'sample.pdf'
Return Nil

*------------------------------------------------------------------------*
Function print_grid( nRow,nCol, height, width, nScaleLine_X,nScaleLine_Y,nScaleText_X,nScaleText_Y, nTag_x,nTag_Y )
*------------------------------------------------------------------------*
   Local  font,x,y
   Local Pdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local Page       := _HMG_SYSDATA[ 150 ][ 7 ]  

    font = HPDF_GetFont (pdf, "Helvetica", Nil)

    HPDF_Page_SetFontAndSize (page, font, 5)
    HPDF_Page_SetGrayFill (page, 0.5)
    HPDF_Page_SetGrayStroke (page, 0.8)

    /* Draw horizontal lines */
    y := 0 // distabcia inicio primeira linha
    while (y < height)
        if  (y % (nScaleLine_Y*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
           if (HPDF_Page_GetLineWidth (page) != 0.25)
              HPDF_Page_SetLineWidth (page, 0.25)
           Endif
        Endif

        HPDF_Page_MoveTo (page, 0, y)
        HPDF_Page_LineTo (page, width, y)
        HPDF_Page_Stroke (page)

        if (y % nTag_Y == 0 .and. y > 0)
            HPDF_Page_SetGrayStroke (page, 0.5)

            HPDF_Page_MoveTo (page, 0, y)
            HPDF_Page_LineTo (page, nScaleLine_Y, y)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        y += nScaleLine_Y
    End

    /* Draw vertical lines */
    x := 0 //distabcia inicio primeira linha
    while (x < width)
        if (x % (nScaleLine_X*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
            if (HPDF_Page_GetLineWidth (page) != 0.25)
                HPDF_Page_SetLineWidth (page, 0.25)
            Endif
        Endif

        HPDF_Page_MoveTo (page, x, 0)
        HPDF_Page_LineTo (page, x, height)
        HPDF_Page_Stroke (page)

        if (x % nTag_X == 0 .and. x > 0)  // linha de referencia com a tag texto linha mais forte
            HPDF_Page_SetGrayStroke (page, 0.5)

            //tag esquerda
			HPDF_Page_MoveTo (page, x, 0)
            HPDF_Page_LineTo (page, x, nScaleLine_X )
            HPDF_Page_Stroke (page)

            //tag direita
			HPDF_Page_MoveTo (page, x, height)
            HPDF_Page_LineTo (page, x, height - nScaleLine_X)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        x += nScaleLine_X
    End

    /* Draw horizontal text */

    y := 0 //distabcia inicio texto
    while (y < height)
        if (y % (nScaleText_Y) == 0 .and. y > 0)
            HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, 5, y - 2)
            HPDF_Page_ShowText (page, ltrim(str(Y)))
            HPDF_Page_EndText (page)
        Endif

        y += nScaleText_Y
    End


    /* Draw virtical text */

    x := 0
    while (x < width)
        if (x % (nScaleText_X) == 0 .and. x > 0)

            //tag em baixo
			HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x, 5)
            HPDF_Page_ShowText (page, ltrim(str(x)))
            HPDF_Page_EndText (page)

            //tag em cima
			HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x, height - 10)
            HPDF_Page_ShowText (page, ltrim(str(x)))
            HPDF_Page_EndText (page)
        Endif

        x += nScaleText_X
    End

    HPDF_Page_SetGrayFill (page, 0)
    HPDF_Page_SetGrayStroke (page, 0)

	
	

Return Nil


Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: pdf grid

Post by edk »

Here you are, anything else :?:

Code: Select all

#include "hmg.ch"

Function Main()
Local i, lSuccess

SELECT HPDFDOC "sample.pdf" TO lSuccess ORIENTATION HPDF_ORIENT_LANDSCAPE PAPERSIZE HPDF_PAPER_A4
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE
	    

	print_grid( 0, 0, HPDF_Page_GetHeight (_HMG_SYSDATA[ 150 ][ 7 ]), HPDF_Page_GetWidth (_HMG_SYSDATA[ 150 ][ 7 ]), 5, 5, 50 , 50 , 10 , 10 )

	@10,10 HPDFPRINT "Grid Demo Page 1"
    END HPDFPAGE    
    
    START HPDFPAGE
	
	@10,10 HPDFPRINT "Grid Demo Page 2"
	print_grid( 400, 150, 160, 200, 5, 5, 20 , 20 , 10 , 10 )
	

    END HPDFPAGE
        

END HPDFDOC

IF lSuccess
   Execute File 'sample.pdf'
ENDIF	

Return Nil

*------------------------------------------------------------------------*
Function print_grid( nRow, nCol, height, width, nScaleLine_X, nScaleLine_Y, nScaleText_X, nScaleText_Y, nTag_x, nTag_Y )
*------------------------------------------------------------------------*
   Local  font,x,y, cLabel, nLabWidth
   Local Pdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local Page       := _HMG_SYSDATA[ 150 ][ 7 ]  
   Local nFontSize   := 5

    font = HPDF_GetFont (pdf, "Helvetica", Nil)

    HPDF_Page_SetFontAndSize (page, font, nFontSize)
    HPDF_Page_SetGrayFill (page, 0.5)
    HPDF_Page_SetGrayStroke (page, 0.8)


    /* Draw horizontal lines */
    y := 0 // distabcia inicio primeira linha
    while (y <= height )
        if  (y % (nScaleLine_Y*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
           if (HPDF_Page_GetLineWidth (page) != 0.25)
              HPDF_Page_SetLineWidth (page, 0.25)
           Endif
        Endif

        HPDF_Page_MoveTo (page, nCol, y + nRow)
        HPDF_Page_LineTo (page, width + nCol, y + nRow)
        HPDF_Page_Stroke (page)

        if (y % nTag_Y == 0 .and. y > 0)
            HPDF_Page_SetGrayStroke (page, 0.5)

            HPDF_Page_MoveTo (page, nCol, y + nRow)
            HPDF_Page_LineTo (page, nScaleLine_Y + nCol , y + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        y += nScaleLine_Y
    End

    /* Draw vertical lines */



    x := 0 //distabcia inicio primeira linha
    while (x <= width)
        if (x % (nScaleLine_X*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
            if (HPDF_Page_GetLineWidth (page) != 0.25)
                HPDF_Page_SetLineWidth (page, 0.25)
            Endif
        Endif

        HPDF_Page_MoveTo (page, x + nCol, nRow)
        HPDF_Page_LineTo (page, x + nCol, height + nRow)
        HPDF_Page_Stroke (page)

        if (x % nTag_X == 0 .and. x > 0)  // linha de referencia com a tag texto linha mais forte
            HPDF_Page_SetGrayStroke (page, 0.5)

            //tag esquerda
	    HPDF_Page_MoveTo (page, x + nCol, nRow)
            HPDF_Page_LineTo (page, x + nCol, nScaleLine_X + nRow )
            HPDF_Page_Stroke (page)

            //tag direita
	    HPDF_Page_MoveTo (page, x + nCol, height + nRow)
            HPDF_Page_LineTo (page, x + nCol, height - nScaleLine_X + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        x += nScaleLine_X
    End



    /* Draw horizontal text */


    y := 0 //distabcia inicio texto
    while (y < height)
        if (y % (nScaleText_Y) == 0 .and. y > 0)
	    cLabel:=ltrim(str(y))
            HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, nScaleLine_Y + nCol, y + nRow - (nFontSize/2) + .75  /* Middled Label */)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        y += nScaleText_Y
    End


    /* Draw virtical text */

    x := 0
    while (x < width)
        if (x % (nScaleText_X) == 0 .and. x > 0)
            cLabel:=ltrim(str(x))
	    nLabWidth:=HPDF_Page_TextWidth( page, cLabel )

            //tag em baixo
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, nScaleLine_X + nRow + 1)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)

            //tag em cima
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, height - (nScaleLine_X * 2) + nRow)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        x += nScaleText_X
    End

    HPDF_Page_SetGrayFill (page, 0)
    HPDF_Page_SetGrayStroke (page, 0)
	
Return Nil

sample-page-001.jpg
sample-page-001.jpg (137.14 KiB) Viewed 8359 times
sample-page-002.jpg
sample-page-002.jpg (21.48 KiB) Viewed 8359 times
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: pdf grid

Post by jairpinho »

edk wrote: Tue Oct 03, 2017 5:24 pm Here you are, anything else :?:

Code: Select all

#include "hmg.ch"

Function Main()
Local i, lSuccess

SELECT HPDFDOC "sample.pdf" TO lSuccess ORIENTATION HPDF_ORIENT_LANDSCAPE PAPERSIZE HPDF_PAPER_A4
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE
	    

	print_grid( 0, 0, HPDF_Page_GetHeight (_HMG_SYSDATA[ 150 ][ 7 ]), HPDF_Page_GetWidth (_HMG_SYSDATA[ 150 ][ 7 ]), 5, 5, 50 , 50 , 10 , 10 )

	@10,10 HPDFPRINT "Grid Demo Page 1"
    END HPDFPAGE    
    
    START HPDFPAGE
	
	@10,10 HPDFPRINT "Grid Demo Page 2"
	print_grid( 400, 150, 160, 200, 5, 5, 20 , 20 , 10 , 10 )
	

    END HPDFPAGE
        

END HPDFDOC

IF lSuccess
   Execute File 'sample.pdf'
ENDIF	

Return Nil

*------------------------------------------------------------------------*
Function print_grid( nRow, nCol, height, width, nScaleLine_X, nScaleLine_Y, nScaleText_X, nScaleText_Y, nTag_x, nTag_Y )
*------------------------------------------------------------------------*
   Local  font,x,y, cLabel, nLabWidth
   Local Pdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local Page       := _HMG_SYSDATA[ 150 ][ 7 ]  
   Local nFontSize   := 5

    font = HPDF_GetFont (pdf, "Helvetica", Nil)

    HPDF_Page_SetFontAndSize (page, font, nFontSize)
    HPDF_Page_SetGrayFill (page, 0.5)
    HPDF_Page_SetGrayStroke (page, 0.8)


    /* Draw horizontal lines */
    y := 0 // distabcia inicio primeira linha
    while (y <= height )
        if  (y % (nScaleLine_Y*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
           if (HPDF_Page_GetLineWidth (page) != 0.25)
              HPDF_Page_SetLineWidth (page, 0.25)
           Endif
        Endif

        HPDF_Page_MoveTo (page, nCol, y + nRow)
        HPDF_Page_LineTo (page, width + nCol, y + nRow)
        HPDF_Page_Stroke (page)

        if (y % nTag_Y == 0 .and. y > 0)
            HPDF_Page_SetGrayStroke (page, 0.5)

            HPDF_Page_MoveTo (page, nCol, y + nRow)
            HPDF_Page_LineTo (page, nScaleLine_Y + nCol , y + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        y += nScaleLine_Y
    End

    /* Draw vertical lines */



    x := 0 //distabcia inicio primeira linha
    while (x <= width)
        if (x % (nScaleLine_X*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
            if (HPDF_Page_GetLineWidth (page) != 0.25)
                HPDF_Page_SetLineWidth (page, 0.25)
            Endif
        Endif

        HPDF_Page_MoveTo (page, x + nCol, nRow)
        HPDF_Page_LineTo (page, x + nCol, height + nRow)
        HPDF_Page_Stroke (page)

        if (x % nTag_X == 0 .and. x > 0)  // linha de referencia com a tag texto linha mais forte
            HPDF_Page_SetGrayStroke (page, 0.5)

            //tag esquerda
	    HPDF_Page_MoveTo (page, x + nCol, nRow)
            HPDF_Page_LineTo (page, x + nCol, nScaleLine_X + nRow )
            HPDF_Page_Stroke (page)

            //tag direita
	    HPDF_Page_MoveTo (page, x + nCol, height + nRow)
            HPDF_Page_LineTo (page, x + nCol, height - nScaleLine_X + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        x += nScaleLine_X
    End



    /* Draw horizontal text */


    y := 0 //distabcia inicio texto
    while (y < height)
        if (y % (nScaleText_Y) == 0 .and. y > 0)
	    cLabel:=ltrim(str(y))
            HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, nScaleLine_Y + nCol, y + nRow - (nFontSize/2) + .75  /* Middled Label */)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        y += nScaleText_Y
    End


    /* Draw virtical text */

    x := 0
    while (x < width)
        if (x % (nScaleText_X) == 0 .and. x > 0)
            cLabel:=ltrim(str(x))
	    nLabWidth:=HPDF_Page_TextWidth( page, cLabel )

            //tag em baixo
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, nScaleLine_X + nRow + 1)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)

            //tag em cima
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, height - (nScaleLine_X * 2) + nRow)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        x += nScaleText_X
    End

    HPDF_Page_SetGrayFill (page, 0)
    HPDF_Page_SetGrayStroke (page, 0)
	
Return Nil

sample-page-001.jpg
sample-page-002.jpg

exactly that edk, only one doubt (nRow = 400) and the sheet is A4 has 210mm nRow = 400 (pixel)?
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: pdf grid

Post by edk »

Haru Pdf is based on pixels for default resolution 72dpi. Also note the coordinates that are different from HMG HPDF.
http://libharu.sourceforge.net/graphics.html
So 210mm is: 210/25.4 * 72 = 595,275591 px
and 297mm is: 297/25.4 * 72 = 841,889764 px
Look at grid on page 1.
At sample on page 2, value 400 corresponds lower-left corner of the grid in pixels (nRow), so 400/72 * 25.4 = 141,111111 mm, counting from bottom of the page.
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: pdf grid

Post by jairpinho »

edk wrote: Tue Oct 03, 2017 8:59 pm Haru Pdf is based on pixels for default resolution 72dpi. Also note the coordinates that are different from HMG HPDF.
http://libharu.sourceforge.net/graphics.html
So 210mm is: 210/25.4 * 72 = 595,275591 px
and 297mm is: 297/25.4 * 72 = 841,889764 px
Look at grid on page 1.
At sample on page 2, value 400 corresponds lower-left corner of the grid in pixels (nRow), so 400/72 * 25.4 = 141,111111 mm, counting from bottom of the page.
Thank you for the answers, it helped my projects a lot.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: pdf grid

Post by jairpinho »

edk, text along with the grid is not accentuating, I already added _HMG_HPDF_SetEncoding ("WinAnsiEncoding") but it does not work
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: pdf grid

Post by edk »

You need to do:
HPDF_GetFont gets the handle of a corresponding font object by specified name and encoding.

Code: Select all

Local cEncoding := _HMG_SYSDATA[ 150 ] [ 10 ]       //Value of "SET HPDFDOC ENCODING TO".   "SET HPDFDOC ENCODING TO" set _HMG_HPDF_SetEncoding
font := HPDF_GetFont (pdf, "Helvetica", cEncoding)
Good luck to you.
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: pdf grid

Post by jairpinho »

edk wrote: Thu Oct 05, 2017 7:59 pm You need to do:
HPDF_GetFont gets the handle of a corresponding font object by specified name and encoding.

Code: Select all

Local cEncoding := _HMG_SYSDATA[ 150 ] [ 10 ]       //Value of "SET HPDFDOC ENCODING TO".   "SET HPDFDOC ENCODING TO" set _HMG_HPDF_SetEncoding
font := HPDF_GetFont (pdf, "Helvetica", cEncoding)
Good luck to you.
it does not work so I need the horizontal text to be right-aligned just with HPDF_Page_SetTextMatrix? But the accent does not work.
MÃ-nimo: 119 -> "Mínimo: "


Local Pdf := _HMG_SYSDATA[ 150 ][ 1 ]
Local Page := _HMG_SYSDATA[ 150 ][ 7 ]
Local cEncoding := _HMG_SYSDATA[ 150 ] [ 10 ]

ofont := HPDF_GetFont (Pdf, cFont, cEncoding)
HPDF_Page_SetFontAndSize (Page, ofont, nFontSize)

nAngle := 0
nRad := nAngle / 180 * 3.141592 //radian value
nTextWidth := HPDF_Page_TextWidth( page ,"Mínimo: " +alltrim(str(nMim) ))

nxPos:= 85 - (nTextWidth* cos (nRad)) // posição coluna do texto
nyPos := nRow + nMim
HPDF_Page_BeginText (page)
HPDF_Page_SetTextMatrix ( page , cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos - nFontSize/2 + .75 ) // nyPos = posicao Linha(Row)
HPDF_Page_ShowText (page, "Mínimo: "+alltrim(str(nMim)))
HPDF_Page_EndText (page)
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: pdf grid

Post by edk »

I don't see the problem with accents:

Code: Select all

#include "hmg.ch"

Function Main()
Local i

SELECT HPDFDOC "sample.pdf" ORIENTATION HPDF_ORIENT_LANDSCAPE PAPERSIZE HPDF_PAPER_A4
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE

     print_grid( 400, 150, 160, 200, 5, 5, 20 , 20 , 10 , 10 )
     HPDF_RotateTextPx( 510, 200, 'MĂ-nimo: 119 -> "Mínimo: "', Nil, 7, 90 , , , , 'T' )  //units: pixels

     
     
    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateTextPx( nRow, nCol, cTxt, cFont, nFontSize, nAngle, lBold, lItalic, aColors, cAlign)
* Rotating text

   Local nRad, nTextWidth, oFont, cFnt
   
   Local hPdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local hPage       := _HMG_SYSDATA[ 150 ][ 7 ]
   Local cPdfEnc     := _HMG_SYSDATA[ 150 ][ 10 ]

   Local nWidth      := _HMG_SYSDATA[ 150 ][ 4 ]
   Local nHeight     := _HMG_SYSDATA[ 150 ][ 5 ]
   Local nxPos       := nCol
   Local nyPos       := nRow

   DEFAULT cFont       := "Helvetica"
   DEFAULT nFontSize   := 12   
   DEFAULT cTXt        := ""
   DEFAULT nAngle      := 0
   DEFAULT lBold       := .F.
   DEFAULT lItalic     := .F.
   DEFAULT aColors     := { 0, 0, 0}
   DEFAULT cAlign      :=""		//Empty - Left and bottom, R - Right, C - Center, T - Top, M - Middle

   If _HMG_SYSDATA[ 150 ][ 1 ] == Nil // PDF object not found!
      _HMG_HPDF_Error( 3 )
      Return Nil
   endif

   If _HMG_SYSDATA[ 150 ][ 7 ] == Nil // PDF Page object not found!
      _HMG_HPDF_Error( 5 )
      Return Nil
   endif

   
   IF VALTYPE(cAlign)#'C' 
      cAlign := ''		//Left as default
   ENDIF
   
   
   // set color
   If VALTYPE( aColors )#'A' .OR. LEN( aColors )#3 .OR. ;
      VALTYPE( aColors[1] )#'N' .OR. VALTYPE( aColors[2] )#'N' .OR. VALTYPE( aColors[3] )#'N' .OR. ;
      aColors[1]<0 .OR. aColors[1]>255 .OR. ;
      aColors[2]<0 .OR. aColors[2]>255 .OR. ;
      aColors[3]<0 .OR. aColors[3]>255
      
      aColors     := { 0, 0, 0}
   Endif 
   HPDF_Page_SetRGBFill( hPage, aColors[1]/255, aColors[2]/255, aColors[3]/255 )   

   // set font
   If HMG_LEN( AllTrim( cFont ) ) == 0
      cFont := _HMG_HPDF_SetFont( cFont, lBold, lItalic )
      oFont := HPDF_GetFont( hPdf, cFont, cPdfEnc )

   else

      cFont := AllTrim(_HMG_HPDF_SetFont( cFont, lBold, lItalic ))
    
      if HMG_UPPER (cFileExt (cFont)) == '.TTF' // load ttf font
   
         cFnt := HPDF_LOADTTFONTFROMFILE( hPdf, cFont, .t. )

         If HMG_LEN( Alltrim( cFnt ) ) == 0
            _HMG_HPDF_Error( 6 , cFont )
            Return Nil
         endif

         oFont := HPDF_GetFont( hPdf, cFnt, cPdfEnc )
     
      else
     
         If HMG_UPPER( alltrim( cFont ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFont ) ) == "ZAPFDINGBATS"
            oFont := HPDF_GetFont( hPdf, cFont, Nil )
         else   
            oFont := HPDF_GetFont( hPdf, cFont, cPdfEnc )
         endIf
   
      endif

   endIf
   
   If oFont == Nil
      _HMG_HPDF_Error( 6 , cFont )
      Return Nil
   Endif

   HPDF_Page_SetFontAndSize( hPage, oFont, nFontSize )
   nTextWidth := HPDF_Page_TextWidth( hPage, cTxt )
   
   nRad := nAngle / 180 * 3.141592 	//radian value
   
   //calculate nxPos
   IF 'R'$HMG_UPPER(cAlign)		//Right
      nxPos:=nxPos - (nTextWidth* cos (nRad))
   ELSEIF 'C'$HMG_UPPER(cAlign)	//Center
   	 nxPos:=nxPos - ((nTextWidth* cos (nRad))/2)
   ENDIF
   
   //calculate nyPos
   IF 'T'$HMG_UPPER(cAlign)		//Top
      nyPos:=nyPos - (nTextWidth* sin (nRad))
   ELSEIF 'M'$HMG_UPPER(cAlign)	//Middle
   	 nyPos:=nyPos - ((nTextWidth* sin (nRad))/2)
   ENDIF
 
   HPDF_Page_BeginText( hPage )
   HPDF_Page_SetTextMatrix ( hPage, cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos)
   HPDF_Page_ShowText( hPage, cTxt )
   HPDF_Page_EndText( hPage )

RETURN

*------------------------------------------------------------------------*
Function print_grid( nRow, nCol, height, width, nScaleLine_X, nScaleLine_Y, nScaleText_X, nScaleText_Y, nTag_x, nTag_Y )
*------------------------------------------------------------------------*
   Local  font,x,y, cLabel, nLabWidth
   Local Pdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local Page       := _HMG_SYSDATA[ 150 ][ 7 ]  
   Local cPdfEnc    := _HMG_SYSDATA[ 150 ][ 10 ]

   Local nFontSize   := 5

    font := HPDF_GetFont (pdf, "Helvetica", cPdfEnc)

    HPDF_Page_SetFontAndSize (page, font, nFontSize)
    HPDF_Page_SetGrayFill (page, 0.5)
    HPDF_Page_SetGrayStroke (page, 0.8)


    /* Draw horizontal lines */
    y := 0 // distabcia inicio primeira linha
    while (y <= height )
        if  (y % (nScaleLine_Y*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
           if (HPDF_Page_GetLineWidth (page) != 0.25)
              HPDF_Page_SetLineWidth (page, 0.25)
           Endif
        Endif

        HPDF_Page_MoveTo (page, nCol, y + nRow)
        HPDF_Page_LineTo (page, width + nCol, y + nRow)
        HPDF_Page_Stroke (page)

        if (y % nTag_Y == 0 .and. y > 0)
            HPDF_Page_SetGrayStroke (page, 0.5)

            HPDF_Page_MoveTo (page, nCol, y + nRow)
            HPDF_Page_LineTo (page, nScaleLine_Y + nCol , y + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        y += nScaleLine_Y
    End

    /* Draw vertical lines */



    x := 0 //distabcia inicio primeira linha
    while (x <= width)
        if (x % (nScaleLine_X*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
            if (HPDF_Page_GetLineWidth (page) != 0.25)
                HPDF_Page_SetLineWidth (page, 0.25)
            Endif
        Endif

        HPDF_Page_MoveTo (page, x + nCol, nRow)
        HPDF_Page_LineTo (page, x + nCol, height + nRow)
        HPDF_Page_Stroke (page)

        if (x % nTag_X == 0 .and. x > 0)  // linha de referencia com a tag texto linha mais forte
            HPDF_Page_SetGrayStroke (page, 0.5)

            //tag esquerda
	    HPDF_Page_MoveTo (page, x + nCol, nRow)
            HPDF_Page_LineTo (page, x + nCol, nScaleLine_X + nRow )
            HPDF_Page_Stroke (page)

            //tag direita
	    HPDF_Page_MoveTo (page, x + nCol, height + nRow)
            HPDF_Page_LineTo (page, x + nCol, height - nScaleLine_X + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        x += nScaleLine_X
    End



    /* Draw horizontal text */


    y := 0 //distabcia inicio texto
    while (y < height)
        if (y % (nScaleText_Y) == 0 .and. y > 0)
	    cLabel:=ltrim(str(y))
            HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, nScaleLine_Y + nCol, y + nRow - (nFontSize/2) + .75  /* Middled Label */)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        y += nScaleText_Y
    End


    /* Draw virtical text */

    x := 0
    while (x < width)
        if (x % (nScaleText_X) == 0 .and. x > 0)
            cLabel:=ltrim(str(x))
	    nLabWidth:=HPDF_Page_TextWidth( page, cLabel )

            //tag em baixo
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, nScaleLine_X + nRow + 1)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)

            //tag em cima
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, height - (nScaleLine_X * 2) + nRow)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        x += nScaleText_X
    End

    HPDF_Page_SetGrayFill (page, 0)
    HPDF_Page_SetGrayStroke (page, 0)
	
Return Nil

sample.7z
(1.07 KiB) Downloaded 304 times
Do you have a .prg file saved in UTF-8? Perhaps this is a problem.
Prg in ANSI works fine:
Demo.7z
(2.12 KiB) Downloaded 306 times
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: pdf grid

Post by serge_girard »

Hi Kryzstof,

Is this text right: MĂ-nimo ?

And should the prg be save ad UTF-8 ? I think it must.
I download both and they show "MĂ-nimo".

Serge
There's nothing you can do that can't be done...
Post Reply