ABCPDF:将PDF文件拆分为单页PDF文件

本文关键字:文件 PDF 单页 拆分 ABCPDF | 更新日期: 2023-09-27 18:26:47

我正在使用ABCpdf工具,并试图将1TB的PDF文件(因此效率是一个问题)拆分为单页PDF文件。

我尝试过以下几种:

Doc theSrc = new Doc();
theSrc.Read("C://development//pdfSplitter//Bxdfbc91ca-fc05-4315-8c40-798a77431ee0xP.pdf");
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();
    singlePagePdf.Save("C://development//pdfSplitter//singlePDF//singlePage"+i+".pdf");
    singlePagePdf.Clear();
}
theSrc.Clear();

这是一个非常快,但它没有保持旋转的页面,他们需要。我试着手动旋转它们,但很快就有点乱了,它们并没有像原始文档中那样精确。

我也试过:

Doc theSrc = new Doc();
theSrc.Read("C://development//pdfSplitter//Bxdfbc91ca-fc05-4315-8c40-798a77431ee0xP.pdf");
for (int i = 1; i <= theSrc.PageCount; i++)
{  
    Doc singlePagePdf = new Doc();
    singlePagePdf.Append(theSrc);
    singlePagePdf.RemapPages(i.ToString());
    singlePagePdf.Save("C://development//pdfSplitter//singlePDF//singlePage"+i+".pdf");
    singlePagePdf.Clear();
}
theSrc.Clear();

这一个(在大型文档上)比第一个慢大约6倍,但它保持了旋转页面的格式,这很重要。这个的问题是,我必须附加整个文档,并再次删除所有不需要的页面。这是为文件中的所有页面执行的,这是非常低效的。

有人能在这件事上帮我吗?

ABCPDF:将PDF文件拆分为单页PDF文件

所以我与WebSuperGoo(ABCpdf的创建者)的支持人员进行了交谈,他们给了我以下内容:

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();

这个解决方案与我的第一个解决方案相同,但它包含了页面旋转,速度非常快。

我希望这也能帮助其他人。

有一个更新的解决方案,(>ABCpdf 9.0的最新版本)这是一种高效、快速的方法。

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

将要拆分的类型为int[]pages或字符串逗号或空格分隔的页码的参数传递给REMAPPAGES方法(上面的代码sb是字符串生成器)并保存。