ABCPDF: Split PDF files into single page PDF files

馋奶兔 提交于 2019-12-05 17:50:33

So I talked to the support at WebSuperGoo (The creators of ABCpdf) and they gave me the following:

Doc theSrc = new Doc();
theSrc.Read("C://development//pdfSplitter//Bxdfbc91ca-fc05-4315-8c40-798a77431ee0xP.pdf");

int srcPagesID = theSrc.GetInfoInt(theSrc.Root, "Pages");
int srcDocRot = theSrc.GetInfoInt(srcPagesID, "/Rotate");

for (int i = 1; i <= theSrc.PageCount; i++)
{   
    Doc singlePagePdf = new Doc();
    singlePagePdf.Rect.String = singlePagePdf.MediaBox.String = theSrc.MediaBox.String;
    singlePagePdf.AddPage();
    singlePagePdf.AddImageDoc(theSrc, i, null);
    singlePagePdf.FrameRect();

    int srcPageRot = theSrc.GetInfoInt(theSrc.Page, "/Rotate");
    if (srcDocRot != 0)
    {
        singlePagePdf.SetInfo(singlePagePdf.Page, "/Rotate", srcDocRot);
    }
    if (srcPageRot != 0)
    {
        singlePagePdf.SetInfo(singlePagePdf.Page, "/Rotate", srcPageRot);
    }

    singlePagePdf.Save("C://development//pdfSplitter//singlePDF//singlePage"+i+".pdf");
    singlePagePdf.Clear();
}
theSrc.Clear();

This solution is equal to my first solution but it incorporates the page rotation and is very fast.

I hope this can help others as well.

There is an updated solution for this, (latest version of > ABCpdf 9.0) this is an efficient and faster way of doing.

 using (Doc copyDoc = new Doc())
      {
           copyDoc.Read(filePath);
           copyDoc.RemapPages(sb.ToString());
           copyDoc.Save(tagetFileName);
      }

Pass arguments of type int[] pages or a string comma or space separated page numbers that you want to split to REMAPPAGES method (above code sb is stringbuilder) and save.

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