Options

Problem with PDFCreator

miksy123miksy123 Member Posts: 10
I am trying to automatically save a sales order to a specified location on my hard drive and I want to do it from inside the report (I have a reason for doing this). The problem is I get one big NOTHING. The file isn't there! Here is the code that I have in OnPostTrigger:
CLEAR(PDFCreatorOption);
CLEAR(PDFCreator);
CLEAR(PDFCreatorError);

FileDirectory := 'C:\';
FileName := 'example1.pdf';

IF ISCLEAR(PDFCreator) THEN
  CREATE(PDFCreator);
IF ISCLEAR(PDFCreatorError) THEN
  CREATE(PDFCreatorError);

PDFCreatorError := PDFCreator.cError;

IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN
     ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description);

IF ISCLEAR(PDFCreatorOption) THEN
  CREATE(PDFCreatorOption);
PDFCreatorOption := PDFCreator.cOptions;

PDFCreatorOption.UseAutosave := 1;
PDFCreatorOption.UseAutosaveDirectory := 1;
PDFCreatorOption.AutosaveDirectory := FileDirectory;
PDFCreatorOption.AutosaveFormat := 0; 
PDFCreatorOption.AutosaveFilename := FileName;

PDFCreator.cOptions := PDFCreatorOption;
PDFCreator.cSaveOptions(PDFCreatorOption);
PDFCreator.cClearCache();
DefaultPrinter := PDFCreator.cDefaultPrinter;
PDFCreator.cDefaultPrinter := 'PDFCreator';
PDFCreator.cPrinterStop := FALSE;

SLEEP(15000);

PDFCreator.cPrinterStop := TRUE;
PDFCreator.cDefaultPrinter := DefaultPrinter;
PDFCreator.cClose;
CLEAR(PDFCreator);

I have ordered the report to sleep for 15 seconds (15000 miliseconds) and wait for the .PDF file to be created, but I still get nothing. It simply doesn't create the file. I have only one Invoice and I think 15 seconds is more than enough for PDFCreator to create a file. I succeeded saving the file but I had to first initialize the PDFCreator printer from a codeunit, then RUNMODAL the report (also from codeunit) without starting the ReqWindow like this:
REPORT.RUNMODAL(ReportSelection."Report ID",FALSE,TRUE,SalesHeader);

I don't want to do it like this! I have a reason for not doing something like this and I want the code inside the report! I want it to create a .PDF file every time I preview/print the report...even from Object Designer. The user also needs to filter the report, use the request form before printing etc.

Thanks for helping me!

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,096
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    kinekine Member Posts: 12,562
    You have this code in OnPostTrigger of what? The reports itself? How you are handling on which printer the report is printed? You need to print it on PDFCreator printer and this code you are using must be used before and after the report is printed, it means before REPORT.RUN is called (setting the parmeters) and after it ended (waiting for creation of the file).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    miksy123miksy123 Member Posts: 10
    OMG I just realized that this doesn't work if I run the report with ReqWindow... :(
Sign In or Register to comment.