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 |