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

To automatically save the pdf in a folder

Status
Not open for further replies.

janak vyas

Technical User
Jun 3, 2020
47
IN
Hi !
I wanted to know if it is possible to save the pdf into a folder.
What I mean is, the program will first create a folder and then save the pdf(s) into that particular folder.
folder name being created from a variable.

How is it possible?
 
Good point, Mike. I guess that means the output file name needs a .pdf extension if one wants to be able to click it open with their default pdf reader. (Or renaming the .txt extension to .pdf).
Steve
 
The way it becomes a PDF is by the reportlistener that's used, that uses lidpdf.dll and it's triggered by OBJECT TYPE 10, look into foxypreviewer documentation.

In contrast, if you don't use foxypreviewer and have TO FILE some.pdf this will not ouptut PDF content to a file.
If I know it correctly the TO FILE option just redirects anything that the driver would send to the printer to a file. That could be any printr command language, that could be pure simple generic text.

You can't usually use this even with PDF printer drivers that emulate a printer and priduce a PDF from the text, data, commands, graphics, whatever sent to them. If you'd use TO FILE with such a printer set you'd just prevent this paert of the data flow going through the part of the driver that actually only creates PDF from its input. So you'd not do the essential step.

With Foxypreviewer again it only works because in itself Foxypreviewer uses repoortlistener events like render to generate a PDF file and it uses this REPORT command option in another way than the usual reportengine (both the 80 or 90) engine do.

So once more in short TO FILE isn't a general solution. You can try but you'll see that you don't get what you expect with it, also inn other cases like using Microsoft viirtual printer drivers for XPS documents or anything else.

TO FILE mainly works with TXT only outputs and more general can just store into a file what you could later forward to a printer port like LPT1. It's as old as the ideas to have these kind of serial data transfer and network drivers and GDI+ drivers or postscript or anything wasn't yet playing the major role. It's a track switch and redirects what is before the "conversion" to PDF or XPS or any output type you actually want. So TO FILE is an outdated artifact pointing to a technical history of printers in DOS times that plays no role anymore and I'm even a bit angry the foxypreviewer team revived this REPORRT command option as it gives wrong ideas.

Chriss
 
Steve Myerson said:
Not sure why a company would insist on Adobe instead of FoxyPreviewer output. Is there a difference?

Political reasons, contracts, anything.

And yes, different drivers can cause different output. Make some extensive tests and you likely find differences, too. Use header/footer in Word and save to PDF. Thanks to the by now included feature this will work, but before Word itself had the option, not all PDF printer drivers would care for the header/footer section of word document pages.

Surely, I also can recommend Foxypreviewer as it solves the problem, but it may not work for that company. for whatever spcific or also untechnical reasons.

Chriss
 
Chris said:
Surely, I also can recommend Foxypreviewer as it solves the problem, but it may not work for that company. for whatever spcific or also untechnical reasons.

But it has worked well for me for many years, and the other stuff is way beyond me. [glasses]

Steve
 
I would have suggested using XFRX to do this, generating the pdfs from reports in VFP and controlling where they go is really easy.

Not free, but very good all the same.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
I also like XFRX. I tend to use Foxy for when I want an interactive preview window, and XFRX for exporting reports to PDFs, Word, Excel, etc. without user interaction. They each have their strengths and weaknesses.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
other stuff is way beyond me

Well, what's beyond me is using OBJECT TYPE 10.
The most straight forward use of Foxypreviewer is adding this line of code to your main prg and change nothing else:
Code:
DO FOXYPREVIEWER.APP

I know you surely either found the documentation telling this way of printing PDF with FoxyPreviewer, but there's a - in my eyes - simpler way:

Code:
SET PROCEDURE TO LOCFILE("FoxyPreviewer.App") ADDITIVE 
LOCAL loReport AS "PreviewHelper" OF "FoxyPreviewer.App" 
loReport = CREATEOBJECT("PreviewHelper") 
WITH loReport AS ReportHelper 
        .AddReport("...your.frx", "NODIALOG") 
        .cDestFile = "c:\targetfoldder\outputname.pdf"  && Use to create an output without previewing
        .RunReport()
ENDWITH 
loReport = NULL

I see the official documentation makes OBJECT TYPE the newer version and marks this as deprecated usage, but I think code like this is more speaking for itself what it does, actually.
Seems they found it less elegant to use a helper object to have a way of setting options and control how the report is processed. But I actually find this more elegant and extensible to many more things.

Yes, it's even more lines of code, but that's not always what matters. You already can guess this offers to process multiple report by calling .AddReport() with multiple frxes, and still only produce one PDF, for example.

Chriss
 
I like to make the pdf and then have the chance to do things with it - such as popping them on the clipboard for
pasting into an email... or providing it to a web client as a download

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Thanks for the explanation & code. I will try that.

Chris said:
with multiple frxes, and still only produce one PDF, for example.
Up til now I have I've been guilty of using the very "unelegant" method using NOPAGEEJECT except for the last page. It's worked so far. Haven't had any complaints.

Steve
 
NOPAGEEJECT isn't unelegant, too.

I'm just thinking of so many more opportunities of a helper/parameter/result object:
You could have several properties with Information available after the report run, you can add parameters to such an object, which RunReport() then makes available as report variables, and the class can also have helper functions you could use/embed in a report.

I guess they consider it better to only need the REPORT FORM as that's what most VFP developers use to print anyway and it means less changes to existing code. You can also make OBJECT TYPE 10 more speaking by defining a constant that points out PDF output and is 10. But then I mainly complained about the "misuse" of the TO FILE option and the redefinition from its original meaning. TO FILE once was a means to be able to produce files you then could perhaps save to disk and send to a printer on another computer, before printers were networked.

Or collect a few files and then print them all at once, during night, when you're not in office and don't have to stand the noise of needle printers or worse.

I guess not even Mike Lewis will share my view, as TO FILE some.txt always also was a simple text report end result. They weren't the end product, usually. And now reviving this REPORT FORM option is not a bad idea, but it is giving less informed developers bad ideas of how this is usable in general, while it's not.

Chriss
 
In my projects I have two different pdf-drivers that are possible to programmatically choose both path and filename. One is very old and is called EREPORTS.DLL, the other one is XFRX that is a very potent program in many aspects and can also export to Word and Excel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top