RadaeePDF.com :: Topic: How to merge two documents? (1/2)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

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

TOPIC: How to merge two documents?

How to merge two documents? 3 years 7 months ago #5165

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!
The administrator has disabled public write access.

How to merge two documents? 3 years 7 months ago #5172

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
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;
    }
Last Edit: 3 years 7 months ago by .
The administrator has disabled public write access.

How to merge two documents? 3 years 7 months ago #5317

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

How to merge two documents? 3 years 7 months ago #5325

  • nermeen
  • nermeen's Avatar
  • OFFLINE
  • Moderator
  • Posts: 684
  • Thank you received: 40
  • Karma: 18
The code should work, make sure that the demo project is activated with the premium license..
try to check with PDFTestAct.concate_pdf
The administrator has disabled public write access.

How to merge two documents? 3 years 7 months ago #5365

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

How to merge two documents? 3 years 7 months ago #5380

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
you'd better managed 2 Document as 1 document by wrapping a new Document class.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Powered by Kunena Forum