Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use FoxyPreviewer to generate a pdf from a label programmatically

Status
Not open for further replies.

costin77

Programmer
Jul 9, 2010
4
0
0
RO
Hey there,
I found this code which works very well to generate a pdf from a report using FoxyPreviewer :

SET PROCEDURE TO LOCFILE("FoxyPreviewer.App") ADDITIVE
LOCAL loReport AS "PreviewHelper" OF "FoxyPreviewer.App"
loReport = CREATEOBJECT("PreviewHelper")
WITH loReport AS ReportHelper
.lOpenViewer = .f.
.AddReport(m.raport, "NODIALOG")
.cDestFile = cale_aplicatie + raport + ".pdf" && Use to create an output without previewing
.RunReport()
ENDWITH
loReport = NULL


Can someone tell me how to change this code to use a label instead of a "report form" as the source?

Thank you,
Costin
 
Welcome to the forum.

I've always produced labels in Foxypreviewer in much the same way as producing reports. But my code is different from yours (and much simpler).

I have this at the start my main program:

[tt]SET REPORTBEHAVIOR 90
DO FoxyPreviewer.APP[/tt]

And when I am ready to produce the PDF, I do either this:

[tt]REPORT FORM <report name> TO FILE <name of PDF output file>[/tt]

or

[tt]LABEL FORM <label name> TO FILE <name of PDF output file>[/tt]

There are various customisations you can do, for example the nPDFType property determines the method used to create the PDF, but I've never bothered with these.

Note that all of the above assumes you are using VFP 9.0. If not, none of it willl apply.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
Thanks for your quick response and offer of help.
I tried your code, but no pdf file was created. Maybe the problem with your code is that the application needs first to select a pdf printer?

PS. I am using FoxyPreviewer v299z41.
Regards,
Costin
 
I am using FoxyPreviewer v299z41

According to the documentation, the method I showed you requires Foxy version 3 or later. For earlier versions, I think you need to add [tt]OBJECT TYPE 10[/tt] to the REPORT FORM or LABEL FORM command.

Alternatively, it looks from the code that you posted that you are creating the PDF without going through the preview first. If that's so, is there any reason for you to use FoxyPreviewer for this task. Assuming that your users have a PDF printer driver installed, you could simply SET PRINTER to that driver, and then just print the labels in the normal way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

I second your notice, that using a PDF filename in the FILE clause only works in foxypreviewer 3, we had discussed how that works now in the latest version in a recent thread.
But costin77 obviously diectly makes use of a class of foxypreviewer.app directly.

I think the use case for this code is to not use the preview feature of FoxyPreviewer, but its PDF feature without a PDF printer software installed. And that is working this way. I think you can alos use AddReport to add a label file, not sure. It's just whatever is in m.raport that determines what's printed as PDF. Not sure whether that class also has an AddLable() method, it's eas to find out.



Chriss
 
My goal is to create pdf files from my application, without any preview of report/label which is being generated.
 
In that case, I would think the easiest solution would be to ensure that your users have a suitable PDF driver installed (which they would probably want in any case), and then use the normal LABEL FORM or REPORT FORM commands (as mentioned in my previous post).

You will probably need a way to programmatically set the output filename without any user involvement. Most (not all) PDF printer drivers provide a way of doing that, for example by amending a configuration file. Check the driver's docs for that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I want a solution which it should work for any pdf printer and any version of Windows.
Do you know where I can find a complete manual for FoxyPreviewer?
 
Costin77,

FoxyPreviewer, no matter which veersion works for as many Windows versions as VFP9, and that's almost all since Windows95 up until today. I don't know why you bring that up in this discussion.
But more importantly, FoxyPreviwer does not make use of a PDF printer driver, It makes use of the haru pdf library and that doesn't require more.

You just have to upgrade to version 3 to use Mikes method or you have to find out whether the code you have also works, if the file you add is a lbx file instead of a frx. I think it does, haven't tried. It might need to handle lbx differently in later running it with Label Form instead of Report Form and therefore have either or both a AddLabel() method and or a RunLabel() method. Why don't you simply try that out yourself?

Chriss
 

Chris Miller said:
FoxyPreviewer, no matter which veersion works for as many Windows versions as VFP9, and that's almost all since Windows95 up until today. I don't know why you bring that up in this discussion.
But more importantly, FoxyPreviwer does not make use of a PDF printer driver, It makes use of the haru pdf library and that doesn't require more.

FoxyPreviewer 3.0 use Haru lib or Microsoft PDF Printer or custom render "engine" as output to PDF (nPdfType property).

mJindrova
 
mJindrova,

yes, that's also new. the point is that FoxyPreviewer doesn't use or need a PDF printer installed.
And Mike has a point that if you like, you can use a PDF printer driver instead of Foxypreviewer, too. Then you would not use that code but simply SET PRINTER TO such a printer driver and be done, for both reports and labels.

Chriss
 
Costin, I understand that you want to use Foxypreviewer because it would avoid the need to install and configure a PDF driver. And also that you don't need to preview the labels. You can achieve that with the code I suggested in the first of my above posts. I'm fairly sure that the reason it didn't work for you was that you didn't have the latest Foxy version installed. If so, just go ahead and upgrade to the latest.

That said, there are several other ways of creating PDFs without installing a PDF driver. But since you have already started with Foxypreviewer, I suggest you try that first.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top