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!

Using PDFCreator from Visual Foxpro (VFP9) to create .pdf file without interaction. 1

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have been using PDF Creator version 1.7.3 from my VFP application to create .pdf files from within the application, without the need for user dialog. I create a PDFCreator object, modify its properties, broadly as follows :

oPDFC = CREATEOBJECT(“PDFCreator.clsPDFCreator”,”pdfcreator”)
oPDFC.cOption(”UseAutosave”) = 1
. . . .
. . . .
oPDFC.cOption(“AutosaveFileName”) = m.lcFileName
SET PRINTER TO NAME (oPDFC.cDefaultPrinter)
REPORT FORM (m.lcRepName) NOCONSOLE TO PRINTER

This has generally worked, thank you. However I am experiencing a problem; If my program fails (no doubt because of my own errors), I am finding that the PDFCreator becomes disabled even for applications like Microsoft Word. It still exists as a printer (under Windows 7), and can be selected, but printing to this PDFCreator printer no longer has any effect: the File | Print command goes through all the motions, and Word thinks it has done its work, but no dialog (to select the output filename) is displayed.

The only way to resolve the problem is to un-install PDF Creator and to re-install it. I have done this several times.
I accept the responsibility of correcting my own errors, but feel that it is unfortunate that PDFCreator is then disabled for other applications like Word and Excel.

Does anyone know why this should be happening? And is there any way of re-enabling the PDF Creator printer when I have accidentally disabled it.

In an attempt to resolve the problem I have tried installing version 2.1 of PDFCreator. However my VFP application then fails at first base : the CREATEOBJECT() function returns the error :

Class definition PDFCreator.clsPDFCreator not found

I would like to know what sequence of commands I can use to generate a .pdf file from version 2.1 of PFCreator.

Thank you. Andrew Mozley


I realise that I should perhaps post this question on the PDFCreator Forum However, whenever I enter a title and the body of this query, then press Post Discussion, I get the message "Body is required" - so I am not doing very well! If anyone knows how to post questions on the PDFForge forum I would be grateful for that too . . .
 
I don't use PDFCreator, but from what you describe the settings you're making are in effect for all applications, the printer now also generates the PDF file you specify, if you print from Word, and no dialog appears.
Try it, the print will go to the file you specified in VFP, I'm quite sure.

You should always reset these settings after done printing, so other applications use the printer driver interactively.

Bye, Olaf.
 
I don't use PDFCreator either. But it's fairly obvious that your application is not changing the settings back to their normal values after a crash. You presumably have the code that does the resetting, but because the application stops with an error, that code is not being run.

If that's right, then the solution would be to run the resetting code from within your error-handler. Or, use a TRY/CATCH structure around the relevant report-printing code, and do the resetting if you catch an error.

But it makes me wonder what would happen if a user prints both from your application and (e.g.) Word at the same time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
>makes me wonder what would happen if a user prints both from your application and (e.g.) Word at the same time.

Yes, this situation, but also printing a series of documents, you really would need your own exclusive installation of PDFCreator and I wonder if that's possible. I doubt you're asked for the printer name you want during installation.

Bye, Olaf.
 
Yes, this situation, but also printing a series of documents, you really would need your own exclusive installation of PDFCreator and I wonder if that's possible

That makes perfect sense.

I wonder if you can rename the printer driver after you've installed it (you can with other PDF drivers, in my experience). If so, you might then be able to install a second instance. If you give the first one a cryptic name that users are unlikely to use, the problem won't arise.

But I think you should do the reset from within your error-handler in any case, if only for the sake of tidiness. I'd guess it would only be a matter of setting [tt]oPDFC.cOption("UseAutosave")[/tt] to 0.

By the way, when you say that, when you print from Word, nothing seems to happen, in fact the printing does take place, but it goes to the same file that you are using in VFP (and overwriting whatever was there before).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You have multiple choices, but first please accept my apologies because I forgot to reset the autosave mode.
At the end of the procedure, please add :
oPDFC.cOption("UseAutosave") = 0
After this updated sample, I post some supplementary solutions.

The updated sample (also I emphasize the possibility to generate pictures instead of PDF)
Code:
DECLARE Sleep IN kernel32 INTEGER
LOCAL lcRepName,lcFileName,lcFolder,oPDFC,lcOldDefaPrint,DefaultPrinter,laf[1],lnCount

CREATE CURSOR cc (ii I)
APPEND BLANK
GO top
lcFolder = ADDBS(JUSTPATH(SYS(16)))
lcRepName = m.lcFolder  + "cc.frx"
CREATE REPORT (m.lcRepName) FROM cc
lcFileName = "cc.pdf"

IF ADIR(laf,m.lcFolder+m.lcFileName) > 0
	ERASE (m.lcFolder+m.lcFileName)
	IF ADIR(laf,m.lcFolder+m.lcFileName) > 0
		MESSAGEBOX("Can't create " + m.lcFolder+m.lcFileName,16,"Erase the old PDF")
		RETURN
	ENDIF
ENDIF
lcOldDefaPrint = Alltrim(Set('PRINTER', 2))

oPDFC  = CREATEOBJECT("PDFCreator.clsPDFCreator","pdfcreator")
oPDFC.cStart("/NoProcessingAtStartup")
oPDFC.cOption("UseAutosave") = 1
oPDFC.cOption("UseAutosaveDirectory") = 1
oPDFC.cOption("AutosaveFormat") = 0
* 0 = PDF format
* 1 = PNG
* 2 = JPEG
* 3 = BMP
* 4 = PCX
* 5 = TIFF
DefaultPrinter = oPDFC.cDefaultprinter
oPDFC.cDefaultprinter = "pdfcreator"
oPDFC.cClearCache
ReadyState = 0
oPDFC.cOption("AutosaveFilename") = m.lcFileName
oPDFC.cOption("AutosaveDirectory") = m.lcFolder
oPDFC.cprinterstop=.F.

SET PRINTER TO NAME (oPDFC.cDefaultprinter) && Fix this 
REPORT FORM (m.lcRepName) NOCONSOLE TO PRINTER 

lnCount = 0
DO WHILE ADIR(laf,m.lcFolder+m.lcFileName) = 0 AND m.lnCount <= 40
    sleep(50)
    lnCount = m.lnCount + 1
ENDDO

oPDFC.cDefaultprinter = DefaultPrinter
****************************
* This is the the new line *
****************************
oPDFC.cOption("UseAutosave") = 0
****************************
****************************
oPDFC.cClearCache
RELEASE m.oPDFC
Set Printer To Name (m.lcOldDefaPrint)

In case of errors
1) You can reset the Autosave mode automatically using this small piece of code

Code:
**********************************************
* Small procedure to reset the autosave mode *
**********************************************
oPDFC  = CREATEOBJECT("PDFCreator.clsPDFCreator","pdfcreator")
oPDFC.cStart("/NoProcessingAtStartup")
oPDFC.cOption("UseAutosave") = 0
oPDFC.cClearCache
RELEASE m.oPDFC

2) The same thing cane be done manually.
If the PDFCreator application is not active in memory, launch it from Start -> All Programs -> PDFCreator -> PDFCreator and from the Printer menu, choose Options
If the PDFCreator application is still active in memory, select it from the lower-right corner of the screen, right click its icon and choose Options
If needed, expand the program node and click Auto-Save (from the left side); and from the right panel, untick Use Auto-save
Please click the link below, to see the picture.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
 http://files.engineering.com/getfile.aspx?folder=26dc9b0d-6c82-445c-a222-c5c255c0bd97&file=11.png
Thank you Vilhelm for your very clear instructions.

I have checked out the facility to fire up Start | All Programs | PDF Creator &c, and can see how to unset the Auto-save option. The next time that I get this error (no doubt caused by myself), I will use this to reset PDFCreator; I have every confidence!

On the other matters, is the facility of using PDFCreator from VFP available in version 2.1? As mentioned, I found that I could not create the PDFC object when I had version 2.1 installed, so have gone back to (your recommended) version 1.73.

Also are you able to post a message of the PDFforge forum; as mentioned, I get a message saying "Body is required", even though I have entered my message in the appropriate box; the 'Preview' button also does not seem to work (for me).

Thanks again; Andrew
 
I suppose version 2.1 is still under development (this is what I read in the installation wizard, at API section) and this is the reason for version 1.73 being still available.
I just downloaded and installed PDFCreator 2.1.1, then quickly I removed it and installed back the 1.73 version.

I didn't used their forum, so I can't help with that :-(

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top