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

VFP Reports to PDF - Page Size Differences 1

Status
Not open for further replies.

kazl

Programmer
Dec 9, 2002
68
GB
Hi. Can you help please?

I am using Adobe Distiller to output reports with REPORT FORM myreport TO PRINTER PROMPT

The text is stored in a single field database with page headings etc. The VFP report is a simple one liner listing from this database.

REPORT FORM myreport PREVIEW shows that the paging is fine in VFP but when it goes out to PDF the paging can be different due to the margins. (i.e. start of page 4 can show at bottom of page 3)

It is OK on Win98 as I can change the Margins in Printer Properties for the Distiller. But on Win XP I can't find how to change these margins.

Can I somehow include the margins/unprintable area in the FRX file so that the setting is carried through to Adobe?

Also, if this is possible, can I specify the Distiller as the printer in the report to save using PRINTER PROMPT on multiple reports?

 
Hi,

If you have set the papersize to A4 or whatever and that is available in the printer info of the vfp report, I think you should sail without problem. But you have to have the same setup in the PDF distiller. I am not using distiller, but using print2pdf, and that seems to work OK.
Only hack the printer name in the report header and keep the orientation, size etc in the report and try.

:)

ramani :)
(Subramanian.G)
 
Hi Ramani

After much hoohah I changed the report page layouts to full page, which matched Distiller, and then adjusted my printing program. Seems to be OK.

Thanks.


 
Also, if this is possible, can I specify the Distiller as the printer in the report to save using PRINTER PROMPT on multiple reports?

You can use the PDFWRITER printer driver that comes with Adobe Acrobat to generate PDFs directly from VFP. PDFWRITER presents a dialog box that asks for the PDF filename to create for each report. If you decide to use PDFWRITER, post back and I'll go over the method for bypassing the dialog box and specifying the PDF filenames in code.




Mike Krausnick
Dublin, California
 
Thanks Mike.

I have an order document that uses one report for each detail page and another for the final page with the summary and terms etc.

I'd like to specify the file name for each page without using the dialog box.

The aim is then to merge the pages into one PDF to sent by email. I don't know how much of this can be automated.

Any tips would be appreciated.

Kaz
(Herts. UK)
 
The following code requires REGISTRY.PRG, which is in the VFP samples directory.

In your report code, call INITPDFNAME() before executing REPORT FORM to populate the registry key with the name you want to use. Also, change the default printer to the PDFWRITER printer. Then executing REPORT FORM will print to PDFWRITER, which will get its filename from the registry. In the code below, REGFILE is a #DEFINE pointing to the location of registry.prg.

The call to INITPDFNAME() looks like this:

Code:
InitPDFName(cPDFDir+cPDFName+".PDF")

After printing the page, PDFWRITER automatically deletes the registry key, so you don't have to worry about that.

Oh, it would be a good idea to make sure the PDFWRITER driver is installed by passing the output from APRINTERS() to INITPDFNAME. Or you could do that manually prior to calling INITPDFNAME by scanning the array for the name PDFWRITER.

Code:
*====================================================================
FUNCTION  InitPDFName(cRegKeyVal, aPrts)    && Initialize Adobe PDF filename
* Parameters:   (required) cRegKeyVal - Filename to post
*                               (optional) aPrts - Array of installed printers
* Note:                 Uses REGISTRY.PRG
* Returns:      nResult         - Numeric error# from SetRegKey() - 0=Success
*====================================================================
local n

* See if PDFWRiter is a defined printer; exit if not
if vartype(aPrts) == "C"
  if ascan(aPrts,PDFWRITER) = 0
    return 0
  endif
endif

IF !FILE(REGFILE)
        MESSAGEBOX("INITPDFNAME: The required file "+REGFILE+" could not be found.")
        RETURN
ENDIF
if type(&quot;cRegKeyVal&quot;) <>&quot;C&quot;
        MESSAGEBOX(&quot;INITPDFNAME: The required filename parameter is missing&quot;)
        RETURN
ENDIF

return  SetRegValue(cRegKeyVal, ;
                                        &quot;Software\Adobe\Acrobat PDFWriter&quot; , ;
                                        &quot;PDFFileName&quot;)


FUNCTION  SetRegValue(cRegKeyVal, cRegFolder, cRegKeyName)    && Assign a registry key value
* Parameters:   (required) cRegKeyVal   - Key value to post
*                               (optional) cRegFolder   - Folder containing key
*                               (optional) cRegKeyName  - Key name
* Notes:                1. Uses REGISTRY.PRG
*                               2. Customized for setting PDF filename, but will set any key
* Returns:      nResult         - Numeric error# from SetRegKey() - 0=Success
*====================================================================

#DEFINE HKEY_CURRENT_USER           -2147483647  && BITSET(0,31)+1
LOCAL oReg,nErrNum
IF !FILE(REGFILE)
        MESSAGEBOX(&quot;SETREGVALUE: The required file &quot;+REGFILE+&quot; could not be found.&quot;)
        RETURN
ENDIF
if type(&quot;cRegKeyVal&quot;) <>&quot;C&quot;
        MESSAGEBOX(&quot;SETREGVALUE: The required key value parameter is missing&quot;)
        RETURN
ENDIF
* Parameters
cRegFolder  = iif(type(&quot;cRegFolder&quot;) ==&quot;C&quot;,cRegFolder ,&quot;Software\Adobe\Acrobat PDFWriter&quot;)
cRegKeyName = iif(type(&quot;cRegKeyName&quot;)==&quot;C&quot;,cRegKeyName,&quot;PDFFileName&quot;)
oReg = NewObject(&quot;FoxReg&quot;,REGFILE)      && Create registry object
return oReg.SetRegKey(  cRegKeyName     , ;
                                                cRegKeyVal                              , ;
                                                cRegFolder                              , ;
                                                HKEY_CURRENT_USER)


Mike Krausnick
Dublin, California
 
Thank you.

I'll give this a try a let you know how I get on.

Kaz
 
Hi Mike

It has been a few weeks so I understand if you don't have any more time for this thread. Just in case you can still help... my program says

SET PRINTER TO NAME GETPRINTER( )
InitPDFName(&quot;C:\WINDOWS\Desktop\MyFile.PDF&quot;)
REPORT FORM printrep TO PRINTER NOCONSOLE

When I choose Acrobat PDFWriter the program still prompts for the PDF file name

If I choose Acrobat Distiller I get a file called All. in the C:\WINDOWS folder which I can open with Distiller
(I guess I'm not meant to use Distiller at this stage.)

InitPDFName refers to &quot;Software\Adobe\Acrobat PDFWriter&quot;

Do I change this to match the location of PDFWriter on my computer? APRINTERS() lists PDFWriter as LPT1:

Any suggestions?

Kaz.
 
InitPDFName refers to &quot;Software\Adobe\Acrobat PDFWriter&quot;

That is the name of the folder (in the registry) containing the registry key you set with SetRegValue. The name of the key you set is &quot;PDFFileName&quot;.

Maybe the GetPrinter() is not using the filename created by InitPdfName() because it's not there when you call Getprinter()? As a test, try setting the PDFWriter as the default printer before starting VFP and eliminating the call to GetPrinter(). Or try calling INITPDFNAME() prior to the call to GetPrinter().

The BOL indicates that when using SET PRINTER TO NAME... the argument is the network name of the printer, so I don't think setting to LPT1: would work. I've never tried it though.

If this is any help, I discovered a situation in my code where INITPDFNAME() got called, but the report never actually printed. What happened is that the name set by INITPDFNAME() stayed in the registry and was used the next time I printed ANY document to the pdfwriter. So when I expected a dialog asking for a filename, I didn't get one.


Mike Krausnick
Dublin, California
 
Hi Mike

Thanks for your reply.

I set the port for Acrobat PDFWriter to &quot;C:\WINDOWS\All Users\Desktop\*.pdf (PDF Port)&quot; and I've tried setting it as the Default printer.

Then I used a few variations on the instructions. I still have the same problem. The Save As dialog still comes up and it offers My Documents, not Desktop.

I traced thru the REGISTRY program and it chooses Win 95 when I'm on Win 98 but other than that there's no error.

Guess I'll start again. There must be other settings in my way. I appreciate your help across the time zones though. Thanks.

When I crack it I'll post back.

Kaz
 
Hi

I have come back to this and now have questions about InitPDFName and REGISTRY.

As this is no longer about page sizes I have started a new thread 184-717615 (Name files for PDFWriter...)

I haven't resorted to banging my head on the desk yet tho. Can I get some help on the next thread, please?

Kaz
 
Hi !
Just a remark on using the PDF-writer:

Once you 'print' the report to a PDF-file with destination other than the default destination you have to reset your
'set default to (gcDefaultDir)' for the PDF-writer changes the default-settings of your application.

-Bart
 
Thanks Bart

I found that out from previous trial and error but it is an important point to note and good of you to draw attention to it.

Kaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top