You are viewing limited content. For full access, please sign in.

Question

Question

Merge pages from two or more documents into a new document using C# SDK

SDK
asked on May 15, 2018 Show version history

I'm using C# SDK
using Laserfiche.DocumentServices;
using Laserfiche.RepositoryAccess;

I have two or more documents that I need to merge.

1. I started create a new document with: copyto 

    mEntry.CopyTo("\\TESTCOPY\\mytest", EntryNameOption.AutoRename);

2. I opened the second document and need to append these pages to the new document

    DI.CopyPagesTo(DI.AllPages,"\\TESTCOPY\\mytest",mLastpage);

 

I couldn't find a merge function...

Anyone already have code to do this?  It seems like I'm doing this "the long way"

Thanks.

0 0

Answer

SELECTED ANSWER
replied on May 15, 2018

One way to improve this is to create the destination document yourself with DocumentInfo.Create(), lock it with Lock(), and pass in the DocumentInfo to CopyPagesTo. This way the document lock is only released once at the end of the operation when you call Unlock(). Sample:

using (DocumentInfo target = new DocumentInfo(session))
{
    target.Create(Folder.GetFolderInfo(@"\TESTCOPY", session), "mytest", session);
    target.Lock(LockType.Exclusive);
    sourceDoc1.CopyPagesTo(sourceDoc1.AllPages, target, target.PageCount + 1);
    sourceDoc2.CopyPagesTo(sourceDoc2.AllPages, target, target.PageCount + 1);
    target.Unlock();
}

 

2 0
replied on May 15, 2018

As a follow up to this, if you're not keeping the source document(s) after the pages have been "merged" I would go with MovePagesTo instead of CopyPagesTo because it has slightly less overhead based on my observations/testing.

CopyPagesTo will copy the image files and add the new images to the document, but MovePagesTo will change the reference for the existing images so there seemed to be less read/write activity on the volume/drive.

I have a versioning script in Workflow that does this and the per document difference is minimal, but it adds up when you are processing a lot of documents.

1 0
replied on May 15, 2018

Great to know!   Thanks Jason!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.