簡體   English   中英

ABCPDF:將PDF文件拆分為單頁PDF文件

[英]ABCPDF: Split PDF files into single page PDF files

我正在使用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倍(在大型文檔上)但它保留了旋轉頁面的格式,這很重要。 這個問題是我必須附加整個文檔並再次刪除所有不需要的頁面。 這對文件中的所有頁面都是非常低效的。

有人可以幫我解決這個問題嗎?

所以我談到了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 []頁面類型的參數或要分割為REMAPPAGES方法的字符串逗號或空格分隔的頁碼(上面的代碼sb是stringbuilder)並保存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM