We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Error: PdfFileEditor merge not working

Hello,

I try to use PdfFileEditor to merge several PDFs together with the Append(string inputFile, string[] portFiles, int startPage, int EndPage, string outputFile) method.
Given one set of files, this works satisfactorily. However, on a different set of files it fails by not returning from the call to Append().
My code looks like:

private void Merge(string filename)
{

    var pdfEditor = new PdfFileEditor();
    var pageFiles = new List<string>();
    for (var pNum = 1; pNum < 3; pNum++)
    {
        var appendFilename = $@"C:\Temp\xy.pdf";
        pageFiles.Add(appendFilename);                
    }

    const string finalPage = @"C:\Temp\out.pdf";
    pdfEditor.Append(finalPage, pageFiles.ToArray(), 1, int.MaxValue, targetFilename);
}

The files in question, both the set for which it is working and the set for which it is not have been generated by splitting a large presentation. If you need I can send you the required files.

For our project it is really urgent to understand if your library can handle this or we need to find another API?

Thank you
Stefan Kaht

@skaht,

Please create a ZIP of your three problematic PDF documents. There is an upload button in the header of the post editor. In case, if the attachment exceeds 3MB size limit, then please upload this file to any free file sharer server, e.g. Google Drive, Dropbox etc. and share its download URL with us.

PDFDemo.zip (250.0 KB)

Hi,

here we go - thanks for your support!

Stefan Kaht

@skaht,

It is because you are passing the Max integer value as the end page number parameter. We recommend our clients to pass the realistic values. Please change the Max value, and then let us know how that goes into your environment.

Hi Imran,

thank you for the response. If I pass in a smaller value as int.MaxValue the call works (for the moment).

I am not sure what I need to specify here for startPage and endPage parameters.

Do they specify a range of documents within the filename array to merge, i.e. Append(“Page1.pdf”, [ “Page2.pdf”, “Page3.pdf”, Page4.pdf”], 1, 1, “Merged.pdf”) will merge documents Page1.pdf and Page3.pdf into Merged.pdf?

Or will the call Append(“Page1.pdf”, [ “Page2.pdf”, “Page3.pdf”, Page4.pdf”], 1, 2, “Merged.pdf”) merge the first and second page (or the second and third page) of all three documents into the target document?

I have not been able to find this out experimentally, for me, a range of 0 to 1 produces no output document, but the function returns (at least).

A range of 1 to 2 produces output document with all files merged – I cannot tell about the page ranges merged as this are single page documents.

A range of 1 to int.MaxValue crashes your function with the files provided, but not with other files.

I think you need to explain this a little bit more in your documentation.

Additionally, I would still consider it a bug if I pass in int.MaxValue into your function and the function silently dies. This somehow makes me wonder if I have observed a memory buffer overflow in your function.

Please advise and clarify that this is not the case, as it would raise security concerns when using your components.

Thx
Stefan

@skaht,

You can retrieve the page collection or a single page instance from a PDF document, and then concatenate into the second PDF document. In order to concatenate multiple PDF documents, you can repeat this process in the code. Please refer to this help topic: Concatenate PDF Files

There is no way to track page numbers in an array of PDF file names. In order to specify a range of pages, you can import a PDF document to Document instance, add or remove page(s) before inserting into another PDF document by calling PageCollection.Add method, and do not save this instance of PDF document to local computer. Please refer to these help topics: Delete a Particular Page from the PDF File and Insert an Empty Page in a PDF File

It has been logged under the ticket ID PDFNET-44848 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.