pdf grid
Posted: Sun Oct 01, 2017 12:03 am
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
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