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

lopdf does not output xref table or trailer dictionary as per spec #344

Closed
fschutt opened this issue Nov 6, 2024 · 2 comments
Closed

lopdf does not output xref table or trailer dictionary as per spec #344

fschutt opened this issue Nov 6, 2024 · 2 comments

Comments

@fschutt
Copy link
Contributor

fschutt commented Nov 6, 2024

  1. The trailer dictionary is missing the required trailer keyword, i.e. lopdf outputs << /Root 5 0 R/Size 6 ... >> instead of trailer<< /Root 5 0 R/Size 6 ... >>
  2. lopdf doesn't output any standard plain-text xref table? In every newly PDF generated by lopdf, there is no xref table, only an /XRef stream on the trailer dictionary.

This leads to errors in some PDF viewers, see mozilla/pdf.js#19007

@Heinenen
Copy link
Collaborator

There are two ways in the spec to write the cross-reference information, the "old" way as an xref table and the "new" (since PDF1.5) way as a cross-reference stream.

The default way that lopdf does it is via the cross-reference stream. The stream does not require the trailer keyword (cf. 7.5.8 Cross-reference streams).

The value following the startxref keyword shall be the byte offset of the cross-reference stream rather
than the xref keyword. For PDF files that use cross-reference streams entirely ([..]), the keywords xref and trailer shall no longer be used.

If you prefer the classical xref table over cross-reference streams, you can configure lopdf to output those instead by changing the xref type:

let mut doc = Document::with_version("1.7");
doc.reference_table.cross_reference_type = XrefType::CrossReferenceTable;

I couldn't reproduce the issue by myself. Could you maybe post some way to reproduce your issue?

PS: The PDF in your linked issue is not spec compliant because it is only PDF1.3 which are not allowed to have cross-reference streams (only since PDF1.5). If you don't have the specific requirement to use PDF1.3 I highly recommend switching to at least PDF1.7. By now, PDF1.7 is 16 years old, so all readers should be able to handle it.

@fschutt
Copy link
Contributor Author

fschutt commented Nov 18, 2024

Thank you. It's not really about the age of the PDF standard, it's just that some PDF standards are set for a specific conformance and for print proofing, so Acrobat will spit out errors when sending the PDF file to a printing company.

@fschutt fschutt closed this as completed Nov 18, 2024
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