Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

ImportPage returning false 9 years 6 months ago #7350

  • rockycamacho
  • rockycamacho's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 15
  • Thank you received: 0
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();
}

Please Log in or Create an account to join the conversation.

ImportPage returning false 9 years 6 months ago #7354

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
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.

Please Log in or Create an account to join the conversation.

ImportPage returning false 9 years 6 months ago #7355

  • rockycamacho
  • rockycamacho's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 15
  • Thank you received: 0
Is it possible to test importPage using the demo account?

Please Log in or Create an account to join the conversation.

Last edit: by Ovchinnikov.

ImportPage returning false 9 years 6 months ago #7356

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
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.

Please Log in or Create an account to join the conversation.

ImportPage returning false 9 years 6 months ago #7358

  • rockycamacho
  • rockycamacho's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 15
  • Thank you received: 0
my activatePremium call returns true.

I use the premium account details in Global.java
I also have the package name com.radaee.reader

Please Log in or Create an account to join the conversation.

ImportPage returning false 9 years 6 months ago #7361

  • rockycamacho
  • rockycamacho's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 15
  • Thank you received: 0
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

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum