Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad /Contents 1 error while processing a file #95

Open
isbur opened this issue Nov 6, 2024 · 10 comments
Open

Bad /Contents 1 error while processing a file #95

isbur opened this issue Nov 6, 2024 · 10 comments

Comments

@isbur
Copy link

isbur commented Nov 6, 2024

Hello! I have a bunch1.zip of files which I'm processing with cpdf. Two of them were previously processed by cpdf. I'm trying to merge them and than page-number the merged file with command inside PowerShell script:

cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 $file.FullName -o $targetPath

And it fails with error:
Bad /Contents 1

However if I run cpdf on a bunch2.zip, that consists of initital source files not processed by cpdf, it pagenumbers the merged PDF without problems.

It seems like somehow cpdf corrupts files while merging and makes it inapropriate for -add-text command.

If I try to pagenumber single preprocessed by cpdf file from bunch1.zip (actually both of them, they are marked as -merged in filenames) cpdf also runs smoothly.
bunch1.zip
bunch2.zip

@johnwhitington
Copy link
Contributor

Can you give the output of cpdf -version please.

@isbur
Copy link
Author

isbur commented Nov 6, 2024

Sure

cpdf AGPL Version 2.7.2 (28th October 2024)

@johnwhitington
Copy link
Contributor

Ok, I ran:

cheddar:Downloads john$ ./cpdf
cpdf AGPL Version 2.7.2 (28th October 2024)
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch1/02_Урок\ 13\,15\ учителю.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch1/OGE_2024_Zadanie_13_pr_resh.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch1/OGE_2024_Zadanie_13_vse-merged.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch1/OGE_2024_Zadanie_14_pr_resh.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch1/OGE_2024_Zadanie_14_vse-merged.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/ -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/02_Урок\ 13\,15\ учителю.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/OGE_2024_Zadanie_13_vse.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/OGE_2024_Zadanie_13_vse_otvety.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/OGE_2024_Zadanie_14_pr_resh.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/OGE_2024_Zadanie_14_vse.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/OGE_2024_Zadanie_14_vse_otvety.pdf -o out.pdf
cheddar:Downloads john$ ./cpdf -add-text "%Page" -bottom 15pt -font "Times-Roman" -font-size 14 ~/Desktop/isbur/bunch2/OGE_2024_Zadanie_13_pr_resh.pdf -o out.pdf

and I get no errors. Can you show me a failing command?

@isbur
Copy link
Author

isbur commented Nov 30, 2024

It's a kind of magic...

I've tried once again and couldn't detect any issues too.

Indeed when I first encountered the issue, I tried to update cpdf and see whether the issue persisted. It persisted. But maybe I was still using an old version of cpdf somehow? For example, I didn't reload PowerShell and it used some cached version of binary... I dunno.

@isbur isbur closed this as completed Nov 30, 2024
@isbur
Copy link
Author

isbur commented Dec 2, 2024

Hm.... I've met this error again. Here's the command:

cpdf -add-text "%Page of %EndPage" -bottom 15pt -font "Times-Roman" -font-size 14 .\учителю.pdf -o .\учителю-numbered.pdf

Here's the problematic file:
учителю.pdf

@johnwhitington are you able to reproduce error on your machine?

@isbur isbur reopened this Dec 2, 2024
@johnwhitington
Copy link
Contributor

The file is malformed: it has some page contents entries pointing to stuff which is not page content.

I have altered CamlPDF (Cpdf's base library) to ignore the problem and it now completes:

$ cpdf -add-text "%Page of %EndPage" -bottom 15pt -font "Times-Roman" -font-size 14 учителю.pdf -o out.pdf
Page /Contents not a stream: ignoring.
Page /Contents not a stream: ignoring.
Page /Contents not a stream: ignoring.
Page /Contents not a stream: ignoring.

As a bonus, the file will now be repaired - at least in that respect. Your file crashes Adobe Reader, but after processing with this new version of Cpdf it does not crash - it shows a couple of error popups though, complaining of malformed content - so presumably there are other problems. As a check, I asked Ghostscript to convert it to PostScript and got:

$ pdf2ps учителю.pdf
**** Error: Page drawing error occurred.
Output may be incorrect.

So there is definitely some malformity.

You can build a new version from source (use master CamlPDF with master Cpdf).

If you're a commercial customer I can make a build for you - contact me using the support email address.

@isbur
Copy link
Author

isbur commented Dec 10, 2024

Thank you for finding solution quickly!

However, I'm afraid it's just a temporary solution with some deeper problem hiding underneath. This file itself was created with cpdf, so it seems that there is some problem with file generation.

I used these files to create the malformed one with the following command:

cpdf -merge -idir $args -o $fileName

I've used the same page-numbering script on every source file and it has run successively.

@johnwhitington
Copy link
Contributor

Was that merged file created by cpdf 2.7.2 or an earlier version? This smells like a problem to do with rewriting of structure trees on merging which was corrected a few weeks ago - a fix included in 2.7.2.

@johnwhitington
Copy link
Contributor

I ran

cpdf -idir files -o merged.pdf

Then

cpdf -add-text "%Page of %EndPage" -bottom 15pt -font "Times-Roman" -font-size 14 merged.pdf -o numbered.pdf

And I get the attached file. This is with cpdf 2.8 (which is out soon). Please re-check you are using v2.7.2. If that fails, I will send you a build of v2.8.

numbered.pdf

@johnwhitington
Copy link
Contributor

I don't mean v2.7.2, I mean v2.7.2(fix 1) i.e downloaded from this repository "master".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants