- Posts: 15
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
ImportPage returning false
- rockycamacho
- Topic Author
- Offline
- New Member
-
Less
More
IP: 192.168.0.71
11 years 3 months ago #7350
by rockycamacho
ImportPage returning false was created by rockycamacho
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.
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.
Code:
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();
}
IP: 192.168.0.156
11 years 3 months ago #7354
by Davide
Replied by Davide on topic ImportPage returning false
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.
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.
- rockycamacho
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 15
- Thank you received: 0
IP: 192.168.0.71
11 years 3 months ago - 11 years 3 months ago #7355
by rockycamacho
Replied by rockycamacho on topic ImportPage returning false
Is it possible to test importPage using the demo account?
Last edit: 11 years 3 months ago by Ovchinnikov.
IP: 192.168.0.156
11 years 3 months ago #7356
by Davide
Replied by Davide on topic ImportPage returning false
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 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.
- rockycamacho
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 15
- Thank you received: 0
IP: 192.168.0.71
11 years 3 months ago #7358
by rockycamacho
Replied by rockycamacho on topic ImportPage returning false
my activatePremium call returns true.
I use the premium account details in Global.java
I also have the package name com.radaee.reader
I use the premium account details in Global.java
I also have the package name com.radaee.reader
- rockycamacho
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 15
- Thank you received: 0
IP: 192.168.0.71
11 years 3 months ago #7361
by rockycamacho
Replied by rockycamacho on topic ImportPage returning false
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 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
Time to create page: 0.400 seconds