michaelrsweet / pdfio

PDFio is a simple C library for reading and writing PDF files.
https://www.msweet.org/pdfio
Apache License 2.0
198 stars 44 forks source link

acrobat reader: The font '<font>' contains bad /Widths #64

Closed zacii7 closed 5 months ago

zacii7 commented 8 months ago

fonts embedded by pdfioFileCreateFontObjFromFile give adobe acrobat reader trouble. all other pdf viewers i have tried work fine. on PC, it gives an error message: "The font '...' contains bad /Widths". after clicking "ok", the pdf renders, but text alignment is off. on mobile (android; I have not tried others), as well as acrobat online, it does not render any text at all with these fonts. even when searching for text that should be there, nothing comes up. the rest of the pdf is rendered correctly.

I have used the same font with perl PDF::API2, and the text does display correctly on acrobat mobile.

I dont know it this is an issue with pdfio or the ttf library. the problem only comes up when used in a pdf.

michaelrsweet commented 8 months ago

Please attach a sample PDF generated with PDFio and the corresponding TTF file. I can't reproduce with the test suite.

zacii7 commented 8 months ago

here is an example pdf with 2 lines of text. the first line is in a base font. the second line is in a custom font. it displays fine in all viewers except adobe acrobat (android mobile, and online), which displays only the first line. sample2.pdf

here are the fonts i am using, but i have had the same problem with any other fonts i have tried fonts.zip

the same fonts work in acrobat when generated with perl PDF::API2 eg. sample.pdf

EDIT

Your mention of the test suite gave me a clue. I noticed that only the unicode tests display in acrobat, the regular one does not. my files were all created with the unicode parameter set to 0. I tried again with unicode set to 1 in both pdfioFileCreateFontObjFromFile and pdfioContentTextShow, and now it works properly in acrobat as well.

thanks

should there be any other difference whether or not unicode is set? if I change all unicode parameters to 1, would that have any other effect on the output pdf?

michaelrsweet commented 5 months ago

should there be any other difference whether or not unicode is set? if I change all unicode parameters to 1, would that have any other effect on the output pdf?

Well it will make the PDF a little larger but otherwise it will work the same. And obviously there must be some issue with the fonts using an 8-bit subset (not all TrueType fonts support non-Unicode usage...)