简体   繁体   English

用于根据模式从 pdf 文件中删除页面的 Perl 脚本

[英]Perl script for removing pages from a pdf file based on pattern

We have a 3,000-page PDF file and we want to remove pages based on a pattern.我们有一个 3,000 页的 PDF 文件,我们想根据模式删除页面。

For example pagenot found in the PDF have 50 pages.例如,在 PDF 中找不到的 pagenot 有 50 页。 Now output is like to 2,950 pages by removing 50 pages from the document.现在,通过从文档中删除 50 页,输出就像是 2,950 页。

Could you please try this:你能试试这个吗:

use strict;
use warnings;
use CAM::PDF;

my $pdf = CAM::PDF->new('input.pdf');
my $ttl_pgs = $pdf->numPages();

for(1..$ttl_pgs)
{
    my $pagnum = $_;
    my $pdf_cnt = $pdf->getPageContent($pagnum);
    if($pdf_cnt=~m/pages not found/i)
    {
         $pdf->deletePage($pagnum);
    }
}
$pdf->cleanoutput('output.pdf');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM