I have been using PDFCreator to create PDF documents from my NAV client.  I am also using it with NAS (Nav Application Server) on my Windows 2003 32bit server.  I needed to get this up an running on a 64bit Windows 2008 server and I ran into problems.

I could easily create the PDF documents from my client.  I saw the pdf file appear in my file system and attached it to my record.  But, when NAS was running the same job no files where created and the job failed.  I unsuccessfully tried a few tricks but nothing changed.  I decided to find another path and looked at bioPDF writer.

The result is a new single instance codeunit to handle the print of any report to a pdf file.  Lets say that the user would like to be able to print and open a sales invoice in pdf format.  Copy the function PrintRecords to PrintRecordsToPDF for table no. 112, Sales Invoice Header.  Add two lines and you are done.

[code htmlscript=”false”]WITH SalesInvHeader DO BEGIN
COPY(Rec);
FIND(‘-‘);
ReportSelection.SETRANGE(Usage,ReportSelection.Usage::"S.Invoice");
ReportSelection.SETFILTER("Report ID",'<>0’);
ReportSelection.FIND(‘-‘);
REPEAT
bioPDFMgt.BeforeReportPrint(ReportSelection."Report ID"); // Dynamics.is
REPORT.RUNMODAL(ReportSelection."Report ID",ShowRequestForm,FALSE,SalesInvHeader);
HYPERLINK(bioPDFMgt.AfterReportPrintGetFileName(ReportSelection."Report ID")); // Dynamics.is
UNTIL ReportSelection.NEXT = 0;
END;[/code]

Where bioPDFMgt is a local variable for the BioPDF Management Codeunit.

The BioPDF Management Codeunit needs to be added to global variable in Codeunit 1, ApplicationManagement.  Add to the FindPrinter function.

[code htmlscript=”false”]FindPrinter(ReportID : Integer) : Text[250]
// Dynamics.is start
IF bioPDFMgt.PrinterBufferExists(ReportID) THEN
EXIT(bioPDFMgt.GetPrinterName);
// Dynamics.is end

CLEAR(PrinterSelection);

IF NOT PrinterSelection.GET(USERID,ReportID) THEN
IF NOT PrinterSelection.GET(”,ReportID) THEN
IF NOT PrinterSelection.GET(USERID,0) THEN
IF PrinterSelection.GET(”,0) THEN;

// Dynamics.is start
bioPDFMgt.SaveLastPrinter(PrinterSelection."Printer Name");
// Dynamics.is end

EXIT(PrinterSelection."Printer Name");[/code]

The BioPDF Management Codeunit includes these functions:

Name Description
BeforeReportPrint Setup PDF printer and printer selection
AfterReportPrintGetBLOB Copy the PDF file to a tempBLOB record
AfterReportPrintGetFileName Return the PDF file name
CleanUp Clear PDF automation objects
ConfirmFileExists Return an error if file does not exist
FileExists Return a boolean value for given file name
FileRename Rename a file (copy and delete combined)
FileErase Delete a file
FileCopy Copy a file
ClearPrinterBuffer Clear the printer selection buffer
CreatePrinterBuffer Adds a report and a printer name to the printer selection buffer
PrinterBufferExists Check if a printer selection buffer exists for given report
GetPrinterName Get the printer name from the printer selection buffer
SaveLastPrinter Save the name of the last printer used
GetLastPrinter Get the name of the last printer used

BioPDF Management Codeunit (2009 R2)

BioPDF Management Codeunit (5 SP1)

17 thoughts on “bioPDF writer

  1. Arthur Zhmur says:

    hi Gunnar. Thaks for greate aricle. But i have one question: is bioPDF freeware for commercial use (PDFCreator is)?

  2. Hi Arthur.
    BioPDF is a professional and paid version of BullZip pdf writer. This code should also work with BullZip pdf writer. Please refer to Biopdf.com for more information

  3. Arthur Zhmur says:

    Hi Gunnar. Could we use this codeunit under Navision 5 SP1? I have a problem when i am trying to execute printing fuctionality (invoke PrintRecordsToPDF) in my NAV 5.0 SP1. Client crashed without any information about reason.

  4. Arthur Zhmur says:

    Also, client crashed when i am trying to push Design button on codeunit 50105.

    1. Did you try to import the text version of the codeunit?

      1. Arthur Zhmur says:

        Main problem is that there is no CU 419 in Navision 5 SP1.

        1. Hi,
          Try this attached text file and let me know if this works for 5 SP1.

          http://www.dynamics.is/wp-content/uploads/2012/06/Codeunit50105_5Sp1.zip

          1. Arthur Zhmur says:

            Hi, i have the following compilation error with new CU: https://dl.dropbox.com/u/5753358/compile_error_50105.png .

  5. Arthur Zhmur says:

    OK. I checked this CodeUnit under Navision 2009 R2 everything works fine.

    1. If this is of value to you, please check my Copyright page.

  6. I am at home for today and I made a compiled version for 5 SP1 and added it to the original post.
    http://www.dynamics.is/wp-content/uploads/2012/06/bioPDFMgt_5Sp1.zip

  7. Jason Chance says:

    Gunnar, did you get bioPDF up and running with the NAV JobQueue? In NAV 2009 R2, I have tried and have a test codeunit that I can run that generates a PDF using the bioPDF COM interface, but when I run that same codeunit in the job queue, there are no errors, but no file is generated. Do you have a code sample that ran successfully in the job queue?

    1. Here is an example that I use to create PDF attachments for all posted sales invoices and -credit memos.

      https://skydrive.live.com/redir?resid=D027A7DF9B341B76!1099

  8. Elwin says:

    This trick is working great in the classic client. In my opinion it is not working in the RTC.
    A singleinstance is working in the RTC but not when it is used through codeunit 1.
    Maybe I’m doing something wrong. I’m not getting it to work.

    1. Hi Elwin,

      You should just use SAVEASPDF in the RTC client and in newer versions of NAV.

      1. Elwin says:

        Hi Gunnar,

        This is not the solution for me because I use PDF background.

        I have just found what is the problem.
        Because we have not created RDLC-layouts for our custom reports the classic client is started from the RTC. This is another client so the SingleInstance does not work.

        Thanks for your quick respons.

        1. Of cource Elwin. Good call.

Leave a Reply

%d bloggers like this: