How to merge pdf files for open Invoices in one single pdf file?
Aravindh_Navision
Member Posts: 258
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
Coding..
SendMailToRegOpenInvoices(CustNo : Code[20])
Can anybody let me know where I made mistake?
Thanks in advance, Aarvi.
[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.
0
Comments
-
However, the branch is quite old, but I want to give my opinion on how to overcome such kind of issues. Ofc, the solution is quite reasonable, but instead of using a code it'd be much easier to do so with this tool https://pdfliner.com/ds_11_form it's paid, but you can have a trial period, which is of the long duration, so you'll have enough time to figure out all issues with your files-1
-
Thank you Alana. I'll check and get back to you.0
-
For basic, merging functionalities, I use the free iTextSharp library for this. Below is the entire code, pretty simple to use. Just create it as a DLL and drop it into your add-in folder. You can then reference it as a DotNet variable.
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;
}
}
}
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions