Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

Luis Guillermo Navas Dangel



Update PDFx Beta Free PDF Listener for VFP

Update 2:  Please download the new updated version with the following modifications
  1. Name of the classes changed to PdfListener (normal pdf output) and pdfasimagelistener (pdf as Image file). Suuggested by Emerson Reed.
  2. 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:

  1. Include PDFx.VCX in your project.
  2. Include Dummy.Prg in your project and marked as excluded.
  3. Copy System.APP (GDIPLUSX library) to the project folder
  4. 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:

  1. No support for Underline or strikeout style in text.
  2. Rounded rectangles will be transformed to ellipsis.
  3. Fills for shapes are not supported
  4. Objects Rotation.

Future improvements:

  1. Objects rotation.
  2. Merge with existing PDF documents.
  3. Support Hyperlinks.
  4. Support annotations.
  5. Try to work around current limitations
  6. Create a Help file.
  7. Support all possible encoding.
  8. I'm not sure about the name, so suggestions are welcome.
  9. 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

Published Tuesday, August 05, 2008 8:29 AM by luisn
Filed Under:
Attachment(s): PdfxNew.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Drivers Gratis Blog » Blog Archive » PDFx Beta Free PDF Listener for VFP said:

August 5, 2008 10:07 AM
 

Dorin Vasilescu said:

Hi, I appreciate your work.

About Rounded shapes and filled rectangles, I managed to solve this in my PDF Listener class based on Haru wrapper

case Between(frx.offset,1,98) &&rounded corners

*rounded corners using graphic path, slow ( not so slow though )
nRay = Round(IIF( nW > nH, Min(frx.offset,Int(nH/2)), Min(frx.offset,Int(nW/2))) , 0)

this.oPdf.Page_MoveTo( this.current_page , nX + nRay , nY )
this.oPdf.Page_LineTo( this.current_page , nR - nRay , nY )
this.oPdf.Page_CurveTo ( this.current_page, nR, nB, nR, nB, nR, nB + nRay )
this.oPdf.Page_LineTo( this.current_page , nR , nT - nRay )
this.oPdf.Page_CurveTo( this.current_page, nR, nT, nR, nT, nR - nRay , nT)
this.oPdf.Page_LineTo( this.current_page, nX + nRay , nT )
this.oPdf.Page_CurveTo( this.current_page, nX, nT, nX, nT, nX, nT - nRay )
this.oPdf.Page_LineTo( this.current_page, nX , nY + nRay )
this.oPdf.Page_CurveTo( this.current_page, nX, nY , nX, nY, nX + nRay , nY )

case frx.offset = 99 &&ellipse/circle

this.oPdf.Page_Ellipse( this.current_page, nX+nW/2 , nY+nH/2, nW/2, nH/2 )

endcase

if frx.mode = 0 &&fill color set, background opaque
this.oPdf.Page_FillStroke(this.current_page)
else
this.oPdf.Page_Stroke(this.current_page)
endif


I have a lot of questions, as we duplicated work to achieve same result :)

How you handle 2 passes reports?
Or "soft fonts" (Like Tahoma Bold Italic)?
What about font substitutions with native PDF Fonts ( for faster rendering ) ?

Maybe will be good for everyone to publish the wrapper itself ( my PDF Listener is just one implementation of it, and report sculptor use it as PDF engine ). I have almost all functionality implemented, including outline, encodings, etc

Maybe will result something good and free.


Hi Dorin, thank you for your comment and sample code I will take note and implement it ASAP, as for the 2 Pass Report (when using _PAGETOTAL) I have it on the Render Method you have to check for the property TwoPassProcces, is really simple and I'm sure you will have a better solution for it, what I do is:

If This.TwoPassProcess Then &&Report will run twice because the use of _PageTotal variable
    If This.CurrentPass=1 Then  &&Run only in the second pass, 0 is the first one
        lbProcces=.T.
    Else
        lbProcces=.F.
    EndIf
Else
    lbProcces=.T.
EndIf
If lbProcces Then
  *Procces the report
EndIf

I haven't checked for Soft Fonts, maybe you can explain me more about it.

As for font substitution I never thought of it, do you think it will be a good idea?

And for joining forces count with me, will you agree to send a project proposal at VFPx or you think they will reject this project?

August 6, 2008 8:55 AM
 

xinjie said:

It's good!I'm from China.It is still not content to Chinese report .
PDF documents generated by the content, the Chinese can not be displayed properly.
Will You consider to solve this problem?

Thank you very much!

Hi there, thanks for your comments, I will try to solve the issues. It's a beta version and will post an update as soon as I can and let you know so you can try it.

August 6, 2008 12:13 PM
 

Imran said:

Hi, great catch, thank you, I updated the ZIP file. This error was preventing the class to draw text.

hello
good work , but when i compile my app it generates error
Compiling d:\tf\pdfx.vcx
Error in global include file: Include file 'd:\degrees\include\sistema.h' is not found.
i think this sistema.h file is missing in zip package.

Regards,

Imran
August 6, 2008 2:20 PM
 

Dorin Vasilescu said:

Hi
Most probably will be rejected as VFPX project, because of commercial solutions

About "soft fonts", these are computed by GDI, without having a corresponding file present. (There is no entry for "Tahoma Bold Italic" in registry , AFAIK )

Regards.

Thank you for the information Dorin, I thought the same about VFPx, but we should try, I remember there was a RTF listener too from a Russian guy maybe we can create something good and complete. I will try to get more information about those fonts thanks for the explanation.
August 6, 2008 3:55 PM
 

Cesar said:

Wow !!!

I knew you were working on this, but I could never think it could work so nice.
It works super fast, I tested it with many reports, and they work really very nice under PDFx.

I just didn't manage to make it work together with other report listeners that customize the "Render" event of the reports. Is it already possible ? Can you provide a sample ?

I'm really speechless.
Your project is really very promising.

Thanks a lot for your efforts, and for sharing your hard work with the public. In these last months so many great things have been happening to the VFP community! Impressive to see so many great projects lifting all over, providing such great possibilities.

About VFPX, personally I'd love to see this project there. I have no idea wether it will be approved or not, but I definitely think you should submit it. Having you and Dorin Vasilescu working on it, and receiving the community feedback, PDFx will become a very important tool for us.

CONGRATULATIONS !

Looking forward to your next moves !

Regards

Cesar

Thanks for your comments Cesar, actually this small effort was inspired in by the work people like you, Emerson Read, Carlos Alloati, Bo Durban, Craig Boyd, etc (sorry I forgot someone) are doing for the community. As for the testing with custom render mode, can you provide me with a sample? so I can test it.

I will try to continually envolve this product to make better and post updates as soon as possible. I will try to submit it to VFPx to, but I will try to make it more mature before that.

I'm really glad you like it!!!

August 7, 2008 5:20 AM
 

Moshe said:

Fantastic. Congratulations 4 ur Work !!!

Thanks, you are welcome
August 7, 2008 6:31 PM
 

Imran said:

Hi Imran that was sample code, the way to assign the filename is responsibility of the user the same with the openviewer property, take a look at the sample form included with the project.

Yes now its working. Well I have few suggesstions where listner is calling report.
Ideally we should ask user to put file name and location of pdf

loListener.cTargetFileName = "MyFile.Pdf"
this  should be
loListerner.cTargetFileName=Getfile("pdf","Select File Name")

And OpenViewer should be .f. otherwise in between application control switches to Adobe Acrobate or othe PDF reader

loListener.lOpenViewer=.F.

Regards,
Imran
August 7, 2008 8:37 PM
 

Emerson Santon Reed said:

Hi Luis!

Firstly, congratulations!
This listener is awesome.
Great work.

Here are some questions. It's possible:
1) To embed a font in the generated pdf?
2) To execute more than one report (sequentially report form commands) and generate only one concatenated pdf?
3) To directly add text watermarks and choose the position and rotation?

Here are some suggestions:
1) In the Load method of sample form, place some code to set the paths (as I do in the main ThemesManager program) to avoid errors;
2) Change the reportlisteners names from PDFListener1 and PDFListener2 to PDFListener and PDFasImageListener, for example.

Regards!

Thanks for your comment Emerson, first with your questions:

1) Yes it's possible to embed a font use the property lEmbedFont to true.
2) and 3 are not possible yet, I will try to implement it on a new realease.

Thanks for your suggestions, be sure I will take them all!!!

Regards.

Luis

August 8, 2008 2:13 PM
 

Shorty said:

Done!!

Hi Luis,
Great work.
The file "sistema.h" is still missing in ZIP file.
I generate PDF file without text ( I have pictures, lines ..).
Is this file responsible for this mistake?
Can you please send it to my mail shorty10@seznam.cz
Thank you for help.
Best regards
Vit
August 12, 2008 7:37 AM
 

xinjie said:

HI, can you please email me a sample report?

Cheers
I had download new version.but,I can't creat PDF document after I set loListener.cCodePage="GBK-EUC-H".

My Code:
loListener = Newobject('PdfListener', 'PDFx.vcx')
loListener.cCodePage="GBK-EUC-H"
loListener.cTargetFileName = "MyFile.Pdf"
Report Form demo Object loListener

I am very confused. Can you help me?

Thank you!
August 14, 2008 4:14 PM
 

Arjun Bagojikop said:

Hi Luis
This Listener is very cool
when i generate the pdf file in the some lables are hiding why i am not understood
Can you please assist me.

Sure, can you send me a sample?
August 27, 2008 5:17 AM
 

Zaheer Ahmed said:

First of all, Thanks for sharing your efforts.
I used PDFx in one of my applications.  The problem I am facing is missing words in resulting pdf.  Some words in the Header and sub-total of columns are missing.
I could'nt find any file attachment option here or I have uploaded the resulting PDF and the Actual result.
What is that I am doing wrong ?

Sorry for the late answer, will you email me to lnavasdangel@gmail.com your reports to try?
September 9, 2008 11:44 AM
 

xinjie said:

Hi Cheers,
I'm sorry that I just see comment.
I will be happy to send a Demo for you.But,I don't know you email.
Can you tell me?
My Email is openvfp@163.com

Thank's again.

Sorry for the late answer is lnavasdangel@gmail.com
September 10, 2008 1:52 PM
 

Enrique said:

Hi Luis,

Where can I download the PDFx Listener Library?

I tried one link you posted but there is nothing.

Thanks

At the end of the post, there is a link to the file.
September 15, 2008 7:38 PM
 

joni aparecido rodaelli said:

Hi Luis Guillermo, I'm from Brazil and your class is fantastic!
i'm using to my report and contain Lines, Shapes, Images and when your
class genarating with PdfasimageListener, PDF is sucess, but when I using
with PdfListener, the PDF GENARATING is wrong.
What can I do using error your class?

thanks

If you have shapes and those shapes have objects behind them, then do a SENT TO BACK in the report designer.
Also please send me a sample,

December 1, 2008 2:08 PM

What do you think?

(required) 
(optional)
(required) 

This Blog

Post Calendar

<August 2008>
SuMoTuWeThFrSa
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

Post Categories

Syndication