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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to supply filename when doing SET PRINTER TO NAME "Microsoft Print to PDF" 2

dylim

Programmer
Dec 12, 2001
175
PH
Hi Experts,

Am trying to the do the following:

Print to a PDF from a REPORT FORM (a receipt), then email this generated PDF file as an attachment to a customer's email address.

My questions:

1. Can I do a SET PRINTER TO NAME "Microsoft Print to PDF" before running REPORT FORM TO PRINT?
2. How do I pass the filename to this?
3. Which email API (is this what we call it) is the most straightforward (and free please) to implement to you guys?

Kindly share your experience.

Love live the Fox!
 
There are quite a few PDF libraries out there, including FoxyPreviewer and XFRX. I have paid versions of both, but the one I use in my actual projects is XFRX because it's super flexible and gives me consistent results.

FoxyPreviewer is easy to implement and has a ton of features too. It it used to have issues with high DPI displays such as 4K/5K monitors, which is why I didn't use it, but this has been resolved. I tested and paid for the revised version because I like to support FoxPro development, but since I'm already using XFRX, I have no immediate need to change.
 
Until now i could not figure out how to pass the filename to "Microsoft Print to PDF". Looks like MS does not (yet) support this feature.
I use "PDF-Creator" , older Version because of easy use of ".INI" configuration.
set the AUTOSAVE-options

Just name the FRX/FRT-File to required YourOutputName
SET PRINTER TO <PDfCreator>
REPORT FORM <YourOutputName> TO PRINTER
 
Just regarding the PDF printing, I'll answer your first two questions:

1. Yes you can do that, I don't think it's going to be your best bet for automatically creating PDFs from Fox without relying on users to manually specify the filename using the prompt though. I'll expand for #2

2. I don't think you can do this easily and the ways that might be possible are not going to be ideal or friendly. I'm not going to say for definite that you cannot but it's not looking good. There are lots of software printers that can sit in your list of printers in Windows and do exactly this kind of behaviour, i.e. a user or an application can force the output to that (software) printer but then that software takes over from that point and a lot of the time that means the software asks the user to specify the filename/path using a manual prompt/dialog that makes it difficult to do things like batch-automate. There's been lots of free PDF printers for more than a decade or two and most of them operated in that manner, with no way of automating them. If you are trying to utilise something and specifically want to supress that prompt, by pre-empting it and supplying the filename/path then that particular software needs to provide a specific way of doing that. It wouldn't be a Fox thing, it would be a thing specific to the (software) printer you are trying to use. There is hope though because there are some free options that can do what you are looking for, they just aren't already baked into Windows.

Doing a bit of googling around things such as "Automate Microsoft Print to PDF" reveals that lots of people have asked this question because lots of people have been excited by a potentially free way of creating PDFs from their software by utilising something already baked into Windows and meaning they don't have to change the install footprint of their application. The responses almost always say that it can't be done and the ones that tease that it might be doable mostly suggest that you could trying putting specific keystrokes into the keyboard buffer to try to almost hack-automate the "Save Print Output As" dialog. That might be possible but it could be sketchy at best and wouldn't be something I'd like to rely on, if it were me.

The SO link in the response from Chriss is another very interesting way to try to do it but it does seem like a very fiddly way to set that up and as others have said there are other ways of creating PDFs from reports in VFP. I'm not going to repeat the options put forward by others except to add my +1 to FoxyPreviewer. I started using that more than a dozen years ago and it was an almost seamless integration to get that to work and really only involved distributing the foxypreviewer.app file alongside our application.

Explore all the options to work out which is going to be best for you.
 
There are quite a few PDF libraries out there, including FoxyPreviewer and XFRX. I have paid versions of both, but the one I use in my actual projects is XFRX because it's super flexible and gives me consistent results.

FoxyPreviewer is easy to implement and has a ton of features too. It it used to have issues with high DPI displays such as 4K/5K monitors, which is why I didn't use it, but this has been resolved. I tested and paid for the revised version because I like to support FoxPro development, but since I'm already using XFRX, I have no immediate need to change.

Hi Joe,

I do use FoxyPreviewer, albeit the free version. I didn't know that it can output to a PDF. I thought it was a better REPORT FORM PREVIEW interface.

Perhaps you can provide me a few snippets to start off?

Thanks!
 
Until now i could not figure out how to pass the filename to "Microsoft Print to PDF". Looks like MS does not (yet) support this feature.
I use "PDF-Creator" , older Version because of easy use of ".INI" configuration.
set the AUTOSAVE-options

Just name the FRX/FRT-File to required YourOutputName
SET PRINTER TO <PDfCreator>
REPORT FORM <YourOutputName> TO PRINTER

Hi EinTerraner,

Code:
SET PRINTER TO <PDfCreator>
REPORT FORM <YourOutputName> TO PRINTER

<YourOutputName> is the name of the .FRX (report form), right?

Suppose I need for the name of generated PDF to be "Customer 0009 - Receipt.pdf", where shall specify this in order for the PDF to be created with that name?

Thanks.
 
Hi Joe,

I do use FoxyPreviewer, albeit the free version. I didn't know that it can output to a PDF. I thought it was a better REPORT FORM PREVIEW interface.

Perhaps you can provide me a few snippets to start off?

Thanks!
FoxyPreviewer is actually the easiest compared to XFRX.

Basically you just call it once and it creates a bunch of objects that you don't even need to understand or use directly to get it to work.

You can just call it like this:
Code:
DO FOXYPREVIEWER WITH "CLEAN"
REPORT FORM YourReport.Frx TO FILE xxxxxx.pdf

Technically, you don't need to call FoxyPreviewer.app more than once, unless your app implicitly releases memory and objects. Once it's run, it's available to your entire program without calling it again.

Here's a link that explains the changes in the newer version: https://www.foxypreviewer.com/p/new.html
 
FoxyPreviewer is actually the easiest compared to XFRX.

Basically you just call it once and it creates a bunch of objects that you don't even need to understand or use directly to get it to work.

You can just call it like this:
Code:
DO FOXYPREVIEWER WITH "CLEAN"
REPORT FORM YourReport.Frx TO FILE xxxxxx.pdf

Technically, you don't need to call FoxyPreviewer.app more than once, unless your app implicitly releases memory and objects. Once it's run, it's available to your entire program without calling it again.

Here's a link that explains the changes in the newer version: https://www.foxypreviewer.com/p/new.html

This is great! I do not need to wander farther.

One more question though. Can one control or customize the dimensions of a PDF file?
 
This is great! I do not need to wander farther.

One more question though. Can one control or customize the dimensions of a PDF file?
As I mentioned, I use XFRX these days, but as far as I know it will just follow whatever dimensions are in the report file.

They have a free version, so give it a try and you may not need to explore other options. That said, I've been using XFRX for decades and it's never let me down.

What first drew me to XFRX was that it even lets you create PDFs programmatically (without an FRX report file). I used to write reports directly in PostScript in the DOS days and it allowed me to follow the same logic to create PDFs directly.
 
Suppose I need for the name of generated PDF to be "Customer 0009 - Receipt.pdf", where shall specify this in order for the PDF to be created with that name?
Right.
Code:
USE ReportFile.FRX
COPY TO MyRequiredPdf.FRX
SET PRINTER TO "Pdf2Mail" && Assuming this is the PDF-Printer
REPORT FORM MyRequiredPdf TO PRINTER


My settings the virtual PDF-Printer (Sry. I use german language)
Version Frm_494.jpg
Document AustoSAve Frm_496.jpg

Actions after printing Frm_497.jpg
 
FoxyPreviewer documentation:

Immediately after you "DO FOXYPREVIEWER.APP" all the properties below will be available in the "_Screen.oFoxyPreviewer" object.
And that object has properties, a lot of properties, for settings. For output type, name, etc.

Regarding PDFCreator, I think it has more and better options about the output size/quality, as you can see here, even in the free version:
1748610510905.png
You also have tons of options of automatic output file naming in the PDFCreator software. All that matters for your requirement is that the file name choice is not interactive, but automatic. I'd even not care for all the options you have, just make it a static name like PDFCreator.pdf and then use RENAME after the REPORT FORM command. It's always harder to provide the file name by a) setting some registry key, b) setting some environment variable c) setting the print job (for which you'd need to dig deep into Windows API and how VFP names its print jobs and how to get at it) or an more options. The PDFCreator software allows you to set up the output directory (by default it's in the users Windows Profile Documents folder, and then a file name that can be anything from the default print job name to a counter automatically increasing, any Windows environment variable etc. All the options have one thing in common: They are not direct parameters of a VFP REPORT FORM command, the way FoxyPreviewer allows the TO FILE yourname.pdf option I think is only available in the commercial version 3. And the way to use a setting is not available with PDFCreator, as it's not running in VFP, obviously, it's a virtual PDF printer and has its software for settings and more on top of the usual Windows printer settings. Bullzip PDF comes with an OCX, IIRC, which also has some properties to set before running the report.

To me the options of PDFCreator win over foxypreviewers own PDF output, but indeed I use foxypreviwer, just set the printer name to PDFCreator and use that driver to turn the normal foxypreviewer output to a PDF file, which then uses PDFCreator profile and printer settings to name the output pdf. Also the end user software was a welcomed option of customers to have this under their own control.
 
Last edited:
1. Can I do a SET PRINTER TO NAME "Microsoft Print to PDF" before running REPORT FORM TO PRINT?
2. How do I pass the filename to this?
Regarding 1 and 2, the tools mentioned above are good, but I'm using PDFium available here: https://github.com/dmitriychunikhin/pdfium-vfp

Do you use Thor in VFP? https://github.com/VFPX/Thor That's a great tool, too, and makes installing PDFium quite easy. I had been using BullZip and find it too cumbersome. PDFium worked the first time with only the effort of downloading it and following the simple instructions for use (see the section on the page I linked you to that starts "Basic usage of PdfiumViewer" - Note: that's for viewing, the section below that is for printing). I'd highly recommend it.
 
Regarding 1 and 2, the tools mentioned above are good, but I'm using PDFium available here: https://github.com/dmitriychunikhin/pdfium-vfp

Do you use Thor in VFP? https://github.com/VFPX/Thor That's a great tool, too, and makes installing PDFium quite easy. I had been using BullZip and find it too cumbersome. PDFium worked the first time with only the effort of downloading it and following the simple instructions for use (see the section on the page I linked you to that starts "Basic usage of PdfiumViewer" - Note: that's for viewing, the section below that is for printing). I'd highly recommend it.

Hi,

What does Thor help us in development sir? Have heard of Thor for the longest time, but never had the change to tinker with it.
 
Thor is a tool manager that handles installation for many add ons that are offered under the roof of VFPX on github, see https://github.com/VFPX/Thor

It's the first thing to install to have most other VFPX extensions managed in the VFP9 IDE.

Chriss,

Have you been using Thor for the longest time sir?
 

Part and Inventory Search

Sponsor

Back
Top