Libharu HPDF library - Export to PDFs
Click on code to select [then copy] -click outside to deselect
Haru is a free, cross platform, open-sourced software library for generating PDF (originally written in C language). It supports the following features.
1. Generating PDF files with lines, text, images.
2. Outline, text annotation, link annotation.
3. Compressing document with deflate-decode.
4. Embedding PNG, Jpeg images.
5. Embedding Type1 font and TrueType font.
6. Creating encrypted PDF files.
7. Using various character set (ISO8859-1~16, MSCP1250~8, KOI8-R).
8. Supporting CJK fonts and encodings.
ref:https://en.wikipedia.org/wiki/LibHaru
You can add the feature of PDF creation by using Haru without understanding complicated internal structure of PDF.
see the copyright of this library in yhelp.chm
It was ported on vfp by Dorin Vasilescu and can be downloaded in this link:https://sites.google.com/site/pdfclasses/
this Vfp9 application gathers some libharu works and makes some demo.Its mainly based on Dorin vasilescu works as _libPDF.prg library class and reports listeners updated.
it converts to PDF:
-1.Any text based to PDF (report)
-2.Any text based to PDF (Simple)
-3.Any text based to pdf (BW)
-4.Any text based to pdf (Colored)
-5.Any single JPG image to pdf
-6.Folder JPG Images to PDF
-7.Image rotation
-8.TTfonts demo
-9.Outline demo
-10.line demo
-11.grid_sheet
-12.fonts demo
-13.Encryption
-14.Arc demo
-15.Text demo
-16.Pie chart
-17.Image demo
-18.ext_gstate_demo
-19.PNG demo
-20.permissions
-21.JPEG demo
-22.VFP Report with Images
-23. Quick report demo
-24.Text demo 2
-25.216 colors palette
-26.pie chart background
Note the item 18 must have implementations in _libhpdf.prg library to work as expected.some function and constants must be added.
this is also available for the Libharu slideshow native demo.
the first panel makes any vfp report (frx) converted to pdf.
it can be encrypted with a custom secret password,set if the document output can be printed or copied (text/images)
the password if set must mandatory typed before re opening the PDF document.
there is 3 kinds of helps
1.the custom help as chm document
2.a link to libharu documentation for graphic functions...
3.a link to libharu ported on javascript with same demos.
Note:
-to compile the project must run vfp9.exe as administrator (writes on registry)
-the architecture must stay as it to dont have problems with paths.
-recompile and run ytest.exe to test capabilities of the library.
-of course this is a first try and many improvments are to perform.
-read the Microsoft Permissive License (Ms-PL) in reportOutput folder.
download the zip and recompile as administrator the project, produce ytest.exe.this is needed to registering purpose (see ytest.vbr & ytest.tlb)-(overwrite the ytest.exe). then you can work safety (no error like "pdflistener.prg not found....").
if first compilation fails to produce a clean exe delete ytest.exe and recompile until no error appears.
Of course can run directly the main form yHaru.scx form from vfp9(or ytest.prg).
After this,click "clean" button to delete superflue files as bak,fxp...
run ytext.exe and report wrapping.frx ...export to pdf.....
at the right panel on the form can run 23 prgs and see helps.
*problems encoutered with Libharu - HPDF and to solve
added to limitations cited by Dorin Vasilescu:
-the convert2pdf raises some signs in the pdf (square..) due to alines
-the pdf output of folder of images : the current position is the bottom of pdf (how to tell it to go top ?)
-alignments are not as well in pdfs and carriage returns.
-Unicode and utf-8 text based files to pdf
-some functions must be implemented to _libpdf.prg to run some libharu demos as slideshow or yext_gstate_demo.prg
-link_annotation.prg dont work as expected (tested on windows10)
Notes:
-the chm help attached to the zip is produced from the previous post:
http://yousfi.over-blog.com/2016/03/build-your-chm-help-with-vfp-html-worshop.html
-to access to pdf fullscreen, the viewer must be acrobat reader.
download the last updated ytest.zip (1730 ko ~) and recompile the project as administrator.The code *1* and *2* below are added to the zip.
ytest.exe: use shortcuts CTRL+ or CTRL ! for zooming even in fullscreen mode
Click on code to select [then copy] -click outside to deselect
*1*
*this is my version of text_demo2.c of libharu library.
* added on Saturday 16 april 2016 ; 16:10:00
*can add it to the zip above (ytest.exe)-can run this code only if put it in same folder as _libpdf.prg
**print_grid is integrated as function here
*sample built with _libpdf.prg library of Dorin vasilescu
#include hpdf_types.h
#include hpdf_consts.h
Erase ("ydemo.pdf")
Local opdf As 'pdfGen' Of '_libpdf.prg'
Local page_title As String
Local pdf As HPDF_Doc
Local fname As String
Local Page As HPDF_Page
Local def_font As HPDF_Font
Local tw, Height,Width, i
page_title = "Font Demo 2"
Local printGrid
printGrid=.T.
fname = 'ydemo.pdf'
opdf = Newobject('pdfGen',Locfile('_libpdf.prg'))
pdf = opdf.New()
opdf.Setcompressionmode( HPDF_COMP_ALL )
*if _screen.activeform.check1.value=1 &&pdf as fullscreen in default viewer
opdf.SetPageMode( HPDF_PAGE_MODE_FULL_SCREEN)
*endi
Page = opdf.Addpage()
Height = opdf.Page_GetHeight(Page)
Width = opdf.Page_GetWidth(Page)
Local samp_text
samp_text = "The quick brown fox jumps over the lazy dog. "
*page = pdf.add_page
opdf.page_setSize(Page,HPDF_PAGE_SIZE_A5, HPDF_PAGE_PORTRAIT)
Width=opdf.Page_GetWidth(Page)
Height = opdf.Page_GetHeight(Page)
*make page background color
opdf.Page_SetCMYKFill(Page, 0.13, 0, 0.16,0.11)
opdf.Page_Rectangle(Page,0,0,Width,Height)
opdf.Page_Fill (Page)
* draw grid to the page in option ( see function below)
If printGrid=.T.
= yprint_grid (opdf, Page)
Endi
Font = opdf.Getfont("Helvetica", Null)
opdf.Page_SetTextLeading(Page,20)
* HPDF_TALIGN_LEFT
Left = 25
Top = 545
Right = 200
Bottom = Top - 40
opdf.Page_Rectangle(Page,Left, Bottom, Right - Left, Top - Bottom)
opdf.page_stroke(Page)
opdf.page_beginText(Page)
opdf.page_setfontandsize(Page,Font, 10)
opdf.page_textout(Page,Left, Top + 3, "HPDF_TALIGN_LEFT")
opdf.page_setfontandsize(Page,Font, 13)
opdf.page_textrect(Page,Left, Top, Right, Bottom, samp_text,HPDF_TALIGN_LEFT)
opdf.Page_EndText (Page)
* HPDF_TALIGN_RIGHT
Left = 220
Right = 395
opdf.Page_Rectangle(Page,Left, Bottom, Right - Left, Top - Bottom)
opdf.page_stroke(Page)
opdf.page_beginText(Page)
opdf.page_setfontandsize(Page,Font, 10)
opdf.page_textout(Page,Left, Top + 3, "HPDF_TALIGN_RIGHT")
opdf.page_setfontandsize(Page,Font, 13)
opdf.page_textrect(Page,Left, Top, Right, Bottom, samp_text,HPDF_TALIGN_RIGHT)
opdf.Page_EndText(Page)
* HPDF_TALIGN_CENTER
Left = 25
Top = 475
Right = 200
Bottom = Top - 40
opdf.Page_Rectangle(Page,Left, Bottom, Right - Left, Top - Bottom)
opdf.page_stroke(Page)
opdf.page_beginText(Page)
opdf.page_setfontandsize(Page,Font, 10)
opdf.page_textout(Page,Left, Top + 3, "HPDF_TALIGN_CENTER")
opdf.page_setfontandsize(Page,Font, 13)
opdf.page_textrect(Page,Left, Top, Right, Bottom, samp_text,HPDF_TALIGN_CENTER)
opdf.Page_EndText(Page)
* HPDF_TALIGN_JUSTIFY
Left = 220
Right = 395
opdf.Page_Rectangle(Page,Left, Bottom, Right - Left, Top - Bottom)
opdf.page_stroke(Page)
opdf.page_beginText(Page)
opdf.page_setfontandsize(Page,Font, 10)
opdf.page_textout(Page,Left, Top + 3, "HPDF_TALIGN_JUSTIFY")
opdf.page_setfontandsize(Page,Font, 13)
opdf.page_textrect(Page,Left, Top, Right, Bottom, samp_text, HPDF_TALIGN_JUSTIFY)
opdf.Page_EndText(Page)
* Skewed coordinate system
angle1 = 5.0
angle2 = 10.0
rad1 = angle1 / 180 * 3.141592
rad2 = angle2 / 180 * 3.141592
opdf.page_gsave(Page)
opdf.page_concat(Page,1, Tan(rad1), Tan(rad2), 1, 25, 350)
Left = 0
Top = 40
Right = 175
Bottom = 0
opdf.Page_Rectangle(Page,Left, Bottom, Right - Left,Top - Bottom)
opdf.page_stroke(Page)
opdf.page_beginText(Page)
opdf.page_setfontandsize(Page,Font, 10)
opdf.page_textout(Page,Left, Top + 3, "Skewed coordinate system")
opdf.page_setfontandsize(Page,Font, 13)
opdf.page_textrect(Page,Left, Top, Right, Bottom, samp_text, HPDF_TALIGN_LEFT)
opdf.Page_EndText(Page)
opdf.page_grestore(Page)
* Rotated coordinate system
opdf.page_gsave(Page)
angle1 = 5.0
rad1 = angle1 / 180 * 3.141592
opdf.page_concat(Page,Cos(rad1), Sin(rad1), -Sin(rad1),Cos(rad1), 220, 350)
Left = 0
Top = 40
Right = 175
Bottom = 0
opdf.Page_Rectangle(Page,Left, Bottom, Right - Left, Top - Bottom)
opdf.page_stroke(Page)
opdf.page_beginText(Page)
opdf.page_setfontandsize(Page,Font, 10)
opdf.page_textout(Page,Left, Top + 3, "Rotated coordinate system")
opdf.page_setfontandsize(Page,Font, 13)
opdf.page_textrect(Page,Left, Top, Right, Bottom, samp_text, HPDF_TALIGN_LEFT)
opdf.Page_EndText(Page)
opdf.page_grestore(Page)
* text along a circle
opdf.page_SetGrayStroke(Page,0)
opdf.page_circle(Page,210, 190, 145)
opdf.page_circle(Page,210, 190, 113)
opdf.page_stroke(Page)
angle1 = 360.0 / Len(samp_text)
angle2 = 180.0
opdf.page_beginText(Page)
Font = opdf.Getfont("Courier-Bold", Null)
opdf.page_setfontandsize(Page,Font, 30)
For i=1 To Len(samp_text)
r=255*Rand()/255
g=255*Rand()/255
b=255*Rand()/255
opdf.Page_SetRGBFill (Page, r, g, b)
m.char=Substr(samp_text,i,1) &&one text character
rad1 = (angle2 - 90) / 180 * 3.141592
rad2 = angle2 / 180 * 3.141592
x = 210.0 + Cos(rad2) * 122
Y = 190.0 + Sin(rad2) * 122
*HPDF_Page_SetTextMatrix(m.page,m.a,m.b,m.c,m.d,m.x,m.y)
opdf.page_setTextMatrix(Page,Cos(rad1), Sin(rad1), -Sin(rad1), Cos(rad1), x, Y)
opdf.page_showtext(Page, m.char)
angle2 =angle2-angle1
Endfor
opdf.Page_EndText(Page)
opdf.SaveToFile(fname)
* clean up
opdf.Free()
*yb Show
loShell = Newobject('_shellexecute', Home(1) + 'ffc\_environ.vcx')
loShell.ShellExecute(m.fname)
*set defa to (yrep)
Return
Function yprint_grid()
Lparameters opdf, Page
If .F.
Local opdf As 'pdfGen' Of '_libpdf.prg'
Endif
Height = opdf.Page_GetHeight(Page)
Width = opdf.Page_GetWidth(Page)
Font = opdf.Getfont("Helvetica", Null)
opdf.page_setfontandsize(Page, Font, 5)
opdf.Page_SetGrayFill(Page, 0.5)
opdf.page_SetGrayStroke(Page, 0.8)
* Draw horizontal lines
Y = 0
Do While Y < Height
If (Y % 10 == 0)
opdf.Page_SetLineWidth (Page, 0.5)
Else {
If (opdf.Page_GetLineWidth (Page) != 0.25)
opdf.Page_SetLineWidth (Page, 0.25)
Endif
Endif
opdf.Page_MoveTo (Page, 0, Y)
opdf.Page_LineTo (Page, Width, Y)
opdf.page_stroke (Page)
If (Y % 10 == 0 And Y > 0)
opdf.page_SetGrayStroke (Page, 0.5)
opdf.Page_MoveTo (Page, 0, Y)
opdf.Page_LineTo (Page, 5, Y)
opdf.page_stroke (Page)
opdf.page_SetGrayStroke (Page, 0.8)
Endif
Y = Y + 5
Enddo
* Draw virtical lines
x = 0
Do While (x < Width)
If (x % 10 == 0)
opdf.Page_SetLineWidth (Page, 0.5)
Else {
If (opdf.Page_GetLineWidth (Page) != 0.25)
opdf.Page_SetLineWidth (Page, 0.25)
Endif
Endif
opdf.Page_MoveTo (Page, x, 0)
opdf.Page_LineTo (Page, x, Height)
opdf.page_stroke (Page)
If (x % 50 == 0 And x > 0)
opdf.page_SetGrayStroke (Page, 0.5)
opdf.Page_MoveTo (Page, x, 0)
opdf.Page_LineTo (Page, x, 5)
opdf.page_stroke (Page)
opdf.Page_MoveTo (Page, x, Height)
opdf.Page_LineTo (Page, x, Height - 5)
opdf.page_stroke (Page)
opdf.page_SetGrayStroke (Page, 0.8)
Endif
x = x + 5
Enddo
*Draw horizontal text
Y = 0
Do While (Y < Height)
If (Y % 10 == 0 And Y > 0)
opdf.page_beginText (Page)
opdf.Page_MoveTextPos (Page, 5, Y - 2)
opdf.page_showtext (Page, Transform(Y))
opdf.Page_EndText (Page)
Endif
Y = Y + 5
Enddo
*Draw vertical text
x = 0
Do While (x < Width)
If (x % 50 == 0 And x > 0)
opdf.page_beginText (Page)
opdf.Page_MoveTextPos (Page, x, 5)
opdf.page_showtext (Page, Transform(x))
opdf.Page_EndText (Page)
opdf.page_beginText (Page)
opdf.Page_MoveTextPos (Page, x, Height - 10)
opdf.page_showtext (Page, Transform(x))
opdf.Page_EndText (Page)
Endif
x = x + 5
Enddo
opdf.Page_SetGrayFill (Page, 0)
opdf.page_SetGrayStroke (Page, 0)
Endfunc
Click on code to select [then copy] -click outside to deselect
*2*
*this code draws 216 rgb colored recangles in a pdf file output.
*add to ytest.zip -Must run in same folder as _libpdf.prg (ytest).
*print_grid is integrated as function here
*The above table contains what is known as the "web safe" color palette, it is also known by the following names: browser-safe palette, Netscape palette, 216 color palette, Web palette or 6x6x6 color cube.
*Added on 16 april 2016 : 22:20:00
#include hpdf_types.h
#include hpdf_consts.h
Erase ("ydemo.pdf")
Local opdf As 'pdfGen' Of '_libpdf.prg'
Local page_title As String
Local pdf As HPDF_Doc
Local fname As String
Local Page As HPDF_Page
Local def_font As HPDF_Font
Local tw, Height,Width, i
page_title = "Font Demo 2"
Local printGrid
printGrid=.T.
fname = 'ydemo.pdf'
opdf = Newobject('pdfGen',Locfile('_libpdf.prg'))
pdf = opdf.New()
opdf.Setcompressionmode( HPDF_COMP_ALL )
*if _screen.activeform.check1.value=1 &&pdf as fullscreen in default viewer
*opdf.SetPageMode( HPDF_PAGE_MODE_FULL_SCREEN)
*endi
Page = opdf.Addpage()
Height = opdf.Page_GetHeight(Page)
Width = opdf.Page_GetWidth(Page)
Local m.pageWidth,m.pageHeight
m.pageWidth=600
m.pageHeight=970
opdf.Page_SetWidth(Page,m.pageWidth)
opdf.Page_SetHeight(Page,m.pageHeight)
Width=opdf.Page_GetWidth(Page)
Height = opdf.Page_GetHeight(Page)
*make page background color
*opdf.Page_SetCMYKFill(Page, 0.13, 0, 0.16,0.11)
opdf.Page_SetRGBFill(Page,0.8,1,1)
opdf.Page_Rectangle(Page,0,0,Width,Height)
opdf.Page_Fill (Page)
* draw grid to the page in option ( see function below)
If printGrid=.T.
= yprint_grid (opdf, Page)
Endi
Font = opdf.Getfont("Helvetica", Null)
opdf.Page_SetTextLeading(Page,20)
** print the title of the page (with positioning top center).
m.hTitle=40
m.page_title=" 216 RGB colored rectangles"
opdf.Page_SetFontAndSize (Page, Font, 18)
tw = opdf.Page_TextWidth (Page, page_title)
opdf.Page_SetRGBFill (Page, .4, 1, 0.6)
opdf.Page_Rectangle(Page,(opdf.Page_GetWidth(Page) - tw) / 2 ,opdf.Page_GetHeight(Page)-m.hTitle,250,25)
opdf.Page_Fill (Page)
opdf.Page_SetRGBFill (Page, 1.0, 0., 0.)
opdf.Page_BeginText (Page)
opdf.Page_TextOut (Page, (opdf.Page_GetWidth(Page) - tw) / 2 ,opdf.Page_GetHeight(Page)-m.hTitle +10 , page_title)
opdf.Page_EndText (Page)
page_title=" Yousfi Benameur 16 april 2016"
tw = opdf.Page_TextWidth (Page, page_title)
Font = opdf.Getfont("Helvetica-BoldOblique", Null)
opdf.Page_SetFontAndSize(Page,Font, 10)
opdf.Page_SetRGBFill (Page, 1.0, 0., 0.)
opdf.Page_BeginText (Page)
opdf.Page_TextOut (Page, opdf.Page_GetWidth(Page) - tw ,15 , page_title)
opdf.Page_EndText (Page)
*draw 216 RGB colored rectangles
Local k,x0,y0,w,h ,Top,Left,delta
delta=5
k=0
x0=20
y0=30
ww=90
hh=20
i=1
Left=x0
Top=y0
Local r,g,b
For r=0 To 1 Step 0.2
g=0
b=0
For g=0 To 1 Step 0.2
For b=0 To 1 Step 0.2
If i>1
Left=Left+ww+delta
Endi
opdf.Page_SetRGBFill (Page, r, g, b)
opdf.Page_Rectangle(Page,Left,Top,ww,hh)
opdf.Page_Fill (Page)
samp_text="["+Trans(r)+","+Trans(g)+","+Trans(b)+"]"
opdf.Page_SetRGBFill (Page, 0, 0,0)
opdf.Page_BeginText(Page)
opdf.Page_SetFontAndSize(Page,Font, 8)
opdf.page_textrect(Page,Left, Top+hh/2+delta,Left+ww, Top-hh/2,samp_text,HPDF_TALIGN_CENTER)
opdf.Page_EndText (Page)
If i>=6
i=1
Left=x0
Top=Top+hh+delta
Else
i=i+1
Endi
k=k+1
Endfor
Endfor
Endfor
Messagebox(Trans(k)+" colors generated",0+32+4096,'',1000)
opdf.SaveToFile(fname)
* clean up
opdf.Free()
*yb Show
If File (m.fname)
loShell = Newobject('_shellexecute', Home(1) + 'ffc\_environ.vcx')
loShell.ShellExecute(m.fname,3)
*set defa to (yrep)
Else
Messagebox("ydemo.pdf not generated",16+4096)
Endi
Return
Function yprint_grid()
Lparameters opdf, Page
If .F.
Local opdf As 'pdfGen' Of '_libpdf.prg'
Endif
Height = opdf.Page_GetHeight(Page)
Width = opdf.Page_GetWidth(Page)
Font = opdf.Getfont("Helvetica", Null)
opdf.Page_SetFontAndSize(Page, Font, 5)
opdf.Page_SetGrayFill(Page, 0.5)
opdf.page_SetGrayStroke(Page, 0.8)
* Draw horizontal lines
Y = 0
Do While Y < Height
If (Y % 10 == 0)
opdf.Page_SetLineWidth (Page, 0.5)
Else {
If (opdf.Page_GetLineWidth (Page) != 0.25)
opdf.Page_SetLineWidth (Page, 0.25)
Endif
Endif
opdf.Page_MoveTo (Page, 0, Y)
opdf.Page_LineTo (Page, Width, Y)
opdf.page_stroke (Page)
If (Y % 10 == 0 And Y > 0)
opdf.page_SetGrayStroke (Page, 0.5)
opdf.Page_MoveTo (Page, 0, Y)
opdf.Page_LineTo (Page, 5, Y)
opdf.page_stroke (Page)
opdf.page_SetGrayStroke (Page, 0.8)
Endif
Y = Y + 5
Enddo
* Draw virtical lines
x = 0
Do While (x < Width)
If (x % 10 == 0)
opdf.Page_SetLineWidth (Page, 0.5)
Else {
If (opdf.Page_GetLineWidth (Page) != 0.25)
opdf.Page_SetLineWidth (Page, 0.25)
Endif
Endif
opdf.Page_MoveTo (Page, x, 0)
opdf.Page_LineTo (Page, x, Height)
opdf.page_stroke (Page)
If (x % 50 == 0 And x > 0)
opdf.page_SetGrayStroke (Page, 0.5)
opdf.Page_MoveTo (Page, x, 0)
opdf.Page_LineTo (Page, x, 5)
opdf.page_stroke (Page)
opdf.Page_MoveTo (Page, x, Height)
opdf.Page_LineTo (Page, x, Height - 5)
opdf.page_stroke (Page)
opdf.page_SetGrayStroke (Page, 0.8)
Endif
x = x + 5
Enddo
*Draw horizontal text
Y = 0
Do While (Y < Height)
If (Y % 10 == 0 And Y > 0)
opdf.Page_BeginText (Page)
opdf.Page_MoveTextPos (Page, 5, Y - 2)
opdf.page_showtext (Page, Transform(Y))
opdf.Page_EndText (Page)
Endif
Y = Y + 5
Enddo
*Draw vertical text
x = 0
Do While (x < Width)
If (x % 50 == 0 And x > 0)
opdf.Page_BeginText (Page)
opdf.Page_MoveTextPos (Page, x, 5)
opdf.page_showtext (Page, Transform(x))
opdf.Page_EndText (Page)
opdf.Page_BeginText (Page)
opdf.Page_MoveTextPos (Page, x, Height - 10)
opdf.page_showtext (Page, Transform(x))
opdf.Page_EndText (Page)
Endif
x = x + 5
Enddo
opdf.Page_SetGrayFill (Page, 0)
opdf.page_SetGrayStroke (Page, 0)
Endfunc
Click on code to select [then copy] -click outside to deselect
*3*
*this is a text effect in rotated coordinate system (0-360 degrees).
*must run in same folder as _libpdf.prg
*demo added on saturday 16 april 2016
#include hpdf_types.h
#include hpdf_consts.h
Erase ("ydemo.pdf")
Local opdf As 'pdfGen' Of '_libpdf.prg'
Local page_title As String
Local pdf As HPDF_Doc
Local fname As String
Local Page As HPDF_Page
Local def_font As HPDF_Font
Local tw, Height,Width, i
page_title = "Text rotation"
Local printGrid
printGrid=.T.
fname = 'ydemo.pdf'
opdf = Newobject('pdfGen',Locfile('_libpdf.prg'))
pdf = opdf.New()
opdf.Setcompressionmode( HPDF_COMP_ALL )
*if _screen.activeform.check1.value=1 &&pdf as fullscreen in default viewer
opdf.SetPageMode( HPDF_PAGE_MODE_FULL_SCREEN)
*endi
Page = opdf.Addpage()
Height = opdf.Page_GetHeight(Page)
Width = opdf.Page_GetWidth(Page)
Local samp_text
samp_text = "Visual foxpro is wondefull. "
opdf.page_setSize(Page,HPDF_PAGE_SIZE_A5, HPDF_PAGE_PORTRAIT)
Width=opdf.Page_GetWidth(Page)
Height = opdf.Page_GetHeight(Page)
*make page background color
opdf.Page_SetCMYKFill(Page, 0.13, 0, 0.16,0.11)
opdf.Page_Rectangle(Page,0,0,Width,Height)
opdf.Page_Fill (Page)
* draw grid to the page in option ( see function below)
If printGrid=.T.
= yprint_grid (opdf, Page)
Endi
Font = opdf.Getfont("Helvetica-BoldOblique", Null)
opdf.Page_SetTextLeading(Page,20)
** print the title of the page (with positioning center).
Local hTitke
hTitle=25
opdf.Page_SetFontAndSize (Page, Font, 18)
opdf.Page_SetRGBFill (Page, 1.0, 0.0, 0.1)
tw = opdf.Page_TextWidth (Page, page_title)
opdf.Page_BeginText (Page)
opdf.Page_TextOut (Page, (opdf.Page_GetWidth(Page) - tw) / 2 ,opdf.Page_GetHeight (Page)-m.hTitle , page_title)
opdf.Page_EndText (Page)
*# Rotated coordinate system
For angle1=0 To 360 Step 5
opdf.page_gsave(Page)
rad1 = angle1 / 180 * 3.141592
opdf.page_concat(Page,Cos(rad1), Sin(rad1), -Sin(rad1),Cos(rad1), 220, 350)
Left = 0
Top = 40
Right = 275 &&175
Bottom = 0
*opdf.Page_Rectangle(Page,Left, Bottom, Right - Left, Top - Bottom)
*opdf.page_stroke(Page)
opdf.Page_SetRGBFill(Page,255*Rand()/255,255*Rand()/255,255*Rand()/255)
opdf.Page_BeginText(Page)
opdf.Page_SetFontAndSize(Page,Font, 16)
opdf.page_textrect(Page,Left, Top, Right, Bottom, samp_text, HPDF_TALIGN_LEFT)
opdf.Page_EndText(Page)
opdf.page_grestore(Page)
Endfor
opdf.SaveToFile(fname)
* clean up
opdf.Free()
*yb Show
loShell = Newobject('_shellexecute', Home(1) + 'ffc\_environ.vcx')
loShell.ShellExecute(m.fname)
*set defa to (yrep)
Return
Function yprint_grid()
Lparameters opdf, Page
If .F.
Local opdf As 'pdfGen' Of '_libpdf.prg'
Endif
Height = opdf.Page_GetHeight(Page)
Width = opdf.Page_GetWidth(Page)
Font = opdf.Getfont("Helvetica", Null)
opdf.Page_SetFontAndSize(Page, Font, 5)
opdf.Page_SetGrayFill(Page, 0.5)
opdf.page_SetGrayStroke(Page, 0.8)
* Draw horizontal lines
Y = 0
Do While Y < Height
If (Y % 10 == 0)
opdf.Page_SetLineWidth (Page, 0.5)
Else {
If (opdf.Page_GetLineWidth (Page) != 0.25)
opdf.Page_SetLineWidth (Page, 0.25)
Endif
Endif
opdf.Page_MoveTo (Page, 0, Y)
opdf.Page_LineTo (Page, Width, Y)
opdf.page_stroke (Page)
If (Y % 10 == 0 And Y > 0)
opdf.page_SetGrayStroke (Page, 0.5)
opdf.Page_MoveTo (Page, 0, Y)
opdf.Page_LineTo (Page, 5, Y)
opdf.page_stroke (Page)
opdf.page_SetGrayStroke (Page, 0.8)
Endif
Y = Y + 5
Enddo
* Draw virtical lines
x = 0
Do While (x < Width)
If (x % 10 == 0)
opdf.Page_SetLineWidth (Page, 0.5)
Else {
If (opdf.Page_GetLineWidth (Page) != 0.25)
opdf.Page_SetLineWidth (Page, 0.25)
Endif
Endif
opdf.Page_MoveTo (Page, x, 0)
opdf.Page_LineTo (Page, x, Height)
opdf.page_stroke (Page)
If (x % 50 == 0 And x > 0)
opdf.page_SetGrayStroke (Page, 0.5)
opdf.Page_MoveTo (Page, x, 0)
opdf.Page_LineTo (Page, x, 5)
opdf.page_stroke (Page)
opdf.Page_MoveTo (Page, x, Height)
opdf.Page_LineTo (Page, x, Height - 5)
opdf.page_stroke (Page)
opdf.page_SetGrayStroke (Page, 0.8)
Endif
x = x + 5
Enddo
*Draw horizontal text
Y = 0
Do While (Y < Height)
If (Y % 10 == 0 And Y > 0)
opdf.Page_BeginText (Page)
opdf.Page_MoveTextPos (Page, 5, Y - 2)
opdf.page_showtext (Page, Transform(Y))
opdf.Page_EndText (Page)
Endif
Y = Y + 5
Enddo
*Draw vertical text
x = 0
Do While (x < Width)
If (x % 50 == 0 And x > 0)
opdf.Page_BeginText (Page)
opdf.Page_MoveTextPos (Page, x, 5)
opdf.page_showtext (Page, Transform(x))
opdf.Page_EndText (Page)
opdf.Page_BeginText (Page)
opdf.Page_MoveTextPos (Page, x, Height - 10)
opdf.page_showtext (Page, Transform(x))
opdf.Page_EndText (Page)
Endif
x = x + 5
Enddo
opdf.Page_SetGrayFill (Page, 0)
opdf.page_SetGrayStroke (Page, 0)
Endfunc
Important:All Codes above are tested on VFP9SP2 & windows 10 pro.
Please come back with any bug.correcting code is usefull to all readers.