Home Performance issue when using old iText for .NET version when splitting a huge PDF
Reply: 0

Performance issue when using old iText for .NET version when splitting a huge PDF

user1565 Published in July 21, 2018, 1:52 pm

My goal here is to split a huge PDF (over 1000 pages).

I tried the example below :

public void ExtractPages(string sourcePdfPath, string outputPdfPath, 
    int startPage, int endPage)
    PdfReader reader = null;
    Document sourceDocument = null;
    PdfCopy pdfCopyProvider = null;
    PdfImportedPage importedPage = null;
        // Intialize a new PdfReader instance with the contents of the source Pdf file:
        reader = new PdfReader(sourcePdfPath);

        // For simplicity, I am assuming all the pages share the same size
        // and rotation as the first page:
        sourceDocument = new Document(reader.GetPageSizeWithRotation(startPage));

        // Initialize an instance of the PdfCopyClass with the source 
        // document and an output file stream:
        pdfCopyProvider = new PdfCopy(sourceDocument, 
            new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));


        // Walk the specified range and add the page copies to the output file:
        for (int i = startPage; i <= endPage; i++)
            importedPage = pdfCopyProvider.GetImportedPage(reader, i);
    catch (Exception ex)
        throw ex;

It works but it takes more than 10 min.

My question here is there any way to skip the for loop and getting all the pages quickly ??

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309633 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO