Wiki Home

Win 2 PDF

Namespace: Wiki
Win 2 PDF creates PDF documents from any application on the Windows NT, 2000, or XP operating systems. It installs as a printer, so users simply 'print' to create PDF files from MS-Word, Excel, Quicken, Internet Explorer, Outlook, Netscape, or ANY Windows application that allows you to print.

Prices are $35 for a single copy, with discounts available for multiple licenses. Win 2 PDF Pro is also available which supports encryption and advanced settings to restrict printing, copying, and editing capability.

Visit for more information.

I've used Win 2 PDF from VFP code and had good results. In addition to being available with the rest of your installed printers from printer dialogs, it allows you to send files 'through it' via code too, controlling the name and location. Maybe all PDF drivers do this but one thing to keep in mind if using Win 2 PDF: it changes VFP's current working directory to the directory where you save the file so whether you are programatically puting a file somewhere or if your users may be selecting Win 2 PDF from the printer prompt dialog and selecting a location, make sure you save your working directory and set it back after the code that uses Win 2 PDF (like a REPORT FORM call)

The code sample below does that and shows some of the code I use when programmatically sending files to Win 2 PDF to a location and filename I'm controlling elsewhere in code. (The registry key to put the filename into was given at the website.)

Andy Needham

03/05/2003: Simplified the sample code a bit and commented it
02/02/2007: Fixed directory saving line to handle spaces in path and added code sample for appending or prepending to existing PDFs Andy Needham

* Key used by Win2PDF for name of file to create (from their documentation)
    lcpdfkey = "HKEY_CURRENT_USER\Software\VB and VBA Program Settings"+;
        "\Dane Prairie Systems\Win2PDF\PDFFileName"

    lcAppendkey = "HKEY_CURRENT_USER\Software\VB and VBA Program Settings"+;
        "\Dane Prairie Systems\Win2PDF\PDFAppendFile"

    lcPrependkey = "HKEY_CURRENT_USER\Software\VB and VBA Program Settings"+;
        "\Dane Prairie Systems\Win2PDF\PDFPrependFile"

    WAIT WINDOW "Attempting to set up Win2PDF print driver..." NOWAIT NOCLEAR

* Search the installed printers to find the name of the
* Win2PDF 'printer' so we can SET PRINTER TO it
    llfoundpdf = .F.
    DIMENSION laprinters[10,2]
    lnprintercount = APRINTERS(laprinters)
    IF lnprintercount > 0
        FOR i = 1 TO lnprintercount
            IF "WIN2PDF" $ UPPER(laprinters[i,1])
                lcpdfname = laprinters[i,1]
                llfoundpdf = .T.
        ENDFOR &&* i = 1 TO lnPrinterCount

    IF llfoundpdf
        STORE "" TO lcp3
        lcp3 = SET("print",3)

* Change printer to it
        SET PRINTER TO NAME (lcpdfname)

* Instantiate a Windows Scripting Object so we can write
* to the registry the name of the file we want Win2PDF to create

        lowshshell = CREATEOBJECT("")
        IF VARTYPE(lowshshell) <> "O"
            ?'Error instantiating Windows Scripting Object.  Cannot continue.'
        ?'Win2PDF printer driver not found.'

* do stuff here to get ready for REPORT FORM call
* (get cursor, select it, etc.)...
* ...
USE testtable

* Save the old directory (Win2PDF changes the current directory
* to where it saves the file: bad for VFP if you don't know it...)
    lccurrentdirectory = '"'+ADDBS(SYS(5) + SYS(2003))+'"'

* Write the name we want to make the file to the registry
    lcOriginalfilename = "C:\mytestfile1.pdf"
    lowshshell.regwrite(lcpdfkey, lcOriginalfilename)

* 'Print' the report.
* Win2PDF puts it in a PDF named "C:\MyOutput\mytestfile.pdf"

* 02/02/2007 Prepend and Appendsamples added.  2 new registry keys added at top of program for this
*** NOTE: These work the opposite of how I expected they would:
*** In the append example the original file is appended to the new REPORT call.  I assumed that append would append the new output to the original PDF.
*** Same with the prepend example: the original is prepended onto the new REPORT

*** You can make both file names the same: ie you can set lcpdfkey and lcAppendkey to lcOriginalfilename and do it in place
*** So anyway: test the order of what you are doing between append and prepend to make sure you get the output in the order you want.
***   If prepend puts it on the wrong spot switch to append (and vice versa).

    lcAppendedfilename = "C:\mytestfile2.pdf"
    lowshshell.regwrite(lcpdfkey, lcAppendedfilename)
    lowshshell.regwrite(lcAppendkey, lcOriginalfilename)

    lcPrependedfilename = "C:\mytestfile3.pdf"
    lowshshell.regwrite(lcpdfkey, lcPrependedfilename)
    lowshshell.regwrite(lcPrependkey, lcOriginalfilename)
    REPORT FORM prependtestreport TO PRINT NOCONSOLE

* Change directory back to where we were and set the printer back to what is was
    SET DEFAULT TO &lccurrentdirectory

Win 2 PDF Pro for Windows NT/2000/XP worked Ok for me: 128-bit encryption, control through Registry values. Creating VFP code for batch processing took comparatively short time -- Anatoliy Mogylevets
Category PDF
( Topic last updated: 2007.02.05 11:16:15 AM )