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

Does the Adobe Acrobat SDK work with VFP?

Status
Not open for further replies.

mkrausnick

Programmer
Apr 2, 2002
766
US
The doc says the examples are in VB. I was just wondering:
1) If it works at all with VFP before I spend the $99 on it, and
2) Do you have a sample of working call syntax in VFP(9) to create a PDF file by printing a VFP report as was possible with the now-dead PDFWRITER printer driver.

The important feature that I'm looking for is the ability to programmatically assign the PDF filename at creation time so as to avoid the "Save As" dialog box.

Thanks!

Mike Krausnick
Dublin, California
 
Hi Mike,

yes, you can do with Acrobat 7 almost the same you were doing with version 5.

Note that I do not have the Acrobat sdk, I have found this solution on the VBA forum and I have adapted it to VFP.
Thanks to djRixMix
Programmatically create a PDF from Access 2002

I don't know how to avoid the automatic opening of the generated PDF file by Acrobat Reader.
I can disable the option in the "Adobe PDF" printer preference, but this is a system wide option ...

Include in your project the class REGISTRY.VCX and REGISTRY.H you can find in:
C:\Program files\Microsoft Visual FoxPro 9\Ffc\

Gianni

Code:
#DEFINE HKEY_CLASSES_ROOT           -2147483648
#DEFINE HKEY_CURRENT_USER           -2147483647
#DEFINE HKEY_LOCAL_MACHINE          -2147483646
#DEFINE HKEY_USERS                  -2147483645

local loRegistry, lcValue, lnRootFolder1, lcRootFolder1, lcOutputFile
loRegistry = NewObject("Registry", "registry")
lnRootFolder1 = HKEY_CURRENT_USER
lcRootFolder1 = "Software\Adobe\Acrobat Distiller"
lcOutputFile = "C:\PRINT FILES\MYFILE.PDF"

set printer to name "Adobe PDF"

erase (lcOutputFile)

loRegistry.SetRegKey(_vfp.ServerName, lcOutputFile, ;
	lcRootFolder1 + "\PrinterJobControl", lnRootFolder1, .t.)

report form YourReport to printer noconsole

private m.set_escape
m.set_escape = set("ESCAPE")
set escape OFF
keyboard "{SPACEBAR}" plain clear
=inkey()
do while .t.
	lcValue = ""
	loRegistry.GetRegKey(_vfp.ServerName, @lcValue, ;
		lcRootFolder1 + "\PrinterJobControl", lnRootFolder1)
	if ! empty(lcValue)
		wait window timeout 1 ;
			"Waiting for the Adobe PDF Driver ... [ESC] Stop waiting" + ;
			" (use only if something goes wrong)"
		if lastkey() = 27
			EXIT
		endif
		LOOP
	endif
	EXIT
enddo
set escape &set_escape

* at this point the PDF files is ready
 
If all you want to do is print a PDF file from VFP, there are a LOT of PDF "print drivers" our on the web - reasonably priced. Some of the freebies also work, but "brand" your output document in some manner.

Once you have installed your PDF Print Driver, then within your application, you only need to change your printer to the "PDF Printer" and issue your command:
REPORT FORM MyReport NOCONSOLE TO PRINT

Generally this is interactive in that most PDF print drivers will request a file name to save to. But there might be others which can be configured to use a passed parameter or a previously saved generic name.

Good Luck,
JRB-Bldr
 
Mike,

The important feature that I'm looking for is the ability to programmatically assign the PDF filename at creation time so as to avoid the "Save As" dialog box.

Many PDF printer drivers allow you to do that, albeit indirectly. For example, in the Docucom driver I use ( you can do it by programmatically editing an INI file.

The PDF printer drivers are usually much simpler than using the Adobe SDK.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike!

when you buy the SDK, please post the code to set peferences like do not open the file after printing, choose between color and bw, ecc.

Thanks in advance!
Gianni
 
Rick Strahl wrote about avoiding Acrobat prompts a long, long time ago. I'll bet the paper's on his website.

Tamar
 
Hi Tamar,

I know how to control these with version 5, but I don't know how with the latest version of Adobe Acrobat printer driver.

The SDK isn't free ...

Gianni
 
Thanks everyone for the responses. Gianni's routine works almost exactly like what I want. It creates the PDF file without the dialog box.

I had to make one change - comparing Gianni's routine to the one I wrote for Acrobat 5 (thread184-677355), his call to SetRegKey had one additional parameter, the ".t." at the end. The call fails with a "must provide additional parameters" dialog. Removing the .T. (the fifth parameter) corrected this.

However, after the file is created, it is previewed in Acrobat. Anybody know of a way to suppress that?

Mike Krausnick
Dublin, California
 
Hi Mike,

after experimenting I have found a better way to check for the printing job done.

Change this block of code:

Code:
do while .t.
    lcValue = ""
    loRegistry.GetRegKey(_vfp.ServerName, @lcValue, ;
        lcRootFolder1 + "\PrinterJobControl", lnRootFolder1)
    if ! empty(lcValue)
        wait window timeout 1 ;
            "Waiting for the Adobe PDF Driver ... [ESC] Stop waiting" + ;
            " (use only if something goes wrong)"
        if lastkey() = 27
            EXIT
        endif
        LOOP
    endif
    EXIT
enddo

with this:

Code:
do while .t.
    if ! file(lcOutputFile)
        wait window timeout 1 ;
            "Waiting for the Adobe PDF Driver ... [ESC] Stop waiting" + ;
            " (use only if something goes wrong)"
        if lastkey() = 27
            EXIT
        endif
        LOOP
    endif
    EXIT
enddo

The function SetRegKey in REGISTRY.VCX accept the 5th parameter.
It is located here:
C:\Program files\Microsoft Visual FoxPro 9\Ffc\

Have you decided not to buy the SDK? [surprise]

Gianni
 
Gianni,

Yes, I have decided not to buy the SDK. With your excellent routine I no longer need it, assuming I can solve the "preview in Adobe Reader" problem. Do you know a way to keep the PDF from being displayed automatically after it is created?



Mike Krausnick
Dublin, California
 
Hi Mike!

No, I haven't found a way yet.
As soon as I find it, you and the forum will be informed and supplyed with the code.

I have found another annoyance:
printing to PDF this way a coloured report, come out in grey,
printing to PDF choosing directly the Adobe PDF printer driver, come out as expected, in colors!

Can you confirm the behavior?

The Adobe PDF driver is, by default, for printing in colors.

Windows XP Home/Pro SP2 Italian
Adobe Acrobat 7 English trial version
Visual Foxpro 9 SP1 English

Gianni
 
OK, two things to finally put this to bed:

1) To keep the PDF from being displayed automatically after it is created, in Properties for the Adobe PDF priner, click "Printing Preferences" and uncheck "View Adobe PDF results"

2) If you select "Print directly to printer" in the Advanced tab of Properties for the Adobe PDF priner, you don't need the section of code after the REPORT FORM that pauses until the registry key goes away. The program will wait for the report to print before resuming execution.




Mike Krausnick
Dublin, California
 
Thanks, but I already have Acrobat. Also, the problem is solved.

Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top