gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

Unrecognized font error in Adobe Acrobat Reader after signing Chrome print PDF #308

Closed omohokcoj closed 2 months ago

omohokcoj commented 2 months ago

index.html.pdf

require 'hexapdf'
require HexaPDF.data_dir + '/cert/demo_cert.rb'

doc = HexaPDF::Document.new(io: File.open('index.html.pdf'))

doc.sign("signed.pdf",
         reason: 'Some reason',
         certificate: HexaPDF.demo_cert.cert,
         key: HexaPDF.demo_cert.key,
         certificate_chain: [HexaPDF.demo_cert.sub_ca,
                             HexaPDF.demo_cert.root_ca])

image

Signing this PDF generated using Chrome Print feature causes 'Cannot extract the embedded font error' in Adobe. Modifying the document and saving a new revision doesn't result in an error.

gettalong commented 2 months ago

Thanks for reporting!

I tried to reproduce the error but failed. My steps were:

  1. Download the linked file.
  2. Add the code in the issue description to a file.
  3. Run the file with HexaPDF 0.44.0.
  4. Open the generated signed.pdf in Adobe Reader on Windows.

The file opens fine in Adobe Reader without any error. Selecting and copying the text also works without problems.

Inspecting the generated signed.pdf shows only one potentially significant difference that is related to the error. The font descriptor object for the font has the /Descent value corrected from 250 to -250 since the PDF spec mandates that the value needs to be negative.

Could you provide the signed.pdf that shows this error?

omohokcoj commented 2 months ago

@gettalong thanks for the quick reply!

signed.pdf

I'm using Adobe Reader on Mac: image image

gettalong commented 2 months ago

Thanks for the PDF! Alas, it doesn't show as invalid for me with Reader 2024.001 image

Could you update to the latest reader on macOS and try again?

gettalong commented 2 months ago

@omohokcoj Could you try the following file signed.pdf? It was generated using write_options: {validate: false} which doesn't modify the font descriptor.

omohokcoj commented 2 months ago

@gettalong i've updated the the latest version of adobe and now the error is gone. some users also reported this error on older versions - but hopefully they can update the Adobe app soon

gettalong commented 2 months ago

@omohokcoj Thanks for the feedback! You could also try the file from https://github.com/gettalong/hexapdf/issues/308#issuecomment-2171361630 that was generated without the validation on the older Reader version.