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

How to merge two documents?

More
IP: 192.168.0.70 11 years 11 months ago #5165 by douglasmedia
Hello,

I want to merge two documents into one single document. Therefore I've developed this method:
Code:
public static boolean mergeDocuments(Document doc1, Document doc2) { Document.ImportContext importContext = doc1.ImportStart(doc2); if (importContext != null) { doc1.ImportPage(importContext, 1, 2); importContext.Destroy(); return true; } return false; }

Unfortunally, the method returns always false, because importContext is null. I have debugged the project and go into the method "ImportStart()". The variable "hand" is 0.
Code:
public ImportContext ImportStart( Document src ) { if( src == null ) return null; int hand = importStart( hand_val, src.hand_val ); if( hand != 0 ) return new ImportContext(this, hand); else return null; }

Seems like it is a bug in the library. Can anybody help me?

Thank you!
More
IP: 192.168.0.70 11 years 11 months ago - 11 years 11 months ago #5172 by radaee
Replied by radaee on topic How to merge two documents?
plz check doc1 has invoked doc1.SetCacheData(...);
and you have actived premium license.
then do like this:
Code:
public static boolean mergeDocuments(Document doc1, Document doc2) { Document.ImportContext importContext = doc1.ImportStart(doc2); int pageno = doc1.GetPageCount(); int cnt = doc2.GetPageCount(); if (importContext != null) { for( int cur = 0; cur < cnt; cur++ ) { doc1.ImportPage(importContext, cur, pageno); pageno++; } importContext.Destroy(); doc1.Save(); return true; } return false; }
Last edit: 11 years 11 months ago by .
More
IP: 192.168.0.70 11 years 11 months ago #5317 by douglasmedia
Thank you for your help. I've tried it with your recommended solution, but importContext is still null. Should it work with the trial licence?

I am using the method like this:
Code:
private PDFReader initReader(String path1, String path2) { mReader = new PDFReader(parent, null); mDoc1 = new Document(); int ret1 = mDoc1.Open(path1, null); if (!TextUtils.isEmpty(path2)) { mDoc2 = new Document(); mDoc2.Open(path2, null); PDFHelper.mergeDocuments(mDoc1, mDoc2); } // if (ret1 == 0) { mReader.PDFOpen(mDoc1, false, null); return mReader; } return null; } }

Best regards,

Robin
More
IP: 192.168.0.158 11 years 11 months ago #5325 by nermeen
Replied by nermeen on topic How to merge two documents?
The code should work, make sure that the demo project is activated with the premium license..
try to check with PDFTestAct.concate_pdf
More
IP: 192.168.0.70 11 years 11 months ago #5365 by douglasmedia
Thank you! It works! The package for the demo project was wrong...

But how can I merge the documents without saving the result? I just want to merge document 2 in document 1 and display the result, without saving the result on the disc. Is that possible?

Beste regards.
More
IP: 192.168.0.70 11 years 11 months ago #5380 by radaee
Replied by radaee on topic How to merge two documents?
you'd better managed 2 Document as 1 document by wrapping a new Document class.
Time to create page: 0.542 seconds
Powered by Kunena Forum