How to save Navision Reports as PDF

14567810»

Comments

  • G8torG8tor Member Posts: 29
    Thanks for the reply.

    But is it possible to use the GhostScript .dll to handle the pdf printing? Or do I always have to rely on printers like PDFCreator that have some versions that are not stable?
    Im running PDFCreator on Windows server 2008 and it has not been working.
  • ara3nara3n Member Posts: 9,256
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • MauddibMauddib Member Posts: 269
    Back from Antwerp and all hangovers recovered from. Annoying PDF Bullzip problem here and I can not seem to find it on Search. Perhaps the brain cells required to do so were killed on Thursday night.

    I have a reporting codeunit running which a couple of Nav Clients are running at the same times on the same server. When a report is running it uses the code:
      PrinterSelection.RESET;
      IF NOT PrinterSelection.GET(USERID, SetupValuesCAL."Object No.") THEN BEGIN
        deletePrinterSelection := TRUE;
        CLEAR(PrinterSelection);
        PrinterSelection."User ID" := USERID;
        PrinterSelection."Report ID" := SetupValuesCAL."Object No.";
        PrinterSelection."Printer Name" := 'Bullzip PDF Printer';
        PrinterSelection.INSERT;
      END ELSE BEGIN
        resetPrinterSelection := TRUE;
        PrinterSelectionBackup := PrinterSelection;
        PrinterSelection."Printer Name" := 'Bullzip PDF Printer';
        PrinterSelection.MODIFY;
      END;
    

    The Object No. of the report I want to auto run coming from a Setup Table.

    I then init the Bullzip settings I require:

    IF ISCLEAR(BullZipPDF) THEN
        CREATE(BullZipPDF);
      BullZipPDF.Init;
        BullZipPDF.LoadSettings;
    
      RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
      BullZipPDF.SetValue('Output', FilePathName);
      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);
    

    Then I RUNMODAL the report and out it usually prints, quite often to c:\temp where it is attached to an email and sent to the relevant users. The Filename usually includes COMPANYNAME and USERID and a TimeStampe so there is 0% chance in my company of two files being created with the same file name.

    I then do a little sleepy time as suggested somewhere else on the forum when I first set this up (Cant remember where now, probably this thread):
    WHILE EXISTS(RunOnceFile) AND (TimeOut < 10) DO BEGIN
        SLEEP(1000);
        TimeOut := TimeOut + 1;
      END;
    

    All of this works fine 95% of the time but I have seen two behaviours I can not explain and can rarely reproduce, if at all.

    1) On very rare occasions the Filename assigned to a PDF is from one client but the actual PDF itself is from another. Can never reproduce this on purpose however
    2) On other occasions, reproducible but only sporadically, the Bullzip window which asks you where you want to save the PDF opens. Normally the code above sets this not to appear and sets the file path and name etc. This of course means the PDF is not created until a user manually intervenes and so the auto matic PDF creation and Email sending has failed.

    Are these known issues I can not find in the search? Has anyone found solutions for them?
  • mdPartnerNLmdPartnerNL Member Posts: 802
    My first guess (without using bullzip) is add a sleep(1000) after "BullZipPDF.WriteSettings(TRUE); "
    So give it time write.
  • MauddibMauddib Member Posts: 269
    I think the issue is stemming from the fact many user accounts are all running Bullzip at the same time(s).

    Problem is I can not imagine how.

    The Runonce file is created in the local users account. Documents/username/etc.etc.etc.

    So 10 users logged into one server all printing with bullzip RunOnceFiles should not really be clashing with each other?

    I have put SLEEPS and TIMEOUTS at every place I can think of. Short ones, long ones, many ones, few ones. No combination appears to be working.

    I even tried to remove the "AND (TimeOut < 10)" entirely but when the problems happen the client just hangs forever then.

    I am wondering if at this stage it is worth abandoning Bullzip entirely and redeveloping with a new solution. Anyone implemented anything else before?
  • nvermanverma Member Posts: 396
    i answered my own question...i used this command to install PDFCreator.
    PDFCreator-1_0_0_setup.exe /SILENT /components=\"!toolbar\" /tasks=\"!desktop_icon\" /f /norestart
    

    Thanks to page2pagepro
  • CalicoCalico Member Posts: 31
    G8tor wrote:
    Thanks for the reply.

    But is it possible to use the GhostScript .dll to handle the pdf printing? Or do I always have to rely on printers like PDFCreator that have some versions that are not stable?
    Im running PDFCreator on Windows server 2008 and it has not been working.

    I use Ghostscript but not the automation objects. Briefly -

    1. Download Ghostscript and install
    2. Install some vanilla printer driver (I use an HP laserjet 4200/4300 PCL6)
    3. Download and install Redmon redirection program which will create port RPT1
    4. Change the printer port to RPT1 and direct to Ghostscript using the arguments -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="C:\your path name\%d.pdf" -dBATCH -f -
    5. Add the printer to NAV and select it in the code that runs the report.
    6. The argument %d.pdf will create the report output with the report caption from NAV so after running the report you probably want to add code to rename the file to the customer number or whatever.

    I do actually have a problem which is why I was looking through Mibuso and found this thread. I have one instance where I want to copy the pdf to a different folder with a different name. But for some reason, although the initial pdf is created OK, the COPY gives an error in NAV and creates an empty file in the target folder - anyone got any idea why this might be so?
  • davmac1davmac1 Member Posts: 1,283
    If you are performing any action on the file after the report has completed, you need to add a sleep command to give the operating system enough time to recognize the file has been created in that directory.
    An OS guru could go into more detail of what is going on behind the scenes. I have found a delay of a few seconds guarantees success.
  • CalicoCalico Member Posts: 31
    davmac1 wrote:
    If you are performing any action on the file after the report has completed, you need to add a sleep command to give the operating system enough time to recognize the file has been created in that directory.
    An OS guru could go into more detail of what is going on behind the scenes. I have found a delay of a few seconds guarantees success.

    Tried that - even with a delay of 30 seconds I get the same result.
  • davmac1davmac1 Member Posts: 1,283
    Can you post the specific error message?
    Things I would look at, depending on the error message:
    1) The code sets the paramters, executes the NAV report, then does the copy
    2) filename including extension is correct in the code
    3) directory pathname is valid and no syntax problems
    4) the process performing the operations has the permissions to write to the directory.
  • ara3nara3n Member Posts: 9,256
    I usually add code to change the timestamp on the file. the NAV function returns a true if sucessful. If the file is still locked it will return a false.

    Add a repeat clause.

    While not SETSTAMP(Name,date,time) do

    end;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • CalicoCalico Member Posts: 31
    davmac1 wrote:
    Can you post the specific error message?
    Things I would look at, depending on the error message:
    1) The code sets the paramters, executes the NAV report, then does the copy
    2) filename including extension is correct in the code
    3) directory pathname is valid and no syntax problems
    4) the process performing the operations has the permissions to write to the directory.

    I was a bit hasty in dismissing the sleep option: I have all the FILE operations in loops and the max number of iterations and the SLEEP time in each iteration are read from a setup record. When I increase both these values massively the COPY works OK but the whole operation is taking nearly 2 minutes.

    The error message I get if I do not trap it is

    You cannot use the file C:\PDFInvoices\Temp\User Folder\Customer Sales Invoice.pdf because it is already in use.

    I shall try Rashed (ara3n) suggestion of using the timestamp to test if the file has been unlocked because currently I am only testing to see if it exists before trying to copy
  • davmac1davmac1 Member Posts: 1,283
    That is a problem with the sleep operation if you have a large number of pdfs. I have found it works okay for my users.
    Please let us know how Rashed's method works out for you - it sounds like a much faster option, and better than trial and error with the sleep method.
  • NaVChBNaVChB Member Posts: 3
    personally , I use Nitro PDF..
    and when I want print the report, I choose the virtual printer NITRO
    That 's the Link :
    http://en.softonic.com/s/free-nitro-pdf-printer
  • CalicoCalico Member Posts: 31
    Have finally got round to trying Rashed's SETSTAMP suggestion and it works great. I previously was using file.COPY in a loop after testing that the pdf had been created and I wonder if that were somehow locking the file, because putting SETSTAMP in a loop with just the same sleep parameters (I use two, user configurable, one for the number of loops, and another for the delay time in each loop) I get no errors.

    Thanks for your help Rashed.

    I used to use PDF Creator and occasionally had the same problem as Mauddib with a payroll application - the file would have one employee's number as the filename but another employees payslip in it. At least the create - rename route puts a lot more of the control in NAV rather than relying on the pdf printer.
  • casanovacasanova Member Posts: 194
    Can it be used in Dynamics Nav 2013 ?
    i tried add variable in 2013, failed
  • davmac1davmac1 Member Posts: 1,283
    you have saveaspdf option in NAV2013
  • casanovacasanova Member Posts: 194
    davmac1 wrote:
    you have saveaspdf option in NAV2013

    i follow help file
    create variable name Reminder
    type report
    subtype Report 117 (Reminder)

    i create code unit
    on run ()
    Reminder.SAVEASPDF('D:\test.pdf');
    

    nothing happened
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Does your report has RDLC data?

    Are you using client-server environment or single machine?
    if clinet-server then the file will be created on system where servicetier is installed..
  • casanovacasanova Member Posts: 194
    Does your report has RDLC data?

    Are you using client-server environment or single machine?
    if clinet-server then the file will be created on system where servicetier is installed..


    my pc is as client
    the service is in the server
    do i need to generate from server?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    File must have generated in server pc's D folder, please check..
  • CalicoCalico Member Posts: 31
    As far as I am aware SAVEASPDF will only work with RTC and does nothing in the Classic client.
  • RachelSoonRachelSoon Member Posts: 202
    hi there,
    when we print the report to pdf from Navision, is there anyway we can set the property(non-editing)/security setting of the pdf file to prevent user to edit the pdf file?

    Thank you.

    regards,
    Rachel
  • abidabid Member Posts: 3
    =D>
    Abid Hussain / Mobile : 0561206303 / Dubai/ UAE
  • airamairam Member Posts: 91
    hi, I have successfully implemented the above, thanks for the solution.

    I have implemented on NAV2009 using pdfcreator.

    The client would like to have the pdfcreator installed only on the server and the files would be saved directly on the server too. is this possible without the NAS? I tried to select the printer as the 'Printer Selection' but it seems that only locally saved printers can be added..

    Any help would be appreciated.

    Thanks!!
  • ara3nara3n Member Posts: 9,256
    if you are running classic client, the pdf printer needs to be installed on client
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • airamairam Member Posts: 91
    yes they're using the Classic Client .. so it has to be installed on each and every client, thanks a lot!!
  • Supremenerd88Supremenerd88 Member Posts: 21
    sorry guys, i've a problem. I'm trying to print a classic report from NAV 2009 R2 to PDF. I readed previous posts, but i don't understand where is my mistake:
    CompInfo.GET;
    GeneralLedgerSetup.GET;
    GeneralLedgerSetup.TESTFIELD("Accounting Books Path");
    IF ISCLEAR(PDFCreator) THEN
      CREATE(PDFCreator,TRUE,TRUE);
    
    IF ISCLEAR(PDFCreatorError) THEN
      CREATE(PDFCreatorError,TRUE,TRUE);
    
    PDFCreatorError := PDFCreator.cError;
    
    IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN
      ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description);
    
    PDFCreatorOption := PDFCreator.cOptions;
    PDFCreatorOption.AutosaveDirectory := gVATReportSetup."VAT Path Destination";
    PDFCreatorOption.AutosaveFilename := gFileName;
    PDFCreatorOption.UseAutosave := 1;
    PDFCreatorOption.UseAutosaveDirectory := 1;
    PDFCreatorOption.AutosaveFormat := 0;
    PDFCreator.cOptions := PDFCreatorOption;
    PDFCreator.cSaveOptions();
    PDFCreator.cClearCache();
    DefaultPrinter := PDFCreator.cDefaultPrinter;
    PDFCreator.cDefaultPrinter := 'PDFCreator';
    PDFCreator.cPrinterStop := FALSE;
    
    IF pComp THEN BEGIN
      REPORT.RUNMODAL(50134, FALSE, TRUE);
    END ELSE BEGIN
      REPORT.RUNMODAL(50196, FALSE, TRUE);
    END;
    
    PDFCreator.cDefaultPrinter := DefaultPrinter;
    PDFCreator.cClose;
    CLEAR(PDFCreatorOption);
    CLEAR(PDFCreator);
    CLEAR(PDFCreatorError);
    

    i call this function many time (15/30 times) by loop (i loop on standard 12147 italian table).

    this path (PDFCreatorOption.AutosaveDirectory := gVATReportSetup."VAT Path Destination") is network address whit everyone all permission and if i try to use PDF creator whit same configuration manually, it work perfectly.

    Please, can anyone help me?
    Giorgio Gandolfi
  • garakgarak Member Posts: 3,263
    To Set a Printer, f.e. Bullzip, as Defaultprinter u can use dhe rundll32
    
    IF ISCLEAR(WSHShell) THEN
      CREATE(WSHShell);
    
    WSHShell.Exec('rundll32 printui.dll,PrintUIEntry /y /n "Bullzip PDF Printer"');
    
    Do you make it right, it works too!
Sign In or Register to comment.