RadaeePDF.com :: Topic: ImportPage returning false (1/2)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC: ImportPage returning false

ImportPage returning false 3 years 1 month ago #7350

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();
}
The administrator has disabled public write access.

ImportPage returning false 3 years 1 month ago #7354

  • Davide
  • Davide's Avatar
  • OFFLINE
  • Moderator
  • Posts: 699
  • Thank you received: 53
  • Karma: 15
Hi,
to use activatePremium you have to buy a Premium license. (www.androidpdf.mobi/shop)
The Premium License will activate the ImportPage and other voids.

Then you have to call activatePremium in the Init(Activity act) void in Global class and, after that, doc_dst.ImportPage(ctx, srcno, dstno); will work properly.

When you use ImportPage do not forget to invoke ImportContext.Destroy() after all pages are imported.
The administrator has disabled public write access.

ImportPage returning false 3 years 1 month ago #7355

Is it possible to test importPage using the demo account?
Last Edit: 3 years 1 month ago by Ovchinnikov.
The administrator has disabled public write access.

ImportPage returning false 3 years 1 month ago #7356

  • Davide
  • Davide's Avatar
  • OFFLINE
  • Moderator
  • Posts: 699
  • Thank you received: 53
  • Karma: 15
Hi,

please first check if your activePremium void return true.

Then you can check in PDFTestAct the concat_pdf void as example of merging two PDF documents.

And looking at your code, you have to check the pageCount after you have saved the pdf.
The administrator has disabled public write access.

ImportPage returning false 3 years 1 month ago #7358

my activatePremium call returns true.

I use the premium account details in Global.java
I also have the package name com.radaee.reader
The administrator has disabled public write access.

ImportPage returning false 3 years 1 month ago #7361

I tested the PdfTestAct and it seems to work there.
The problem must be in my code. I will investigate further. I will let you know the cause of my error as soon as I find it.
Thanks Davide
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Powered by Kunena Forum