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

TOPIC:

How to merge two documents? 10 years 2 months ago #5165

  • douglasmedia
  • douglasmedia's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 7
  • Thank you received: 0
Hello,

I want to merge two documents into one single document. Therefore I've developed this method:
    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.
	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!

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

How to merge two documents? 10 years 2 months ago #5172

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
plz check doc1 has invoked doc1.SetCacheData(...);
and you have actived premium license.
then do like this:
    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;
    }

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

Last edit: by .

How to merge two documents? 10 years 2 months ago #5317

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

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

How to merge two documents? 10 years 2 months ago #5325

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
The code should work, make sure that the demo project is activated with the premium license..
try to check with PDFTestAct.concate_pdf

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

How to merge two documents? 10 years 2 months ago #5365

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

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

How to merge two documents? 10 years 2 months ago #5380

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
you'd better managed 2 Document as 1 document by wrapping a new Document class.

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum