On Ubuntu 18.04 I have a problem with editing PDF files - specifically search & replace strings.
I tried:
PHP mPDF Overwrite () do nothing.
perl CAM :: PDF 1.60 changepagestring.pl do nothing
sed, do nothing.
Does not work with compressed or decompressed PDF, Does not even work with PDF generated from mPDF. UPDATE: after reinstalling libsodium mPDF works fine with PDF files generated fromm mPDF. For other PDF files issue still exist.
Also tried in var / www folders user / group www-data: www / data and in other folders / home e.g.
Any idea for bulk search & replace because I have over 1000 files to process?
The text in the files is readable. Check.
P.S. Search / Replace from the program and online service works with the same files.
Permission on files 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 script allways return "Could not find title" nevermind of readability of file when I print $page variable (see images)
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');
A lot of files ends on this way.
The string that I try to find is "Wagner International Music Examinations" or only "Wagner"
mPDF and CAM-PDF are properly installed without warnings and erros and with all dependencies, I hope. Ubuntu 18.04 mPDF version 8.0 PHP 7.2 Perl 5.26.1 CAM-PDF version 1.60
mPDF occasionally have bug with Overwrite() function, I found on their github community.
Any suggestion or another way for bulk search & replace in PDF files?
Here is a hack that currently works almost for your case (I will come back later and try improve this):