How to save Navision Reports as PDF

1246710

Comments

  • mgmmgm Member Posts: 126
    The code of Rashed is the text export of the object.
    Create a txt file. Copy the code of Rashed in it and save it.
    Import this in NAV and compile it.
    (compare the code with an object you export as a txt file)
  • ObiWanObiWan Member Posts: 21
    ara3n wrote:
    Btw bullzip doesn't have a way to change the the pdf printer to default printer, so you have to set it up in printer selection in NAV. Or make the pdf Printer as default.

    Hi, i use the PDFCreator without the default printer setting.
    I just use an SingleInstance CDU one command line to it
    SI.SetUsePDFCreator.
    In CDU 1, function FindPrinter i just call the SI cdu like this

    IF SI.GetUsePDFCreator THEN
    EXIT('PDFCreator');

    Function in SI is like this

    SetUsePDFCreator()
    UsePDFCreator := TRUE;

    GetUsePDFCreator() : Boolean
    TMPUsePDFCreator := UsePDFCreator;
    UsePDFCreator := FALSE;
    EXIT(TMPUsePDFCreator);

    Best regards ObiWan :D
  • MagnoMagno Member Posts: 168
    Hi,

    Does anyone know how to do this with the acrobat distiller?
    I need to be able to do it with this one. The company i work for does not want to start using another PDF writer, and believe me, they are going to hold on to that :(

    Any help would really be appreciated...
    There are no bugs, only random undocumented features...
    ---
    My Blog: http://NAV-Magno.be
  • ara3nara3n Member Posts: 9,256
    I've done it for a client a year ago.
    You have to set the destiller to automatically save the documents into a folder.

    Then in Nav you would wait till the pdf is finished creating.
    To find out when the pdf was done, I would try and change the datetime on the file. Once that I could change it I would then attach it to the email and email it out and delete it.

    It works but if something wasn't setup correctly, I wouldn't work.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ssissi Member Posts: 39
    We leveraged your Bullzip code into the Lanham Sales E-Mail codeunit so that the report is attached to an e-mail.

    We were able to create the PDF attachment if our default printer was set to "Bullzip PDF Printer." However, if we change our default printer back to our normal printer and add a record in Table 78, we no longer get the PDF attachment on the e-mail.

    Any ideas why this doesn't work?
    SaveReportAsHTML(ReportNo : Integer;SaveFileName : Text[250])
    SalesHeader.SETRECFILTER;
    
    IF ISCLEAR(BullZipPDF) THEN 
      CREATE(BullZipPDF); 
    
    ReportID := ReportNo; // REPORT::"Customer Listing";
    FileDirectory := 'C:\SE_Demo\Temp';
    
    Object.GET(Object.Type::Report,'',ReportID); 
    
    FileName := SaveFileName;
    BullZipPDF.Init; 
    BullZipPDF.LoadSettings; 
    RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE); 
    BullZipPDF.SetValue('Output',FileName);
    BullZipPDF.SetValue('Showsettings', 'never'); 
    BullZipPDF.SetValue('ShowPDF', 'no'); 
    BullZipPDF.SetValue('ShowProgress', 'no'); 
    BullZipPDF.SetValue('ShowProgressFinished', 'no'); 
    BullZipPDF.SetValue('SuppressErrors', 'yes'); 
    BullZipPDF.SetValue('ConfirmOverwrite', 'no'); 
    BullZipPDF.WriteSettings(TRUE); 
    REPORT.RUNMODAL(ReportNo,FALSE,FALSE,SalesHeader);
    
    TimeOut := 0; 
    WHILE EXISTS(RunOnceFile) AND (TimeOut < 10) DO BEGIN 
        SLEEP(1000); 
        TimeOut := TimeOut + 1; 
    END;
    
  • ara3nara3n Member Posts: 9,256
    Turn on the debugger and see what FindPrinter function returns from CU 1
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ssissi Member Posts: 39
    I did. It finds the record and sets PrinterName to Bullzip PDF Printer.

    I should mention that I manually typed in "Bullzip PDF Printer" in the Printer Name field in Table 78. The lookup does not work.
  • ara3nara3n Member Posts: 9,256
    The lookup works, but you have to run the form instead of the table.
    So run the form and select the printer.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ssissi Member Posts: 39
    I added a SLEEP statement before the AddAttachment function is run and it works. Thanks for your help.
  • ara3nara3n Member Posts: 9,256
    Sure and your are welcome and good luck.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • hs_mannhs_mann Member Posts: 17
    I have just finished PDFCreator on VISTA.

    During initial testing PDFCreator is working fine under VISTA Business.

    I am using the PDFCreator Version 0.9.5

    Many Thanks to Rashed for the code.

    During my search for PDFCreator i found various ways while checking for that PDFCreator has finished printing the report or not so that it can be send by email.

    I found a simple solution for the same.

    Try This
    Report.RUNMODAL(***,***,***);
    REPEAT
    UNTIL PDFCreator.cIsConverted;
    

    Harjot
  • elwin68elwin68 Member Posts: 153
    The solution to print to pdf is just what i'm looking for.
    I have installed PDFcreator and implemented the form in a standard 5.0 SP1 database.
    When pushing the button 'Print and save as PDF' the following happens:
    - The report is save as PDF
    - The dialog "Processing" stays open and waits
    - When looking in the Task Manager of windows pdfcreator stays in the
    task list.

    It looks if Navision is waiting for the task pdfcreator to close. Therefor the trigger PDFCreator::eReady() is not activated.

    Does anyone know what the problem is.
    Thanks in advance.
  • ara3nara3n Member Posts: 9,256
    you change the code and instead use thee following code mentioned by hs_mann

    REPEAT
    UNTIL PDFCreator.cIsConverted;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Boom-BoxBoom-Box Member Posts: 27
    hELlo dearest colleagues,

    there is no other way to begin this posting but thanking to Rashed [;)] it's an indeed great example.

    But i still get that 'processing' mistake everytime with pdf creator consuming 98% of my cpu and navision blocking unless i terminate pdf creator on task manager.
    then i get the also-mentioned 'can't call pdf.cclose' mistake.


    you change the code and instead use thee following code mentioned by hs_mann

    REPEAT
    UNTIL PDFCreator.cIsConverted;

    i tried this but it did not work...must i kill the automation? try to call the eReady event somehow? shoudn't it be automatically triggered?

    thanks for the help already given and
    thanks in advance as well


    miguel
  • ara3nara3n Member Posts: 9,256
    Hello you can use also bullzip.
    Here is my blog on this.


    http://mibuso.com/blogs/ara3n/2008/08/0 ... ts-to-pdf/
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ReinhardReinhard Member Posts: 249
    sometimes when I run the form to automatically email pdf reports, the reports are not generated. However, if at some point before that you go and manually run the report, then the form works fine. Anyone else experience this behavior?
  • mel_sadekmel_sadek Member Posts: 23
    Hi ara3n,

    The sample reports you created are a great service to everyone. Thanks.

    Now, I have a slight situation with PDFCreator that's really bugging me. I am running on Windows Vista, but surprisingly your code is running fine...except for one little glitch: I can't choose the destination filename. I set the AutoSave feature in the code, and I specify the filename and directory, but for whatever reason, I cannot save the PDF file to my desired location and name. In fact, I even have AutoSave checked in PDFCreator options, otherwise the save dialog keeps popping up, regardless of my code. Below is a snippet of my code...
    // GRAME01 - Add Start
    IF ISCLEAR(PDFCreator) THEN
      CREATE(PDFCreator);
    IF ISCLEAR(PDFCreatorError) THEN
      CREATE(PDFCreatorError);
    
    FileDirectory := 'C:\';
    FileName := 'example.pdf';
    
    PDFCreatorError := PDFCreator.cError;
    
    IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN
         ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description);
    
    Window.OPEN('processing');
    WindowisOpen := TRUE;
    IF FileName = '' THEN
      ERROR('Please specify what the file should be saved as');
    
    PDFCreatorOption :=  PDFCreator.cOptions;
    PDFCreatorOption.UseAutosave := 1;
    PDFCreatorOption.UseAutosaveDirectory := 1;
    PDFCreatorOption.AutosaveDirectory := FileDirectory;
    PDFCreatorOption.AutosaveFormat := 0;                       //PDF file, you can also save in other formats
    PDFCreatorOption.AutosaveFilename := FileName;
    
    PDFCreator.cOptions := PDFCreatorOption;
    PDFCreator.cClearCache();
    DefaultPrinter := PDFCreator.cDefaultPrinter;
    PDFCreator.cDefaultPrinter := 'PDFCreator';
    PDFCreator.cPrinterStop := FALSE;
    
    TempSalesInvoiceHeader.COPYFILTERS(Rec);
    Rec.SETRANGE("No.", Rec."No.");
    REPORT.RUNMODAL(10074,FALSE,TRUE, Rec);
    Rec.COPYFILTERS(TempSalesInvoiceHeader);
    

    As you can see, my code is almost exactly the same as yours, but I simply can't get it to autosave and use my filename and directory.

    Please help!

    Thanks in advance for your support.
  • Boom-BoxBoom-Box Member Posts: 27
    hI THERE again!

    just wanted to say i'm using bullzip now and it works just fine!

    thx a lot! it's perfect!

    best regards,

    miguel andrade
  • ara3nara3n Member Posts: 9,256
    Boom-Box wrote:
    hI THERE again!

    just wanted to say i'm using bullzip now and it works just fine!

    thx a lot! it's perfect!

    best regards,

    miguel andrade

    I'm glad that it works. Enjoy.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ArtursArturs Member Posts: 30
    Regards,
    Arturs Gedvillo
    CTO
  • ara3nara3n Member Posts: 9,256
    So why did Vista cross the road?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • pballypbally Member Posts: 4
    Thanks to Rash,

    Don't use PDF Creator in NAV 5.0 SP1 environment.
    BullZip is the good solution. It works perfectly.

    Patrice
  • David_SingletonDavid_Singleton Member Posts: 5,479
    pbally wrote:
    Don't use PDF Creator in NAV 5.0 SP1 environment.

    Why not?
    David Singleton
  • pballypbally Member Posts: 4
    With Pdf creator in a NAV 5.0 SP1 context, you have to stop the process manually!!!
    You don't have this problem with Bullzip.
    Thank's again to Rashed.
    Patrice
  • David_SingletonDavid_Singleton Member Posts: 5,479
    pbally wrote:
    With Pdf creator in a NAV 5.0 SP1 context, you have to stop the process manually

    Can you explain what you mean by this?
    David Singleton
  • ReinhardReinhard Member Posts: 249
    when you call PDFCreator.Close it will just hang, consuming any CPU resources not assigned to System Idle Process

    This has happened to me with 3.7
  • rnunesrnunes Member Posts: 9
    Hi,

    i want to set a password on a pdf file and i have this code :

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

    PDFCreatorError := PDFCreator.cError;

    IF PDFCreator.cStart('/NoProcessingAtStartup') = FALSE THEN
    ERROR('Status: Error: ' + PDFCreatorError.Description);

    PDFCreatorOption := PDFCreator.cOptions;
    PDFCreatorOption.UseAutosave := 1;
    PDFCreatorOption.UseAutosaveDirectory := 1;
    PDFCreatorOption.AutosaveFilename := 'Recibo de Vencimento.pdf';
    PDFCreatorOption.AutosaveFormat := 0;
    PDFCreatorOption.AutosaveDirectory := 'C:\Temp';
    PDFCreatorOption.PDFUseSecurity:=1;
    PDFCreatorOption.PDFDisallowCopy:=1;
    PDFCreatorOption.PDFDisallowModifyContents:=1;
    PDFCreatorOption.PDFDisallowPrinting:=1;
    PDFCreatorOption.PDFOwnerPass:=1;
    PDFCreatorOption.PDFOwnerPasswordString:='teste';
    PDFCreatorOption.PDFUserPass:=1;
    PDFCreatorOption.PDFUserPasswordString:='teste';
    PDFCreatorOption.PDFHighEncryption:=1;
    PDFCreator.cOptions := PDFCreatorOption;
    PDFCreator.cClearCache();
    DefaultPrinter := PDFCreator.cDefaultPrinter;
    PDFCreator.cDefaultPrinter := 'PDFCreator';
    PDFCreator.cPrinterStop := FALSE;

    REPORT.RUNMODAL(50101,FALSE,FALSE,EmpPDF);

    PDFCreator.cClose;
    CLEAR(PDFCreatorOption);
    CLEAR(PDFCreator);
    CLEAR(PDFCreatorError);

    but it doesn't work. It creates the file but no password.

    Any clues?

    Best regards
  • ara3nara3n Member Posts: 9,256
    Try this
    //TEST PASSWORD
    PDFCreatorOption.PDFUseSecurity :=1;
    PDFCreatorOption.PDFOwnerPass := 1;
    PDFCreatorOption.PDFOwnerPasswordString := 'MasterPass';
    
    PDFCreatorOption.PDFDisallowCopy := 1;
    PDFCreatorOption.PDFDisallowModifyContents := 1;
    PDFCreatorOption.PDFDisallowPrinting := 1;
    
    PDFCreatorOption.PDFUserPass := 1;
    PDFCreatorOption.PDFUserPasswordString := 'UserPass';
    
    PDFCreatorOption.PDFHighEncryption := 1;
    //TEST PASSWORD 
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • rnunesrnunes Member Posts: 9
    thanks, but no success...
  • ara3nara3n Member Posts: 9,256
    It has worked for others.

    viewtopic.php?f=5&t=18331&st=0&sk=t&sd=a&start=45

    So I don't know why it would not work for you. I would try and reboot.

    Make sure the code is exactly as the example above.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.