Update 2: Please download the new updated version with the following modifications
- Name of the classes changed to PdfListener (normal pdf output) and pdfasimagelistener (pdf as Image file). Suuggested by Emerson Reed.
- Added property cCodePage to handle the different code pages. The list of possible values are here http://libharu.org/wiki/Documentation/Encodings#Singlebyte_Encodings
I will try to update the class with more functions as soon as I can.
Enjoy.
Update: Please download the file again, there was an error in the Registry Class pointing to a header file, this was preventing the listener to draw text. Sorry for the inconvenience.
Do you want to create PDF file from VFP in an easy way without installing printer drivers or any other complicate rutine?
PDFx is a free open source report listener for creating PDF files from Visual FoxPro Reports.
Two years ago, I developed a listener to create PDF files, at beginning because I thought about starting a business the listener was a shareware and you were able to download a Trial Version. The business was not bad, in fact just last week I had a few more sales of QUICKFRX2PDF. Anyway for that listener I was using isedQUICKPDF library which is not open source and I was not able to distribute the source code of it, so it was no practical to open source that pdf listener. A few months ago, while checking ReportSculptor I heard about the work of Dorin Vasilescu with HARUPDF, until that point I've never heard of that library before, so I check it on Google, and I found out it was open source, wrote it in C and with a good support and continue development; some of you may think I'm killing my business, but I decided it was time to give something back for free to the VFP community that has give so much.
I started by browsing the documentation on the HARU site. Since I'm not a guru with API declarations, I checked the Visual Basic 6 Declarations Samples, and I had to recall in the samples of "Using Win32 functions in Visual FoxPro" specially to understand how to send Visual FoxPro data as C structures.
Well the result is this class, which is fully open source and really easy to use and setup:
To use it, just follow these simple steps:
- Include PDFx.VCX in your project.
- Include Dummy.Prg in your project and marked as excluded.
- Copy System.APP (GDIPLUSX library) to the project folder
- Copy libhpdf.dll to your Project folder.
That is all you need to include in your project, and to call the library you can follow this example:
Local loListener As ReportListener
loListener = NewObject('PdfListener1', 'PDFx.vcx') &&Use 'PdfListener2' to create PDF as an Image
loListener.cTargetFileName = "MyFile.Pdf"
loListener.QuietMode=.F.
loListener.lEncryptDocument=.F.
loListener.lCanEdit=.F. &&Only if lEncryptDocument=.T.
loListener.lCanCopy=.T. &&Only if lEncryptDocument=.T.
loListener.lCanAddNotes=.F. &&Only if lEncryptDocument=.T.
loListener.lCanPrint=.T. &&Only if lEncryptDocument=.T.
loListener.cMasterPassword="masterpassword" &&Only if lEncryptDocument=.T.
loListener.cUserPassword="userpassoword" &&Only if lEncryptDocument=.T.
loListener.lOpenViewer=.T.
Report Form MyReport Object loListener
And that's it.
Please try it, and let me know any issues you may have.
Current limitations:
- No support for Underline or strikeout style in text.
- Rounded rectangles will be transformed to ellipsis.
- Fills for shapes are not supported
- Objects Rotation.
Future improvements:
- Objects rotation.
- Merge with existing PDF documents.
- Support Hyperlinks.
- Support annotations.
- Try to work around current limitations
- Create a Help file.
- Support all possible encoding.
- I'm not sure about the name, so suggestions are welcome.
- Please give me feedback!!! and report all the bugs it will have.
Also please try it with different encoding, and let me know the problems you may have.
I hope you find this a useful class and enjoy it.
Luis Navas Dangel