Hello,
I am trying to merge several pdfs together. I use the following code below. Unfortunately, doc_dst.ImportPage(ctx, srcno, dstno); always returns false and page count does not increase. What are the conditions that would cause this method to return false? Is there anything wrong with my code? I am currently using the demo project package name and calling activatePremium method in Global.init()
Any help would be appreciated. Thanks.
List<String> pdfUrls; //list of pdf file locations
String mergedPdfFilePath; //pdf file location
private void mergePdfPages(File baseEditionFolder, File editionConfigFile,
Reader reader) throws IOException, COSVisitorException {
List<String> pdfUrls = getListOfPdfPageFilePaths(baseEditionFolder, editionConfigFile, reader);
Files.copy(pdfUrls.get(0), mergedPdfFilePath); //copy 1st pdf and use copy as output pdf
for(int i = 1; i < pdfUrls.size(); i++) {
concat_pdf(mergedPdfFilePath, pdfUrls.get(i));
}
}
private void concat_pdf( String dst, String src )
{
Document doc_dst = new Document();
Document doc_src = new Document();
doc_dst.Open(dst, null);
doc_dst.SetCache(Global.tmp_path + File.separator + "rdtmp" + File.separator + "ttt.dat");
doc_src.Open(src, null);
Document.ImportContext ctx = doc_dst.ImportStart(doc_src);
int dstno = doc_dst.GetPageCount();
int srccnt = doc_src.GetPageCount();
int srcno = 0;
while( srcno < srccnt )
{
boolean success = doc_dst.ImportPage(ctx, srcno, dstno);
System.out.println("doc_dst.ImportPage(ctx, srcno, dstno): " + success);
dstno++;
srcno++;
System.out.println("doc_dst.GetPageCount(): " + doc_dst.GetPageCount());
}
ctx.Destroy();
doc_dst.Save();
doc_src.Close();
doc_dst.Close();
}