Ubuntu 18.04 上的 mPDF、CAM'PDF 搜索和替换问题
Search & replace issue on mPDF, CAM'PDF on Ubuntu 18.04
关于 Ubuntu 18.04 我在编辑 PDF 文件时遇到问题 - 特别是搜索和替换字符串。
我试过了:
PHP mPDF Overwrite()什么都不做
perl CAM :: PDF 1.60 changepagestring.pl 什么都不做
sed,什么都不做。
不适用于压缩或解压缩的 PDF,甚至不适用于从 mPDF 生成的 PDF。
更新:重新安装 libsodium 后,mPDF 可以很好地处理从 mPDF 生成的 PDF 文件。对于其他 PDF 文件问题仍然存在。
也在 var/www 文件夹用户/组 www-data: www/data 和其他文件夹/home 中尝试,例如
因为我有超过 1000 个文件要处理,所以有关于批量搜索和替换的想法吗?
文件中的文本是可读的。检查。
P.S。从程序和在线服务中搜索/替换使用相同的文件。
文件 0755 i 0777 的权限
root@sasa-ubuntu-1:/var/www/website.local/wp-content/test/2018/12# ls -la *.pdf
-rwxr-xr-x 1 www-data www-data 847451 Oct 18 12:21 clean.pdf
-rwxrwxrwx 1 www-data www-data 395527 Oct 17 21:41 My-First.pdf
-rwxr-xr-x 1 www-data www-data 838307 Oct 17 23:30 My.pdf
-rwxr-xr-x 1 www-data www-data 838167 Oct 18 12:24 New2.pdf
-rwxr-xr-x 1 www-data www-data 838167 Oct 18 01:20 New.pdf
-rwxrwxrwx 1 www-data www-data 270340 Oct 17 16:39 Test2.pdf
-rwxrwxrwx 1 www-data www-data 274022 Oct 17 16:39 Test1.pdf
-rwxr-xr-x 1 www-data www-data 838000 Oct 18 00:55 Test2.pdf
-rwxrwxrwx 1 www-data www-data 205679 Oct 17 23:44 test.pdf
Perl 脚本总是 return "Could not find title" 当我打印 $page 变量时,不要介意文件的可读性(见图片)
use CAM::PDF;
my $pdf = CAM::PDF->new('test.pdf'); # existing document
my $nump = $pdf->numPages();
#print $nump;
my $page = $pdf->getPageContent(1);
print $page;
# $page now holds the uncompressed page content as a string
# replace the text part
if ($page =~ s/Wagner/SoundTech/g) {
$pdf->setPageContent(1, $page);
}
else {
die "Could not find title\n";
}
$pdf->cleanoutput('Test2.pdf');
很多文件都是这样结束的。
我试图找到的字符串是 "Wagner International Music Examinations" 或者只有 "Wagner"
mPDF 和 CAM-PDF 已正确安装,没有警告和错误,并且具有所有依赖项,我希望。
Ubuntu 18.04
mPDF 8.0版
PHP 7.2
Perl 5.26.1
CAM-PDF 版本 1.60
mPDF 偶尔会有 Overwrite() 函数的错误,我在他们的 github 社区上发现了。
对 PDF 文件中的批量搜索和替换有任何建议或其他方法吗?
这是目前几乎适用于您的情况的 hack(我稍后会回来尝试改进它):
use feature qw(say);
use strict;
use warnings;
# the PDF uses a non-standard encoding so it does not help to use UTF-8
# use open qw(:std :encoding(UTF-8));
use utf8;
use CAM::PDF;
my $fn = 'test.pdf'; # uncompressed file..
my $save_fn = 'test2.pdf';
my $pdf = CAM::PDF->new($fn);
my $nump = $pdf->numPages();
my $match = 0;
my $replace = '[(\x{a9} SoundTech International Music Examinations)]TJ';
for my $i (1..$nump) {
my $page = $pdf->getPageContent( $i );
# replace the text part
if ($page =~ s/\[\(\x{a9}\).*?\]TJ/$replace/g) {
$match = 1;
$pdf->setPageContent($i, $page);
}
}
if ( $match ) {
$pdf->cleanoutput($save_fn);
say "Save $save_fn ..";
}
else {
say "No match";
}
关于 Ubuntu 18.04 我在编辑 PDF 文件时遇到问题 - 特别是搜索和替换字符串。
我试过了:
PHP mPDF Overwrite()什么都不做
perl CAM :: PDF 1.60 changepagestring.pl 什么都不做
sed,什么都不做。
不适用于压缩或解压缩的 PDF,甚至不适用于从 mPDF 生成的 PDF。 更新:重新安装 libsodium 后,mPDF 可以很好地处理从 mPDF 生成的 PDF 文件。对于其他 PDF 文件问题仍然存在。
也在 var/www 文件夹用户/组 www-data: www/data 和其他文件夹/home 中尝试,例如
因为我有超过 1000 个文件要处理,所以有关于批量搜索和替换的想法吗?
文件中的文本是可读的。检查。
P.S。从程序和在线服务中搜索/替换使用相同的文件。
文件 0755 i 0777 的权限
root@sasa-ubuntu-1:/var/www/website.local/wp-content/test/2018/12# ls -la *.pdf
-rwxr-xr-x 1 www-data www-data 847451 Oct 18 12:21 clean.pdf
-rwxrwxrwx 1 www-data www-data 395527 Oct 17 21:41 My-First.pdf
-rwxr-xr-x 1 www-data www-data 838307 Oct 17 23:30 My.pdf
-rwxr-xr-x 1 www-data www-data 838167 Oct 18 12:24 New2.pdf
-rwxr-xr-x 1 www-data www-data 838167 Oct 18 01:20 New.pdf
-rwxrwxrwx 1 www-data www-data 270340 Oct 17 16:39 Test2.pdf
-rwxrwxrwx 1 www-data www-data 274022 Oct 17 16:39 Test1.pdf
-rwxr-xr-x 1 www-data www-data 838000 Oct 18 00:55 Test2.pdf
-rwxrwxrwx 1 www-data www-data 205679 Oct 17 23:44 test.pdf
Perl 脚本总是 return "Could not find title" 当我打印 $page 变量时,不要介意文件的可读性(见图片)
use CAM::PDF;
my $pdf = CAM::PDF->new('test.pdf'); # existing document
my $nump = $pdf->numPages();
#print $nump;
my $page = $pdf->getPageContent(1);
print $page;
# $page now holds the uncompressed page content as a string
# replace the text part
if ($page =~ s/Wagner/SoundTech/g) {
$pdf->setPageContent(1, $page);
}
else {
die "Could not find title\n";
}
$pdf->cleanoutput('Test2.pdf');
很多文件都是这样结束的。
我试图找到的字符串是 "Wagner International Music Examinations" 或者只有 "Wagner"
mPDF 和 CAM-PDF 已正确安装,没有警告和错误,并且具有所有依赖项,我希望。 Ubuntu 18.04 mPDF 8.0版 PHP 7.2 Perl 5.26.1 CAM-PDF 版本 1.60
mPDF 偶尔会有 Overwrite() 函数的错误,我在他们的 github 社区上发现了。
对 PDF 文件中的批量搜索和替换有任何建议或其他方法吗?
这是目前几乎适用于您的情况的 hack(我稍后会回来尝试改进它):
use feature qw(say);
use strict;
use warnings;
# the PDF uses a non-standard encoding so it does not help to use UTF-8
# use open qw(:std :encoding(UTF-8));
use utf8;
use CAM::PDF;
my $fn = 'test.pdf'; # uncompressed file..
my $save_fn = 'test2.pdf';
my $pdf = CAM::PDF->new($fn);
my $nump = $pdf->numPages();
my $match = 0;
my $replace = '[(\x{a9} SoundTech International Music Examinations)]TJ';
for my $i (1..$nump) {
my $page = $pdf->getPageContent( $i );
# replace the text part
if ($page =~ s/\[\(\x{a9}\).*?\]TJ/$replace/g) {
$match = 1;
$pdf->setPageContent($i, $page);
}
}
if ( $match ) {
$pdf->cleanoutput($save_fn);
say "Save $save_fn ..";
}
else {
say "No match";
}