delete first page from PDF using iTextSharp

做~自己de王妃 提交于 2019-12-10 13:22:57

问题


Is there a way we can delete the first page of the PDF using iTextSharp?


回答1:


There's no direct way to remove pages from a PDF using iTextSharp.

However, you can copy all the pages you want from a PDF and skip the pages you don't want. In your case you'd copy out all but the first page.

I wrote a method that does this based on the code I found on this blog entry.




回答2:


PdfReader reader_SecondPdf = new PdfReader(pdf_of_Second_File);

        for (j = 2; j <= reader_SecondPdf.NumberOfPages; j++)
    {

    }



回答3:


using itext 7 (thanks to @mkl)

    public static void ExtractPagesFromPdf(string inputFile, string outputFile, int start, int end)
    {
        PdfReader inputPdf = new PdfReader(inputFile);
        PdfDocument docIn = new PdfDocument(inputPdf);

        PdfWriter outputWriter = new PdfWriter(outputFile);
        PdfDocument docOut = new PdfDocument(outputWriter);

        // retrieve the total number of pages
        int pageCount = docIn.GetNumberOfPages();

        if (end < start || end > pageCount)
        {
            end = pageCount;
        }

        var merge = new PdfMerger(docOut);

        merge.Merge(docIn, start, end);

        merge.Close();
    }

from archive.org snapshot using itextsharp 5.x http://web.archive.org/web/20110619070947/http://www.jamesewelch.com:80/2008/11/14/how-to-extract-pages-from-a-pdf-document/



来源:https://stackoverflow.com/questions/2907354/delete-first-page-from-pdf-using-itextsharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!