下面的腳本能夠使用CAM::PDF
一個PDF文件中刪除所有圖像。然而,輸出是腐敗的。 PDF閱讀器仍然可以打開它,但他們抱怨錯誤。例如,mupdf
說:如何刪除從PDF的所有圖像,而無需使用CAM :: PDF破壞呢?
error: no XObject subtype specified
error: cannot draw xobject/image
warning: Ignoring errors during rendering
mupdf: warning: Errors found on page
現在,CAM::PDF
一頁CPAN(here)列在「更深事業」的deleteObject()
方法,想必這意味着它不能用於公共用途。此外,它警告:
此函數不負責依賴此對象。
我的問題是:什麼是使用CAM::PDF
從PDF文件中刪除對象的正確方法?如果問題與依賴關係有關,那麼如何在處理依賴關係時移除對象?
有關拆除使用其他工具從PDF圖像,看到一個相關的問題here。
use CAM::PDF;
my $pdf = new CAM::PDF (shift) or die $CAM::PDF::errstr;
foreach my $objnum (sort { $a <=> $b } keys %{ $pdf->{xref} }) {
my $xobj = $pdf->dereference ($objnum);
if ($xobj->{value}->{type} eq 'dictionary') {
my $im = $xobj->{value}->{value};
if
(
defined $im->{Type} and defined $im->{Subtype}
and $pdf->getValue ($im->{Type} ) eq 'XObject'
and $pdf->getValue ($im->{Subtype}) eq 'Image'
)
{
$pdf->deleteObject ($objnum);
}
}
}
$pdf->cleanoutput ('-');
你會有一個損壞的pdf,使mupdf錯誤可用嗎?我正在調試類似的問題,這將是很大的幫助:) – Darajan