pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hewson <j...@jahewson.com>
Subject Re: Width information for rendered glyphs is inconsistent
Date Sat, 22 Nov 2014 00:21:45 GMT
Vadimo,

Type 0 fonts are special, they are wrappers around a child font, which can be found in the
first element of the DescendantFonts array. Type 0 fonts don’t have a FontDescriptor, instead
it can be found in the child font. Remember, the error message you have is not “Missing
FontDescriptor”, nor is it “Missing width”, so you should expect to find both the FontDescriptor
and Widths present, but just with incorrect values.

Also note that some kinds of font store widths in the “W” entry, instead of “Widths”.

-- John

> On 20 Nov 2014, at 14:42, Vadim Bauer <bauer.vadim@gmail.com> wrote:
> 
> Hello,
> 
> I looked at the areas suggested by John and found that the font didn't had a font descriptor.
> So after creating and setting a font descriptor I copied the widths from the loaded ttf
file with the same name.  
> 
> List<PDPage> allPages = doc.getDocumentCatalog().getAllPages();
> for (PDPage page : allPages) {
>   PDResources pageResources = page.findResources();
>   Map<String, PDFont> fonts = pageResources.getFonts();
>   for (PDFont font : fonts.values()) {
>      assert font.getFontDescriptor() == null; // font descriptor is null
>      PDFontDescriptorDictionary fdDictionary = new PDFontDescriptorDictionary();
>      font.setFontDescriptor(fdDictionary);
>      List<Float> widths = font.getWidths(); // is null
> 
>      //loading same font and apply widths
>      InputStream isNimbus = getClass().getResourceAsStream("/NimbusSanL-Regu.ttf");
>      PDTrueTypeFont ttf = PDTrueTypeFont.loadTTF(doc, isNimbus);
>      List<Float> newWidths = ttf.getWidths();//[278.0, 278.0, 355.0, 556.0, 556.0,
889.0, 667.0, 191.0, 333.0, 333.0, 389.0, 584.0,
>      font.setWidths(newWidths);
>   }
> }
> 
> when I opened the pdf acrobat complained that the font NimbusSanL-Regu could not be loaded.
All the characters were dotted.
> 
> Then I replaced the font in pageResources with the loaded ttf and added under the same
key. But that didn't work as well.
> 
> Any ideas, how I can recalculate the widths from the given font. Was it a problem that
the font in the pdf is marked as Typ0 and the font with the same name is of type3?   
> 
> This is the cos object of the given Font.
> 
> Font COS object.
> COSDictionary{(COSName{Type}:COSName{Font}) (COSName{Subtype}:COSName{Type0}) (COSName{BaseFont}:COSName{NimbusSanL-Regu})
(COSName{Encoding}:COSName{Identity-H}) (COSName{DescendantFonts}:COSArray{[COSObject{26,
0}]}) (COSName{ToUnicode}:COSDictionary{(COSName{Length}:COSInt{791}) }) }
> 
> Best regards,
> Vadimo
> 
>> Am 16.11.2014 um 20:07 schrieb John Hewson <john@jahewson.com>:
>> 
>> Hi Vadimo
>> 
>> This error means that the Widths in the embedded font file don’t match the widths
in the FontDescriptor. You’ll need to update whichever is wrong, however PDFBox can’t
edit fonts so you can only use it to update the FontDescriptor width, which may or may not
be what you want. The Widths specifies the width of each glyph and can be found at:
>> 
>> Page -> Resources -> Font -> FontDescriptor -> Widths
>> 
>> The manner in which fonts are embedded in PDF is very complex, and this kind of repair
will require that you have a good understanding of the relevant concepts from the ISO 32000
PDF specification. PDFBox provides the low-level APIs which you need, but you need to understand
PDF in order to use them.
>> 
>> Thanks
>> 
>> -- John
>> 
>>> On 16 Nov 2014, at 08:02, Vadim Bauer <bauer.vadim@gmail.com> wrote:
>>> 
>>> Hi, 
>>> 
>>> I have a PDFA where Adobe preflight says 'Width information for rendered glyphs
is inconsistent'
>>> I would like to correct that with PDFBox as the PDFs in question has only this
one error.
>>> 
>>> As I understand I need to get all the text characters(Strings?) in the PDF and
set/(modify or recalculate?).
>>> 
>>> 
>>> Question is how can I achieve this with PDFBox, can someone give me hints maybe
in pseudo code.
>>> Currently I am browsing the code but I am quite lost on where to dig.
>>> 
>>> 
>>> Cheers,
>>> Vadimo
>> 
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message