How to merge pdf files for open Invoices in one single pdf file?

Hi Friends,

[Version: NAV 2009]

I have an another issue where I got struct. I need to merge the Open Invoices in one single pdf file. Below were the code I have done.

Function: SendMailToRegOpenInvoices
Locals:
Parameter
CustNo (Code20)

Variables:
Customer (Record) -	Customer	
File1	(Automation) -	'Microsoft Scripting Runtime'.FileSystemObject	
Filename1- (Text200)
RunOnceFile - (Text250)
TimeOut - (Integer)
SalesInv (Report) - Sales Invoice report
SalesInvoice - (Record) - Sales Invoice Header	
PrinterSelection - (Record) - Printer Selection	
CustLedgEntry - (Record) - Cust. Ledger Entry	
InvoiceNo - (Code20)
mergeAfterFilename - (Text200)

Coding..

SendMailToRegOpenInvoices(CustNo : Code[20])
SMTPSetup.GET;
Customer.GET(CustNo);
CustLedgEntry.SETCURRENTKEY("Customer No.",Open,Positive,"Due Date","Currency Code");
CustLedgEntry.SETRANGE(CustLedgEntry."Customer No.",CustNo);
CustLedgEntry.SETRANGE(Open,TRUE);
CustLedgEntry.SETRANGE(CustLedgEntry."Document Type",CustLedgEntry."Document Type"::Invoice);

IF CustLedgEntry.FINDFIRST THEN BEGIN
  REPEAT
    InvoiceNo := CustLedgEntry."Document No.";

    SalesInvoice.SETFILTER(SalesInvoice."No.",InvoiceNo);
    IF SalesInvoice.FINDFIRST THEN BEGIN

      IF ISCLEAR(File1) THEN
        CREATE(File1);

      IF ISCLEAR(BullZipPDF) THEN
      CREATE(BullZipPDF);

      IF NOT File1.FolderExists(SMTPSetup."Path to Save Inv. Report") THEN
        File1.CreateFolder(SMTPSetup."Path to Save Inv. Report");

      Filename1:= SMTPSetup."Path to Save Inv. Report" +'SalesInvoice' + '.pdf';
      mergeAfterFilename := SMTPSetup."Path to Save Inv. Report" +'SalesInvoiceA' + '.pdf';

      IF NOT PrinterSelection.GET('',50003) THEN BEGIN
        PrinterSelection.INIT;
        PrinterSelection."Report ID" := 50003;
        PrinterSelection."Printer Name" := 'Bullzip PDF Printer';
        PrinterSelection.INSERT;
      END;

      BullZipPDF.Init;
      BullZipPDF.LoadSettings;
      RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
      BullZipPDF.SetValue('Output',Filename1);
      BullZipPDF.SetValue('OwnerPassword','abc');
      BullZipPDF.SetValue('UserPassword', CustNo);
      BullZipPDF.SetValue('EncryptionType', 'Standard128bit');
      BullZipPDF.SetValue('ShowSaveAs', 'never');
      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.SetValue('Mergefile', Filename1 + '|.|' + mergeAfterFileName);
      BullZipPDF.SetValue('MergePosition', 'below');
      
      BullZipPDF.WriteSettings(TRUE);

      SalesInv.SETTABLEVIEW(SalesInvoice);
      SalesInv.USEREQUESTFORM(FALSE);
      SalesInv.RUNMODAL;

      TimeOut := 0;
      WHILE (TimeOut < 20) DO BEGIN
        SLEEP(3000);
        TimeOut += 1;
      END;

      CLEAR(File1);
      CLEAR(BullZipPDF);
    END;
  UNTIL CustLedgEntry.NEXT = 0;
END;

Can anybody let me know where I made mistake?

Thanks in advance, Aarvi.
Sign In or Register to comment.