How to save Navision Reports as PDF

ara3nara3n Posts: 9,132Member
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]
«13456710

Comments

  • David_SingletonDavid_Singleton Posts: 5,364Member
    =D>
    David Singleton
    Dynamics NAV Freelancer
    Dynamics Book
    Go-Live International
  • WaldoWaldo Posts: 3,412Member
    Too bad it won't install under Vista :|

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

    http://www.pdfforge.org/node/816
  • WaldoWaldo Posts: 3,412Member
    OK, I'm an official PDFCreator tester now :|

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Posts: 9,132Member
    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.
  • WaldoWaldo Posts: 3,412Member
    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 Posts: 9,132Member
    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.
  • aliennavaliennav Posts: 449Member
    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 Posts: 9,132Member
    you have to modify the object.
    Or just go to the posted invoice and select print and then select pdfcreator as the printer.
  • aliennavaliennav Posts: 449Member
    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 Posts: 114Member
    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 Posts: 9,132Member
    you are welcome.
  • Gary.LoGary.Lo Posts: 5Member
    Very good.. thanks for your help!!! =D>
  • ara3nara3n Posts: 9,132Member
    welcome.
  • sertu21sertu21 Posts: 8Member
    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 Posts: 3,412Member
    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 Posts: 9,132Member
    nothing quiet beats Free.
  • WaldoWaldo Posts: 3,412Member
    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 Posts: 8,047Member
  • WaldoWaldo Posts: 3,412Member
    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 Posts: 29Member
    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 Posts: 9,132Member
    Check your PDF Creator Setting. In the Print Program option make sure the setting Print after saving is unchecked.
  • DenSterDenSter Posts: 8,047Member
    Waldo wrote:
    DenSter wrote:
    CuteFTP works on Vista.

    You mean CutePDF :wink:?
    I should have to try this ... .
    Yes I mean CutePDF :mrgreen:
  • kirankumarkirankumar Posts: 29Member
    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 Posts: 9,132Member
    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.
  • kirankumarkirankumar Posts: 29Member
    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 Posts: 8Member
    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 Posts: 9,132Member
    delete the variable and any place where it's being reference. you don't need it.
  • DiddenDidden Posts: 8Member
    Thanks, I will try that
  • Shabna_NazarShabna_Nazar Posts: 10Member
    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.
«13456710
Sign In or Register to comment.