pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Embedded vs. non-embedded fonts (PDFBox & iText)
Date Fri, 14 Apr 2017 08:54:56 GMT
Am 14.04.2017 um 10:50 schrieb Vassallo, Fabio:
> Thank you very much, Tilman.
> Please, ignore my sentence about the empty file: I had an (unrelated) exception is another
point of my code. Sorry.
>
> The font removal works (the code is at the end of this mail).
>
> Now the viewer issues an error like:
> Cannot find or create the font 'AAAEOG+ArialMT'.
> And obviously the file isn't correctly displayed.

I would have to see the file to find out what went wrong. And an itext 
generated file as well, if possible.

Btw "AAAEOG+ArialMT" means you used a subset. Avoid doing that, i.e. set 
the embedSubset parameter to false. This way PDFBox will embed the full 
font, which you'll delete later.

Tilman


>
> With iText I obtain /Encoding entries referring to /BaseFont /Helvetica, also for the
special characters outside the WinAnsi range, and the viewer correctly opens the file.
> I wonder if it's possible to manipulate the file with PDFBox, so that it refers to Helvetica
as well.
>
> Thank you in advance,
> Fabio
>
>
> ---
>
>      private void clearAllFontDescriptors() throws IOException
>      {
>          for(PDPage page : document.getPages())
>          {
>              PDResources pageResources = page.getResources();
>              for(COSName fontName : pageResources.getFontNames())
>              {
>                  clearFontDescriptor(pageResources.getFont(fontName));
>              }
>          }
>      }
>
>      public void clearFontDescriptor(PDFont pdFont)
>      {
>          PDFontDescriptor fontDescriptor = pdFont.getFontDescriptor();
>          COSDictionary cosObj = fontDescriptor.getCOSObject();
>          Set<COSName> fontNameSet = new HashSet<>();
>          for(COSName name : cosObj.keySet())
>          {
>              if(name.getName().startsWith("FontFile"))
>              {
>                  fontNameSet.add(name);
>              }
>          }
>
>          for(COSName name : fontNameSet)
>          {
>              cosObj.removeItem(name);
>          }
>      }
>
>
> Fabio Vassallo
> Product Development (CIS)
>
>
> W├╝rth Phoenix S.r.l.
> via Kravogl 4, 39100 Bolzano
> T: +39 0471 564 116
> F: +39 0471 564 122
> Website | e-Mail | Map
>
>            
>
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: Friday, April 14, 2017 9:52 AM
> To: users@pdfbox.apache.org
> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>
> Your code looks good.
>
> Does "clearAllFontDescriptors" have access to your current document object?
>
> Does "the resulting file is empty" mean that the file is empty, or that the display is
blank?
>
> I don't have further ideas without seeing more of the code, and maybe look at the files
with pdfdebugger ... maybe try removing "clearAllFontDescriptors" to see whether there's a
problem with your logic.
>
> Tilman
>
> Am 14.04.2017 um 09:37 schrieb Vassallo, Fabio:
>> Actually I don't save the file: i display it in the screen, and then the user can
choose to save it or not.
>> So I currently create a byte[] containing the PDDocument data and I use it to display
the file:
>>
>> ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
>> PDDocument document = ...
>>
>> <... build the PDF content ...>
>>
>> try
>> {
>>       document.save(outputStream);
>>       document.close();
>>       return outputStream.toByteArray(); } catch(IllegalStateException
>> e) {
>>       ...
>> }
>>
>> I tried to do this:
>>
>> try
>> {
>>       document.save(outputStream);
>>       document.close();
>>       document = PDDocument.load(outputStream.toByteArray());
>>       clearAllFontDescriptors();
>>       outputStream = new ByteArrayOutputStream();
>>       document.save(outputStream);
>>       document.close();
>>       return outputStream.toByteArray(); } catch(IllegalStateException
>> e) {
>>       ...
>> }
>>
>> Where clearAllFontDescriptors() should perform the cosObj.removeItem(fontName). But
apparently the PDDocument.load(...) doesn't work as I expected, and the resulting file is
empty.
>>
>> Fabio Vassallo
>> Product Development (CIS)
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message