Combine files too slow

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Combine files too slow

Post by HomerWu »

Hello,

I use 'op.combineDocs'https://sdkhelp.pdf-xchange.com/vi ... ombineDocs to combine 300+ pdf files,each file has 2 pages.but this operation cost me over 5 minites! Do you have any suggestions to solve my issue?
BTW,i also find the operation 'op.document.insertPages' can add pages to a existed Doc,but i have never use it,i wonder which operation is faster for me to combine multi files.
below is my code to combine files:

Code: Select all

 public object CombineDocuments(List<string> documentList)
        {
            try
            {
                PDFXEdit.PXV_Inst Inst = pdfCtl.Inst;
                int nID = Inst.Str2ID("op.combineDocs", false);
                PDFXEdit.IOperation Op = Inst.CreateOp(nID);
                PDFXEdit.ICabNode input = Op.Params.Root["Input"];
                List<IPXC_Document> docList = new List<IPXC_Document>();
                object tempDoc = null;
                foreach (string file in documentList)
                {
                    tempDoc = this.ConvertPDFToDoc(file);
                    if (tempDoc != null)
                    {
                        docList.Add((IPXC_Document)tempDoc);
                    }
                }
                foreach (PDFXEdit.IPXC_Document doc in docList)
                {
                    if (doc != null)
                    {
                        PDFXEdit.IOpInputItem inpItem1 = Op.CreateInputItem(doc);
                        inpItem1.Params.Root["PagesRange.Type"].v = "All";
                        input.Add().v = inpItem1;
                        PDFXEdit.ICabNode options = Op.Params.Root["Options"];
                        options["BookmarksAction"].v = 0;
                        options["AddRootBookmarks"].v = false;
                        options["FieldsAction"].v = 0;
                        Op.Do();
                    }
                }
                PDFXEdit.IPXC_Document resDoc = (PDFXEdit.IPXC_Document)Op.Params.Root["Output"].v;
                foreach (PDFXEdit.IPXC_Document doc in docList)
                {
                    if (doc != null)
                    {
                        doc.Close();
                    }
                }
                return resDoc;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Combine files too slow

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

Have you tried combining those files in the End-User Editor? If so, how much time does it take?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: Combine files too slow

Post by HomerWu »

Dear Sasha,

Thank you for your prompt reply!
I don't have an End-User Editor,and i ran your fulldemo just now,then choose Operations tab,then choose 'Cmbine Documents',and added all those 300+ files……I found the demo use just 4 seconds to combine those files! :D
Why your demo so fast?can you give me the method to combine multi files fastly?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Combine files too slow

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

Are you trying the release build? Also, what are you doing inside of the ConvertPDFToDoc method? The combine document operation can use an array of IAFS_Name interfaces - no need to open each document manually.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Combine files too slow

Post by Sasha - Tracker Dev Team »

I've looked through your code again - why are you launching the combine operation for each separate document? You should add all of the files to the input and then launch the combine operation once.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: Combine files too slow

Post by HomerWu »

Dear Sasha,

Thanks for your help!The operation is very fast now! :lol:
The old code is just from your sample code https://sdkhelp.pdf-xchange.com/vi ... ombineDocs,and i saw the parameter type is 'IPXC_Document',so i use the method 'ConvertPDFToDoc ' to convert a PDF file to a IPXC_Document……
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Combine files too slow

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Re: Combine files too slow

Post by HomerWu »

Hello Sasha,

I ran into another problem when combine documents:I convert all the file path to PDFXEDIT.IAFS_Name,and add it as a input parameter,this step is success and quickly,but i found all the files will be used after the operation,i can't do any thing with them……Could you please tell me how to dispose the files after combine finished?

Code: Select all

public object CombineDocuments(List<string> documentList)
{
	try
	{
		PDFXEDIT.PXV_Inst Inst=pdfCtl.Inst;
		int nID=Inst.Str2ID("op.combineDocs",false);
		PDFXEdit.IOperation op=Inst.CreateOp(nID);
		PDFXEdit.ICabNode input=opParams.Root["Input"];
		foreach(string file in documentList)
		{
			PDFXEdit.IAFS_Inst fsInst=(PDFXEdit.IAFS_Inst)Inst.GetExtension("AFS");
			PDFXEdit.IAFS_Name destPath=fsInst.DefaultFileSys.StringToName(file);
			input.Add().v=destPath;
		}
		int opExecFlags=0;
		pdfCtl.Inst.AsyncDoAndWaitForFinish(op,(unit)opExecFlags);
		PDFXEdit.ICabNode output=op.Params.Root["Output"];
		return (PDFXEdit.IPXC_Document)output.Unknown;
	}
	catch(Exception ex)
	{
		
	}
}

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Combine files too slow

Post by Sasha - Tracker Dev Team »

Hello HomerWu,

Are they in use until you close the program, or do they become available after some time has passed?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply