Using - Aspose.PDF Version 7.4
I am appending same PDFs to a PDF. I am unable to generate the resultant PDF with more than 4 pages.
Is this a limitataion in Evaluation version.
For example
1. when to a PDF with 2 pages
i append a PDF with 2 pages and another with 1 page, the resultant is a PDF with 4 pages and not 5.
2. and when to a PDF with 1 page
i append a PDF with 2 pages and another with 1 page, the resultant is a PDF with 4 page which is correct.
Her’s my code -
private static void One() //for case 1
{
String inFile = @“C:\Users\vibhor.agarwal\Desktop\Test\if1.pdf”;
String portFile1 = @“C:\Users\vibhor.agarwal\Desktop\Test\pf1.pdf”;
String portFile2 = @“C:\Users\vibhor.agarwal\Desktop\Test\pf2.pdf”;
String outFile = @“C:\Users\vibhor.agarwal\Desktop\Test\out1.pdf”;
//FileStream fs1 = new FileStream(inFile, FileMode.Create, FileAccess.ReadWrite);
FileStream fs1 = new FileStream(inFile, FileMode.Open, FileAccess.Read);
FileStream fs2 = new FileStream(portFile1, FileMode.Open, FileAccess.Read);
FileStream fs3 = new FileStream(portFile2, FileMode.Open, FileAccess.Read);
FileStream fs4 = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite);
int pc = GetPdfPageCount(fs1);
int ia = GetPageCount(portFile1);
int ib = GetPageCount(portFile2);
PdfFileEditor ed = new PdfFileEditor();
ed.Insert(fs1, pc, fs2, Enumerable.Range(1, ia).ToArray(), fs4);
fs1.Dispose();
fs2.Close(); fs2.Dispose();
ed.Insert(fs4, pc + ia, fs3, Enumerable.Range(1, ib).ToArray(), fs4);
fs3.Close(); fs3.Dispose();
fs4.Close(); fs4.Dispose();
}
private static void Two() //for case 2
{
String inFile = @“C:\Users\vibhor.agarwal\Desktop\Test\if2.pdf”;
String portFile1 = @“C:\Users\vibhor.agarwal\Desktop\Test\pf1.pdf”;
String portFile2 = @“C:\Users\vibhor.agarwal\Desktop\Test\pf2.pdf”;
String outFile = @“C:\Users\vibhor.agarwal\Desktop\Test\out2.pdf”;
FileStream fs1 = new FileStream(inFile, FileMode.Open, FileAccess.Read);
FileStream fs2 = new FileStream(portFile1, FileMode.Open, FileAccess.Read);
FileStream fs3 = new FileStream(portFile2, FileMode.Open, FileAccess.Read);
FileStream fs4 = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite);
int pc = GetPdfPageCount(fs1);
int ia = GetPageCount(portFile1);
int ib = GetPageCount(portFile2);
PdfFileEditor ed = new PdfFileEditor();
ed.Insert(fs1, pc, fs2, Enumerable.Range(1, ia).ToArray(), fs4);
fs1.Dispose();
fs2.Close(); fs2.Dispose();
ed.Insert(fs4, pc + ia, fs3, Enumerable.Range(1, ib).ToArray(), fs4);
fs3.Close(); fs3.Dispose();
fs4.Close(); fs4.Dispose();
}
private static int GetPageCount(string fileName)
{
Document d = new Document(fileName);
return d.Pages.Count;
}
I am attaching the files used & generated:-
if1.pdf - InFile for Case 1
if2.pdf - InFile for Case 2
pf1.pdf - File inserted I
pf2.pdf - File inserted II
out1.pdf - OutFile for Case 1
out2.pdf - OutFile for Case 2
out1.pdf contains both pf1.pdf and pf2.pdf
out2.pdf contains pf1.pdf but not pf2.pdf