PDF Creator Processing.

I have a report that should save and send by email automatically to my customers. That far am able to save to a folder automatically and send by email still automatically BUT have to repeat the action 2 times. The problem is that the PDF creator seems to be very fast such that by the time its attaching and sending the email, the file is NOT ready. (File Not already saved). so whenever i repeat the action again, the file is already existing and can now be attached and send.

QS can someone assist me on what to do to automate this just the first time?

Thank you

Hi Fezih,

Maybe you can insert a SLEEP between the creation of the pdf, and the mailing of the pdf.
This would give the PDF-creator more time to save the file, before you try to fetch it.

Thanx Sander 4 yr reply. This SLEEP is strage to me. could u plz insert it for me on the relevant position.

These ar part of my codes where u can insert it:

Window.OPEN (‘processing’);
WindowisOpen := TRUE;
Object.GET (Object.Type::Report,’’,ReportID);
PDFCreatorOption := PDFCreator.cOptions;

PDFCreatorOption.UseAutosave := 1;
PDFCreatorOption.UseAutosaveDirectory := 1;
PDFCreatorOption.AutosaveDirectory := FileFolder;
PDFCreatorOption.AutosaveFormat := 0; //PDF file, you can also save in other formats
PDFCreatorOption.AutosaveFilename := FileName2;

PDFCreator.cOptions := PDFCreatorOption;
PDFCreator.cClearCache();

DefaultPrinter := PDFCreator.cDefaultPrinter;
PDFCreator.cDefaultPrinter := ‘PDFCreator’;
PDFCreator.cPrinterStop := FALSE;
REPORT.RUNMODAL(ReportID,FALSE,TRUE,customer2);
AttachFile := FileFolder+FileName2;

//WHILE NOT PDFCreatorPDFCreator.cClose DO;
IF Mail.NewMessage (EmailAdd, ‘’, Subject, Body, AttachFile, FALSE) THEN
NoOfEmails += 1;
MESSAGE(Text000, NoOfEmails);

Sure,

REPORT.RUNMODAL(ReportID,FALSE,TRUE,customer2);
// I assume this REPORT.RUNMODAL is where the actual pdf is created…
// Then insert the SLEEP here.
SLEEP(1000); // This will give a 1 sec sleep, maybe you need more, but keep it as short as possible.
AttachFile := FileFolder+FileName2;

//WHILE NOT PDFCreatorPDFCreator.cClose DO;
IF Mail.NewMessage (EmailAdd, ‘’, Subject, Body, AttachFile, FALSE) THEN
NoOfEmails += 1;
MESSAGE(Text000, NoOfEmails);

This is copied from the NAV-help…
SLEEP

Use this function to return control to the operating system for a specifiable amount of time.

SLEEP(Duration)

Duration

Data type: integer

The number of milliseconds to return control to the operating system for.

Comments

When using SLEEP, control is guaranteed to return to the operating system for at least Duration milliseconds (implying that the period may be longer, depending on what the operating system is doing at the time when control is to return to the caller.)

Try this:

``
IF NOT PDFFile.OPEN(AttachFileName) THEN BEGIN
Window.OPEN('#1############# - @2@@@@@@@@@@@@@@');
Window.UPDATE(1,'Creating PDF...');
REPEAT
Window.UPDATE(2,Counter);
Counter += 1;
SLEEP(100);
UNTIL PDFFile.OPEN(AttachFileName) OR (Counter > 10000); // FileDirectory + '\' + FileName) OR (Counter > 10000);
SLEEP(100);
PDFFile.OPEN(AttachFileName);
Window.CLOSE;
END;

Neat one David.
I’ll keep that one in mind.

Thanx i think it has worked as required. But have to try on computers of different speed. Otherwise i appreciate.

Great

The problem is not just the speed of the computer but also the size of the report. Anyway go with the solution that works for you.

Exactly which PDF Creator is this subject about?

PDF Creator is actually the name of the program.

http://sourceforge.net/projects/pdfcreator/

Its not bad as PDF generators go, though it does have a couple of issues. Three common ones.

  1. No support for Vista.

  2. Strange quirks with some versions that tend to act differently, so it important that you compile NAV objects with the same verison (of PDF creator) that the customer will use.

  3. There is no flag to tell you if the file conversion is complete (well there is a flag, but it seems to indicate that the process started, not that it finished). So its important to work out a way to be certain that the PDF file exists on disk.

Other than that its great. I especially like that it works great on Citrix, so its a great solution for report printing in complex citrix environments.

So all in all you will still say that this one is the best one which is currently available? Especially in Citrix environments?

Better to say is that I have been able to reolve all issues with it, and it works very reliably. I am sure there is better out ther, but this works, so I am happy. The Citrix part was very important for the projects I was working on, so the fact that it works well under citrix is an important factor.

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;

Hi,

I think I have found the solution. If you are using the code:

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;

to determine if PDFCreator is finished with the PDF conversion, (using the property PDFCreator.cIsConverted), you need to initialize this value to FALSE first. For some reason, it retains the value from previous runs.