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)
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;
Comments
using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace iTextPDF
{
public static class PDFtools
{
public static bool MergePDFs(string file1, string file2, string targetPdf)
{
using (FileStream stream = new FileStream(targetPdf, FileMode.Create))
{
using (Document document = new Document())
{
PdfCopy pdf = new PdfCopy(document, stream);
try
{
document.Open();
using (PdfReader reader = new PdfReader(file1))
{
pdf.AddDocument(reader);
reader.Close();
}
using (PdfReader reader = new PdfReader(file2))
{
pdf.AddDocument(reader);
reader.Close();
}
}
catch (Exception ex)
{
Errs.WriteEventLog(ex.Message);
return false;
}
finally
{
if (document != null)
{
document.Close();
}
}
}
}
return true;
}
}
}