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

Naming a report for output to a .pdf file

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have a program which will re-print invoices from couple of data tables.

After the user has selected which invoice he wants, I build up two cursors for the invoice header and for the line details. Then set a relation between the two.

The format for the report is in a format file, MyInv.frx. I then effectively issue this command :

Code:
REPORT FORM Myinv TO PRINTER PROMPT NOCONSOLE

This allows the report to be printed and also lets the user select a printer. If however he selects a pdfprinter (I use CutePdf Writer), this offers the user a default name for the output file. In this case it is MyInv.pdf - so it is taken from the name of the report format.

I would like the default name to be the number of the invoice itself, ANM123 (which my program knows). Is there a way of setting this name, so that by the time Cutepdf ptrinter gets control, it will offer that instead?

Rather optimistically I tried including a clause <NAME "ANM123"> in the REPORT FORM statement, but this does not have the desired effect.

Thanks. Andrew
 
Andrew,

As far as I know, you can't do that in the basic CutePDF package. You need the product they refer to as "Custom PDF Writer with programmatic access". To quote from the blurb:

This edition also enables applications to set the output file in the registry keys programmatically. So the printer driver creates the PDF files directly without Save As dialog box.

So you would write to the appropriate Registry keys from VFP (which is easy with the relevant FFC class), then go ahead and execute your REPORT FORM. I don't know off-hand which keys you need to write to, but presumably the documentation will tell you that.

By the way, you're right that adding a NAME clause to REPORT FORM is not the correct approach. In general, REPORT FORM doesn't know anything about PDFs, so the solution does not lie within VFP.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Follow up ....

If you don't like the idea of messing with Registry keys, and if you are not completely wedded to CutePDF, consider switching to XFRX. I've used it many times to output VFP reports to PDFs, and have found that it works flawlessly.

The cost is comparable to that of the professional versions of CutePDF, but it is a much simpler product. (If you do decide to get it, you don't need to go for the full package: just get the minimum version that supports PDF.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The NAME clause of REPORT FORM is for an object Name of a reportlistner, only valid for reportlistener assisted reports.
There is a TO FILE clause, but that'll also not generate PDFs, but ASCII files.

VFP is not a printer driver, it mereley prepares everything up to the point the ouptu should go to a printer driver. And as no normal printer creates files, there is no clause of the REPORT FORM command to specify a Destination file n used by the Printer driver, that's nonsense from the historical point of view.

Of course there are more and more file types created by "printers", eg also Microsofts XPS or OneNote, but this all is emulating a normal Printer and so the Destination is part of the Printer configuration, not of VFPs Report or REPORT FORM command, that's out of control of what the Printer driver does with it's Output.

There is one new way in the rpoertlistners, eg VFP Comes with some sample listener generating HTML files instead or additonal to a normal Report, you can also chain reportlisteners.

Anyway, that is more complicated and the easiest way is to use a PDF Printer driver to generate a file, but you depend on the vendor of these drivers and their way of configuring it, to be able to control the output file name.

BullZIP PDF is another pdf driver known to work with VFP and having the feature to predefine an output file name, see thread184-1633942

Bye, Olaf.
 
By the way: The wrong upper case words in my last post came from IE spelling corrections, which default to German here in Germany. That's ok, obviously, but IE should be able to detect, if I write German or English. I have to reconfigure some things, I fear.

The reason some words became upper case is not that they are the same in german, but we use many english terms, mostly technical terms. And if they are nouns they get capitals in german, not only at the start of each sentence, something you only do with names and the word "I" (interestingly).

Bye, Olaf.
 
Thanks again, Mike and Olaf

In fact since I first raised this question, I have discovered a work-around, whereby I create a copy of the report definition with a different name. It goes something like this :

Code:
  lName1 = "MyInv"
   lname2 = "ANM123"
   IF !FILE(lname2 + ".frx")
      lname1frx = lname1 + ".frx"
      lname1frt = lname1 + ".frt"
      COPY FILE &lname1frx TO ANM123.frx
      COPY FILE &lname1frt TO ANM123.frt
      REPORT FORM ANM123 TO PRINTER PROMPT NOCONSOLE
      DELETE FILE ANM123.frx
      DELETE FILE ANM123.frt
     ELSE
      REPORT FORM &lName TO PRINTER PROMPT NOCONSOLE
      ENDIF

I am not proud of this code, but I think (with bit more macro-substitution) it will do the trick.

Thanks again. Andrew
 
Can't see anything wrong with that. If it works, stay with it.

However, there are a couple of caveats. First, will the FRX and FRT files be bound into the EXE? If so, can you use COPY FILE to extract them from the EXE? (That's not a rhetorical question; I don't know the answer to it.)

Also, you will be copying the files to the default directory. You need to make sure that's not a directory in the Program Files tree (in Windows Vista or above), otherwise you will run into permissions issues. I would use the user's Temp directory for cases like this.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The way that I do it with my clients is to use a pre-configured PDF 'printer'/driver (we use BullZip) which will ALWAYS write the new PDF file to one single place and ALWAYS name it with one single filename (both path & filename ALWAYS the same each time).

Then, by 'knowing' where the file resides and what its default name is, the application can then immediately find the file, move it (if necessary) and rename it as needed to whatever is desired.

This approach has enabled the client's application to write 100's of PDF files each morning and then rename them as needed into unique PDF files.

Good Luck,
JRB-Bldr
 
I don't see how the name of the frx would determine the name of the resulting PDF, the printer driver doesn't get the frx file name, the frx file is processed by VFP, not by the printer driver. But if it works for you, it works. Most PDF drivers ask for a result name with a save file dialog and that doesn't change when you change the source report file name.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top