How to save Navision Reports as PDF

1457910

Comments

  • Dave_beDave_be Member Posts: 35
    Do you have a code snippet to obtain this?
  • ara3nara3n Member Posts: 9,255
    ara3n wrote:
    mgm wrote:
    Thanx Rashed,

    What a SERVICE!

    This is what I added to make Bullzip default printer.
    IF NOT lPrinterSelection.GET('',lReportID) THEN BEGIN
      lPrinterSelection.INIT;
      lPrinterSelection."Report ID" := lReportID;
      lPrinterSelection."Printer Name" := 'Bullzip PDF Printer';
      lPrinterSelection.INSERT;
    END;
    

    Works great!
    Thanx again.

    Maarten

    Here is the code.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Dave_beDave_be Member Posts: 35
    And after the report is print I probably need to destroy the newly created record in "Printer Selection"?
  • ara3nara3n Member Posts: 9,255
    Yes otherwise it will use bullzip as default printer for that report when the user prints.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Dave_beDave_be Member Posts: 35
    Ok, everything works so far but the only thing that's kind of strange is the fact that somethime a "0" reference for the bullzip printer is created in the printer selection.
  • ara3nara3n Member Posts: 9,255
    paste your code on how you are inserting and deleting record from report selection.

    Also delete the 0 record first.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Dave_beDave_be Member Posts: 35
    recSalesHeader.SETRANGE("Document Type", Rec."Document Type");
    recSalesHeader.SETRANGE("No.", Rec."No.");
    recVendor.GET("Buy-from Vendor No.");
    
    //Printer tijdelijk instellen
    IF NOT lPrinterSelection.GET('',ReportID) THEN BEGIN
      lPrinterSelection.INIT;
      lPrinterSelection."Report ID" := ReportID;
      lPrinterSelection."Printer Name" := 'Bullzip PDF Printer';
      lPrinterSelection.INSERT;
    END;
    
    IF ISCLEAR(BullZipPDF) THEN
    CREATE(BullZipPDF);
    Window.OPEN('bezig met verwerken ######################1##');
    ReportID := REPORT::AankoopOrder;
    FileDirectory := 'C:\TMP-PDF\';
    FileName := 'IO'+"No." + '.pdf';
    
    
    Object.GET(Object.Type::Report,'',ReportID);
    
    
    
    BullZipPDF.LoadSettings;
    RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
    BullZipPDF.SetValue('Output',FileDirectory+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(ReportID,FALSE,FALSE,recSalesHeader);
    
    TimeOut := 0;
    WHILE EXISTS(RunOnceFile) AND (TimeOut < 10) DO BEGIN
    SLEEP(1000);
    TimeOut := TimeOut + 1;
    END;
    Window.CLOSE;
    cuMail.NewMessage(recVendor."Fax No.",Text036 + ' ' + "No.",'',FileDirectory+FileName,TRUE);
    IF lPrinterSelection.GET('',ReportID) THEN BEGIN
    
    //Printer terug verwijderen
      lPrinterSelection.INIT;
      lPrinterSelection."Report ID" := ReportID;
      lPrinterSelection.DELETE;
    END;
    
  • ara3nara3n Member Posts: 9,255
    change the code to the following.
    Window.CLOSE;
    cuMail.NewMessage(recVendor."Fax No.",Text036 + ' ' + "No.",'',FileDirectory+FileName,TRUE);
    
    lPrinterSelection.DELETE;
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • MonoMono Member Posts: 3
    I have been lurking in this thread for a little while, and I'd like to thank Rashed for this contribution!

    I've been dabbling with bullzip for a bit, myself now. What I was curious about, were the settings that one can use for Bullzip (such as ShowPDF, ShowProgressFinished,...) It might have been posted before, but I've looked through this thread before and haven't found it as of yet:

    http://www.biopdf.com/guide/settings.php

    These are the settings that can be used as the .SetValue('configname', 'configvalue'); parameters.

    Rashed already incorporated those of most value, but maybe someone else out there could make use of another parameter.
    RememberLastFileName, RemeberLastFolderName, ShowSaveAs, etc... might improve the usability for your users. It also seems possible to embed watermarks, merge PDF files, password-protect files, you can even pass on the way the document is supposed to be viewed in the default viewer, after output (though not all viewers might accept those parameters).

    Do note, the above website is for bioPDF, the commercial "branch" for BullZip, though the functions seem to remain the same, from what I have been able to test.

    The only thing I'm missing, is a mail function... Anyone had any luck on that with BullZip?
  • ara3nara3n Member Posts: 9,255
    i'm sure you know that you can use smtp to send the pdf as email.
    And thanks for the link and welcome to mibuso with your first post. :)
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • MonoMono Member Posts: 3
    Thank you for the warm welcome! Truth is, I have posted here before, rarely. But it seems I forgot the account details...

    And, you're welcome. Whatever I can do to attribute to your awesome post.

    I'm not quite a developer. I do mess around in code very now and then, but could you point me in the right direction to look into SMTP from within NAV?

    I noticed that it's possible to automatically execute a .VBS script whilst parsing the report to PDF. I had considered using a .VBS script to launch an emailer of some sort. But I'd rather keep my code IN NAV.
  • ara3nara3n Member Posts: 9,255
    What version are you on? If you are current on your maintenance/license and you are on older version, you can get CU 400 table/form 409 from 5.0 sp1 and load them into your version. You also need to register/copy Microsoft.Navision.Mail.dll, Microsoft.Navision.Mail.tlb.

    Once you have done this. Then you can use CU 400 to send email.

    The code will look like this.


    SMTPEmail.CreateMessage(SenderNameEmailAddress,SenderAddressEmailAddress,
       RecipientsEmailAddress,Subject,'Body',HtmlFormattedBolean);
      SMTPEmail.AddAttachment('C:\mydoc.PDF');
      SMTPEmail.Send();
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • gerdhuebnergerdhuebner Member Posts: 155
    This thread is really a great contribution to the knowledge of the community. But, before you code your solution there should be some general considerations allowed:
    1.) How to save Navision Reports as PDF (the original theme, remember) - this question (or How To) is easy to answer. There are many solutions on the market, many of them are free, some of them you will more like than others... - may be your customer will already have one of these solutions installed on his computers..
    2.) What do you want to do with the created PDF file? May be, you want to attach it to a mail, put it into an archive, fax it (yes, this is possible) - there should be all possibilities open.
    3.) If there is a solution for NAV, handling, creating, printing, mailing, etc. PDF files, it should be as "general" as possible? Why? If you are fixed to one PDF solution (PDFCreator, bullzip,...), your solution may work for the moment. But what about the future? Next versions may not be free anymore, there may be other problems with operating systems (Vista), e.g. - Wouldn't it be nice to have a solution for NAV working with an arbitrary PDF creator? What kind of basic functionality should this PDF creator provide? The only thing, we need is the capability to create a PDF file from a NAV report. - this file could have a fixed name (in the simplest case). Fortunately almost every "PDF creator solution" can accomplish this in the most simplest way, in form of a printer driver which is configured to print to a file (there is no automation component necessary).
    4.) The PDF solution for NAV should be as simple as possible. If you want for example attach the print result of a report to a mail as a PDF file, it should not be necessary to design the report in any way (except if you want to initialise the mailaddress, of course).

    All these considerations (and a few more) have led us to the decision to develop a "general" tool, where the mail (SMTP or MAPI) and fax issues integrate as naturally into the application as the printing process. I will soon present this tool in the product directory...
  • MonoMono Member Posts: 3
    ara3n wrote:
    What version are you on? If you are current on your maintenance/license and you are on older version, you can get CU 400 table/form 409 from 5.0 sp1 and load them into your version. You also need to register/copy Microsoft.Navision.Mail.dll, Microsoft.Navision.Mail.tlb.

    Once you have done this. Then you can use CU 400 to send email.

    The code will look like this.


    SMTPEmail.CreateMessage(SenderNameEmailAddress,SenderAddressEmailAddress,
       RecipientsEmailAddress,Subject,'Body',HtmlFormattedBolean);
      SMTPEmail.AddAttachment('C:\mydoc.PDF');
      SMTPEmail.Send();
    

    Awesome! Thanks Rashed. I'm trying to accomplish the PDF export in a 5.01 environment, with a developers license, so I think I'm good to go.

    Thanks again for your valuable input. You're really helping a NAV newbie out, here :)

    @gerdhuebner:
    I can only speak for myself here, but I think this thread was specifically created for all the people that were asking about creating a PDF from within NAV?
  • ara3nara3n Member Posts: 9,255
    I've already posted a how-to fax NAV reports. in here.


    http://mibuso.com/blogs/ara3n/2009/06/1 ... amics-nav/


    All the solution are available. I guess they just need to be put together.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • fredefrede Member Posts: 80
    Hi,

    thanx for this very informative post, Rashed!

    I've tried Bullzip with good luck - but have a problem as I need to print both A4 PDF and a local page size. I've set up the "local page size" in a extra instance of the Bullzip pdf printer - called PDF-FLG. But I cannot get NAV to find this. I've tried the below code:


    FileName := SH."No." + '.pdf';
    BullZipPDF.SetPrinterName('PDF-FLG');
    BullZipPDF.Init;
    BullZipPDF.LoadSettings;
    RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
    BullZipPDF.SetValue('Output',FileDirectory+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);
    SH2 := SH;
    SH2.SETRECFILTER;
    REPORT.RUNMODAL(ReportID,FALSE,FALSE,SH2);

    Hoping that the SETPRINTERNAME would help - but it doesn't seem to make any difference.

    Are there other ways of making this happen?
    Regards,

    Henrik Frederiksen, Denmark
  • ara3nara3n Member Posts: 9,255
    Hello frede

    Bullzip does not have a setting to set default printer. So you will need to use navision printer selection to set which report nav will use to print the report.
    IF NOT lPrinterSelection.GET('',lReportID) THEN BEGIN
      lPrinterSelection.INIT;
      lPrinterSelection."Report ID" := lReportID;
      lPrinterSelection."Printer Name" := 'Bullzip PDF Printer';   //change this to print to PDF-FLG for specific page size. 
      lPrinterSelection.INSERT;
    END;
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • fredefrede Member Posts: 80
    Sorry Rashed,
    I didn't think of this because your example code on your blog is made from a form. Of course - that's the way to do it - as a "normal" printer!
    When I print to a matrix printer it uses another font than when I make a preview of the document - or open the PDF. Do you have any ideas?
    And thank you again!
    Regards,

    Henrik Frederiksen, Denmark
  • ara3nara3n Member Posts: 9,255
    I don't know much about dot matrix printer.

    I suggest to get a new printer. :D

    It is much cheaper than messing with dot matrix printer.

    I didn't think dot matrix could print in different fonts.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • gerdhuebnergerdhuebner Member Posts: 155
    frede wrote:
    ...I didn't think of this because your example code on your blog is made from a form. Of course - that's the way to do it - as a "normal" printer!
    Yes, that's the way to do it. May be the new Tool NAVPFM 6.0 could be helpful for you and many others:
    http://www.mibuso.com/pdinfo.asp?FileID=249
  • roflrofl Member Posts: 22
    Hello,

    I gave up searching for solution myself, so this thread is my last hope.
    I have to make such thing: to make a report in excel then save it to PDF and then send it by email, but most importantly - it has to be done without any user intervention.
    First job is done: there is an excel report. Now I'm struggling with the second (email option is my last concern). I am using PDFCreator and when I try to print a file in a particular directory, PDFCreator opens default program (in this case Excel), shows that tiny print dialog window, prints the file to the appropriate directory (user doesn't have to do anything even all of the windows appear), but when it finishes printing, it closes current workbook, but blank Excel window is STILL hanging on the screen and I can't figure out how to close that damn thing. Maybe you have some kind of life-saving ideas?

    Here is the piece of code that I use:

    IF ISCLEAR(pdfCreatorApp) THEN
    CREATE(pdfCreatorApp);
    IF ISCLEAR(pdfCreatorOptions) THEN
    CREATE(pdfCreatorOptions);
    XlWrkBk.SaveCopyAs(ENVIRON('TEMP') + '\' + XlWrkBk.Name + '.xlsx');
    ExcelFileName := XlWrkBk.Name;
    XlWrkBk.Close(FALSE);
    XlApp.Quit;

    IF pdfCreatorApp.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN BEGIN
    globalErrDescriptionTxt := 'Status: Error: ' + pdfCreatorError.Description;
    ERROR(globalErrDescriptionTxt);
    END;

    pdfCreatorApp.cClearCache();
    pdfCreatorApp.cVisible := FALSE;

    DefaultPrinter := pdfCreatorApp.cDefaultPrinter;
    pdfCreatorApp.cDefaultPrinter := 'PDFCreator';

    pdfCreatorOptions := pdfCreatorApp.cOptions;
    pdfCreatorOptions.UseAutosave := 1;
    pdfCreatorOptions.UseAutosaveDirectory := 1;
    pdfCreatorOptions.AutosaveDirectory := ENVIRON('TEMP');
    pdfCreatorOptions.AutosaveFilename := ExcelFileName;
    pdfCreatorOptions.AutosaveFormat := 0;

    pdfCreatorApp.cSaveOptions := pdfCreatorOptions;

    pdfCreatorApp.cPrinterStop := FALSE;

    pdfCreatorApp.cPrintFile(ENVIRON('TEMP') + '\' + ExcelFileName + '.xlsx');

    pdfCreatorApp.cPrinterStop := TRUE;

    pdfCreatorApp.cDefaultPrinter := DefaultPrinter;

    // Everything is done except Excel window is still in front of my eyes.
    //Clearing Objects

    P.S. Could somebody explain me, what does that property CPrinterStop do...?
  • WLWL Member Posts: 12
    Hi,

    Not too sure if I have miss out any thread on why the PDF Creator hangs and is unable to execute the PDFCreator.cClose(). I am working on NAV 3.60 with PDF Creator version 0.9.6.
    I have another customer on NAV4.0SP3 with PDF Creator version 0.9.3 and that is working fine.
    Can anyone advice?
  • udaya726udaya726 Member Posts: 21
    Hey everybody I didnt get Record 2000000001 in my NAV database?
    Can you pls explain this to me
    Thanks
  • ara3nara3n Member Posts: 9,255
    2000000001 is a virtual table. It contains all the objects.

    You can create a form with table of 2000000001 and you'll see all the table.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WLWL Member Posts: 12
    Hi,

    Is there anyone that can advice me as I need to urgently revert back to my user. It only hangs when it is printing the report with a range of records. If I am to print by per record it is fine.
  • piercapierca Member Posts: 10
    Hi, I have a problem using pdfcreator automation. In a form I do something like this:

    " PDFCreatorOption := PDFCreator.cOptions; "

    where
    PDFCreator is the automation 'PDFCreator'.clsPDFCreator
    and
    PDFCreatorOption is the Automation 'PDFCreator'.clsPDFCreatorOptions.

    If I compile the Form under Vista and I use it on the same operating system it works, but if i use the same Form under XP it doesn't works and Nav gives me an error on that code line. I have to ricompile it under XP and then it works on XP but not on Vista!
    Any suggestion?
    Thanks a lot and sorry for my english...
  • ara3nara3n Member Posts: 9,255
    A workaround would be to have two Forms based on OS.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • piercapierca Member Posts: 10
    Thanks for your suggestion!
  • Bart_GrootBart_Groot Member Posts: 5
    A week ago I was trying to use PDF Creator in a batch process to create many PDF invoices. While the batch process was running I wanted to test what happens if I would print another document to PDF Creator. What I was afraid of happened. An invoice that was created in the batch process was overwritten with the document I printed to the PDF Creator. It's a matter of timing which document overwrites the other one.

    The bullzip PDF printer mentioned the other posts does not have this problem due to the local runonce file that is created when used in batch mode.
  • visheshvishesh Member Posts: 60
    Hi ara3n,

    I am trying to run the code for PDF Creator.
    I have installed the latest PDF Creatror (0_9_8). But i am getting the Error which is saying.
    Staus: Error[4] GhostScript Error: -'100'!.
    I dont know why this error is coming as I have done this before but that was under XP and now I am trying with vista.

    Can you give me some idea why this is happning.

    Waiting for ur reply.
    Vishesh Singh
    Vishesh Singh
    Technical Consultant
Sign In or Register to comment.