How to save Navision Reports as PDF

ara3nara3n Member Posts: 9,255
edited 2014-09-05 in NAV Tips & Tricks
Hello There are a lot of topics on creating pdf documents from Navision reports.
Here is an example on how to do it. There are a lot of windows pdf printers out there. The one I've used is a free open source version. To use this example please do the following.

Go to sourceforge.net and download PDFCreator

Here is a direct link.

http://sourceforge.net/project/showfiles.php?group_id=57796

Install the pdfCreator Printer. Once install copy and paste the form bellow, import it and compile it and run it. That's it.
OBJECT Form 50100 Example Report to PDF files
{
  OBJECT-PROPERTIES
  {
    Date=05/13/07;
    Time=[ 8:06:37 PM];
    Modified=Yes;
    Version List=PDFCreator;
  }
  PROPERTIES
  {
    Width=14080;
    Height=7370;
    OnOpenForm=BEGIN
                 IF ISCLEAR(PDFCreator) THEN
                   CREATE(PDFCreator);
                 IF ISCLEAR(PDFCreatorError) THEN
                   CREATE(PDFCreatorError);

                 ReportID := REPORT::"Item List";
                 IF Object.GET(Object.Type::Report,'',ReportID) THEN;
                 FileDirectory := 'C:\';
                 FileName := 'example.pdf';


                 PDFCreatorError := PDFCreator.cError;

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

  }
  CONTROLS
  {
    { 1000000000;CommandButton;4180;4070;5060;1210;
                                                 CaptionML=ENU=Print and save as PDF;
                                                 OnPush=BEGIN
                                                          Window.OPEN('processing');
                                                          WindowisOpen := TRUE;
                                                          IF FileName = '' THEN
                                                            ERROR('Please specify what the file should be saved as');

                                                          Object.GET(Object.Type::Report,'',ReportID);

                                                          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;

                                                          REPORT.RUNMODAL(ReportID,FALSE,TRUE);
                                                        END;
                                                         }
    { 1000000001;TextBox;4180 ;990  ;3080 ;770  ;SourceExpr=ReportID;
                                                 TableRelation=Object.ID WHERE (Type=CONST(Report));
                                                 OnValidate=BEGIN
                                                              Object.GET(Object.Type::Report,'',ReportID);
                                                            END;
                                                             }
    { 1000000002;TextBox;4180 ;2310 ;9350 ;660  ;Editable=No;
                                                 SourceExpr=FileDirectory+FileName;
                                                 OnAssistEdit=VAR
                                                                txtWorkFileName@1000000001 : Text[250];
                                                                intSlashPos@1000000000 : Integer;
                                                                txtFileName@1000000002 : Text[100];
                                                              BEGIN
                                                              END;
                                                               }
    { 1000000003;Label  ;220  ;990  ;3190 ;770  ;CaptionML=ENU=Report ID }
    { 1000000004;Label  ;220  ;2310 ;3300 ;550  ;CaptionML=ENU=Save PDF as }
    { 1000000005;TextBox;7370 ;990  ;6050 ;770  ;Editable=No;
                                                 SourceExpr=Object.Name;
                                                 TableRelation=Object.ID WHERE (Type=CONST(Report));
                                                 OnValidate=BEGIN
                                                              Object.GET(Object.Type::Report,'',ReportID);
                                                            END;
                                                             }
  }
  CODE
  {
    VAR
      FileDirectory@1000000000 : Text[100];
      FileName@1000000010 : Text[100];
      ReportID@1000000001 : Integer;
      Object@1000000002 : Record 2000000001;
      PDFCreator@1000000006 : Automation "{1CE9DC08-9FBC-45C6-8A7C-4FE1E208A613} 4.1:{3A619AE4-50EC-46C8-B19E-BE8F50DD2F22}:'PDFCreator'.clsPDFCreator" WITHEVENTS;
      PDFCreatorOption@1000000005 : Automation "{1CE9DC08-9FBC-45C6-8A7C-4FE1E208A613} 4.1:{F8F15298-30FD-427C-BDFA-55E9AB615632}:'PDFCreator'.clsPDFCreatorOptions";
      PDFCreatorError@1000000004 : Automation "{1CE9DC08-9FBC-45C6-8A7C-4FE1E208A613} 4.1:{082391C9-8188-4364-B4FD-66A1524B2097}:'PDFCreator'.clsPDFCreatorError";
      DefaultPrinter@1000000003 : Text[200];
      Window@1000000007 : Dialog;
      WindowisOpen@1000000008 : Boolean;
      FileDialog@1000000009 : Codeunit 412;

    EVENT PDFCreator@1000000006::eReady@1();
    BEGIN

      PDFCreator.cPrinterStop := TRUE;
      PDFCreator.cDefaultPrinter := DefaultPrinter;
      PDFCreator.cClose();
      IF WindowisOpen THEN
        Window.CLOSE;
      WindowisOpen := FALSE;
    END;

    EVENT PDFCreator@1000000006::eError@2();
    BEGIN
      ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description);
    END;

    BEGIN
    {
      Author: Ahmed Amini
      Email: ara3n(NOSPAM)@hotmail.com
    }
    END.
  }
}


this is an example on how to create through code. You can use the example and modify it to automatically send statements to customers, email invoices all in one batch job.

Enjoy.

[EDIT] PLEASE BE AWARE THAT NEWER VERSION OF PDFCREATOR INSTALLS MALWARE :!:
I suggest to use Bullzip instead.You see the example here here. http://mibuso.com/blogs/ara3n/2008/08/0 ... ts-to-pdf/
Or Follow the following process to install PDF Creator without malware.
viewtopic.php?f=5&t=35076&start=0


[EDIT]
Ahmed Rashed Amini
Independent Consultant/Developer


blog: https://dynamicsuser.net/nav/b/ara3n
«13456710

Comments

  • David_SingletonDavid_Singleton Member Posts: 5,479
    =D>
    David Singleton
  • WaldoWaldo Member Posts: 3,412
    Too bad it won't install under Vista :|

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,255
    They are working for version 9.4 for Vista.

    http://www.pdfforge.org/node/816
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    OK, I'm an official PDFCreator tester now :|

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,255
    that is great. I'm guessing your company is using vista?
    usually 99 % of Dynamics nav users don't use Vista. So it'll take a while to move to vista for nav users.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    My company isn't using Vista ... I'm using it.

    And I'd like to keep it this way at the moment, knowing what stuff I had to do to make Vista "workable" for me.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,255
    I'm trying to stay away from Vista as long as possible.
    The longer I wait, the more apps will be ready for it.
    My guess, probably when my laptop dies on me.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • aliennavaliennav Member Posts: 449
    Hey ma'an it's going grt but what i have to do when i want to print some particular no. of reports.
    Example--i converted sales invoice in PDF ,what i have to do if i want to convert only few no. of invoices.
    Where i have to mention it??
  • ara3nara3n Member Posts: 9,255
    you have to modify the object.
    Or just go to the posted invoice and select print and then select pdfcreator as the printer.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • aliennavaliennav Member Posts: 449
    What if i want to print sales invoice report and that too invoice no. 10,20,30.... etc. only.
    where can i give the values in coding.
    Thanx in advance.
  • rsfairbanksrsfairbanks Member Posts: 107
    Thank you very much for this Rashed.

    We only have report writer but have been able to follow this and create then send emails for purchase orders, sales confirmations and invoices.

    I did have problems in saving the file before emailing, but this was overcome by setting the printer properties (advanced) to print directly to printer instead of the default Spool.

    Not sure if there is an automation for this.

    Anyway over the moon \:D/
  • ara3nara3n Member Posts: 9,255
    you are welcome.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Gary.LoGary.Lo Member Posts: 5
    Very good.. thanks for your help!!! =D>
  • ara3nara3n Member Posts: 9,255
    welcome.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • sertu21sertu21 Member Posts: 8
    I am using free software CutePDF. Just run report, print and select CutePDF Writer as a printer. That will generate you pdf-file. I am using XP SP2.

    http://www.cutepdf.com/Products/CutePDF/writer.asp
    Download and install both CutePDF and Converter.
  • WaldoWaldo Member Posts: 3,412
    Since a few weeks, we 're using eDoc as well. It's quite cheap (30$/PC) and very fast.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,255
    nothing quiet beats Free.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    True, but I need support for Vista.

    And free usually means "not supported" in the way when something goes wrong, you're on your own...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • DenSterDenSter Member Posts: 8,304
  • WaldoWaldo Member Posts: 3,412
    DenSter wrote:
    CuteFTP works on Vista.

    You mean CutePDF :wink:?
    I should have to try this ... .

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • kirankumarkirankumar Member Posts: 29
    Hi

    I have imported the Code U have given in Mibuso Forum.

    The 'Report to PDF Conversion' its working fine But as U suggest in that when the Report is Run it should Print and Make PDF of that.

    The First of it is working that is making PDF of the Report But it shoud't Print the Report along with it.

    Regards
    Kiran.
    Hi
  • ara3nara3n Member Posts: 9,255
    Check your PDF Creator Setting. In the Print Program option make sure the setting Print after saving is unchecked.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSterDenSter Member Posts: 8,304
    Waldo wrote:
    DenSter wrote:
    CuteFTP works on Vista.

    You mean CutePDF :wink:?
    I should have to try this ... .
    Yes I mean CutePDF :mrgreen:
  • kirankumarkirankumar Member Posts: 29
    Hi

    Rashed. Its very much useful to convert the Report in to some readable form by PDF.

    I have imported your code its working fine for Converting the specified PDF from Backend but not able to Print that.

    Is there anyway to get lookup from the Req.form the report list So that we can select the Particular Report to Convert in to PDF and at the same
    time print also.

    Pls, Check that and Provide me the Solution.

    Regards,
    Kiran.
    Hi
  • ara3nara3n Member Posts: 9,255
    Hello KiranKumar
    You don't need the example in order to create a report and print it at the same time.
    you just print any nav report and select the pdfcreator as your printer.

    As far as modifyin the code that part you can try and do it yourself. This example I've posted here is an example on how to do it. You can modify it how ever you want to.
    There are thousands of way that people would modify it to make it work for what they need. I will not post every request or do your programming. You can try and find and NSC to do it for you. If you have specific questions concerning code, pleasae feel free and ask them away.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kirankumarkirankumar Member Posts: 29
    I have no mean of Critisise the Code you written.

    I am very much enthusiastic to know more than what i learnt till now..

    you know its just meet of discussion.


    Once again.............Sorrry


    Regards
    kiran.
    Hi
  • DiddenDidden Member Posts: 8
    I seem to be missing CU 412, therefor I can't compile the form.
    Can any 1 tell me what it is?

    Installed PDF writer already.
  • ara3nara3n Member Posts: 9,255
    delete the variable and any place where it's being reference. you don't need it.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DiddenDidden Member Posts: 8
    Thanks, I will try that
  • Shabna_NazarShabna_Nazar Member Posts: 10
    The code is working fine, but i'm facing some problem

    1. i dont want the report to be printed. So i commented the code for that, then it is not working
    2. Even if i changed the name of the output file, output pdf file is always saved as 'example'.

    Thanks & Regards,
    Shabna.
Sign In or Register to comment.