I have an issue with PDFCreator. This issue seems to be funny, as it is an intermittent problem that happens unexpectedly and without reason. Could also be the way I wrote my code…
I have written something that saves customer statements into pdf files in a folder. Each statement to 1 customer is 1 pdf file. Because of this, the PDFcreator is iterated once per statement print. Somehow, the pdf files created were not consistent. E.g. the first run would generate 120 files, the 2nd would generate 110 so on and so forth. I realised this happened more often, if I minimised Dynamics NAV and perform other things on the PC. Apparently, PDFcreator cannot lose window focus during the run.
I attach my code snippet below. It is written using a report with Customer as the data item.
Customer - OnAfterGetRecord()
OutPutFileName := ‘’;
IF ISCLEAR(PDFCreator) THEN BEGIN
CREATE(PDFCreator);
END;
IF ISCLEAR(PDFCreatorError) THEN
CREATE(PDFCreatorError);
PDFCreatorError := PDFCreator.cError;
IF PDFCreator.cStart(’/NoProcessingAtStartup’,TRUE) = FALSE THEN
ERROR(‘Status: Error[’ + FORMAT(PDFCreatorError.Number) + ']: ’ + PDFCreatorError.Description);
DateTimeStamp :=
FORMAT(TODAY, 0, ‘<Year,2><Month,2><Day,2>’) + ‘’ +
FORMAT(TIME, 0, '<Hours24,2><Minutes,2>_<Seconds,2>’);
PDFCreatorOption := PDFCreator.cOptions;
PDFCreatorOption.UseAutosave := 1;
PDFCreatorOption.UseAutosaveDirectory := 1;
PDFCreatorOption.AutosaveDirectory := FolderName;
PDFCreatorOption.AutosaveFormat := 0;
PDFCreatorOption.AutosaveFilename := FileName + Customer.“No.” + DateTimeStamp + ‘.pdf’;
PDFCreator.cOptions := PDFCreatorOption;
PDFCreator.cSaveOptions(PDFCreatorOption);
PDFCreator.cClearCache();
DefaultPrinter := PDFCreator.cDefaultPrinter;
PDFCreator.cDefaultPrinter := ‘PDFCreator’;
PDFCreator.cPrinterStop := FALSE;
// --------------------------------------------------------------------------------------------------------------------
CLEAR(Statement);
Cust.RESET;
Cust.COPYFILTERS(Customer);
Cust.SETRANGE(“No.”, “No.”);
Statement.SETTABLEVIEW(Cust);
Statement.USEREQUESTFORM(FALSE);
Statement.RUNMODAL;
WaitTime := 0;
REPEAT
SLEEP(1000);
WaitTime += 1000;
IF WaitTime = 60000 THEN
ERROR(‘Timeout error while waiting for PDFCreator.cIsConverted while printing for customer %1!’, “No.”);
UNTIL PDFCreator.cIsConverted;
PDFCreator::eReady()
PDFCreator.cDefaultPrinter := DefaultPrinter;
OutPutFileName := PDFCreator.cOutputFilename;
PDFProcessed += 1;