You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Vassallo, Fabio" <Fa...@wuerth-phoenix.com> on 2017/04/04 10:01:35 UTC

Embedded vs. non-embedded fonts (PDFBox & iText)

Good morning.

I'm currently using PDFBox to build documents for the company I'm working for, and I need to print strings with generic character, also non in the WinAnsiEncoding range (e.g. "ł").

And I shouldn't embed fonts in the PDF documents.

If I use the internal PDFBox fonts (e.g. PDType1Font.HELVETICA) apparently no fonts are than embedded in the document.
So I assume that the document, when displayed, refers to Fonts present in the PC (Arial?); nevertheless PDPageContentStream.showText() throws an IllegalArgumentException for such "special" characters.

Using iText I could use the following call:
   Font myFont = com.itextpdf.text.FontFactory.getFont(name, size, style, color);
Using variable "myFont", now I can refer to the font with no font embedding, and I can use also non-WinAnsiEncoding characters.


Is there any way or workaround in PDFBox to generate a file with no embedded files and with "special" characters?

If not, will it be possible in one of the next PDFBox releases?


Thank you very much in advance,
Fabio Vassallo


Fabio Vassallo
Product Development (CIS)

[cid:image001.png@01D18B3E.92F52E70]
Würth Phoenix S.r.l.
via Kravogl 4, 39100 Bolzano
T: +39 0471 564 116
F: +39 0471 564 122
Website<http://www.wuerth-phoenix.com/> | e-Mail<ma...@wuerth-phoenix.com> | Map<https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.33141,15z/data=!4m2!3m1!1s0x0:0x98a5db69edb2a02?hl=en>

[twitter-2]<https://twitter.com/WuerthPhoenix>  [wordpress-2] <http://www.neteye-blog.com/>   [linkedin] <https://www.linkedin.com/company/wuerth-phoenix>   [youtube] <https://www.youtube.com/user/WuerthPhoenix>   [http://feng-shui-web.net/blog2/wp-content/uploads/2016/02/xing-icon.png] <https://www.xing.com/companies/w%C3%BCrthphoenixsrl>   [facebook] <https://www.facebook.com/wuerthphoenix>


RE: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by "Vassallo, Fabio" <Fa...@wuerth-phoenix.com>.
Dear Tilman.

I won't be able to go on with this issue today, and then I'll be on vacation until Apr 26th.

Thank you very much for your help, so far.

Frohe Ostern,
Fabio


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 1:58 PM
To: users@pdfbox.apache.org
Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Am 14.04.2017 um 12:17 schrieb Vassallo, Fabio:
> Tilman.
>
> Using embedSubset to false I get another problem.
>
> The instruction
>      pageResources.getFont(fontName);
> issues following warning:
> Apr 14, 2017 12:08:18 PM org.apache.pdfbox.pdmodel.font.PDCIDFontType2 
> <init>
> INFO: OpenType Layout tables used in font ArialMT are not implemented 
> in PDFBox and will be ignored

That is harmless. That's why it is just an INFO.

>
> And then the font isn't deleted from the file (but the code runs without any error/exception)...
> pdFont.getName() is "ArialMT", and it contains the COSName with key "FontFile2"

Then it would mean that something is wrong with the FontFile deletion code (although it looks good to me). I suggest you trace at "fontNameSet.add(name);" and at "RemoveItem" to see whether this is really reached.

Tilman

>
>
> 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 10:55 AM
> To: users@pdfbox.apache.org
> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>
> 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
>
>
> ---------------------------------------------------------------------
> 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


Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 14.04.2017 um 12:17 schrieb Vassallo, Fabio:
> Tilman.
>
> Using embedSubset to false I get another problem.
>
> The instruction
>      pageResources.getFont(fontName);
> issues following warning:
> Apr 14, 2017 12:08:18 PM org.apache.pdfbox.pdmodel.font.PDCIDFontType2 <init>
> INFO: OpenType Layout tables used in font ArialMT are not implemented in PDFBox and will be ignored

That is harmless. That's why it is just an INFO.

>
> And then the font isn't deleted from the file (but the code runs without any error/exception)...
> pdFont.getName() is "ArialMT", and it contains the COSName with key "FontFile2"

Then it would mean that something is wrong with the FontFile deletion 
code (although it looks good to me). I suggest you trace at 
"fontNameSet.add(name);" and at "RemoveItem" to see whether this is 
really reached.

Tilman

>
>
> 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 10:55 AM
> To: users@pdfbox.apache.org
> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>
> 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
>
>
> ---------------------------------------------------------------------
> 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


RE: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by "Vassallo, Fabio" <Fa...@wuerth-phoenix.com>.
Tilman.

Using embedSubset to false I get another problem.

The instruction
    pageResources.getFont(fontName);
issues following warning:
Apr 14, 2017 12:08:18 PM org.apache.pdfbox.pdmodel.font.PDCIDFontType2 <init>
INFO: OpenType Layout tables used in font ArialMT are not implemented in PDFBox and will be ignored

And then the font isn't deleted from the file (but the code runs without any error/exception)...
pdFont.getName() is "ArialMT", and it contains the COSName with key "FontFile2"


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 10:55 AM
To: users@pdfbox.apache.org
Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)

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


Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by Tilman Hausherr <TH...@t-online.de>.
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


RE: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by "Vassallo, Fabio" <Fa...@wuerth-phoenix.com>.
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.

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


Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by Tilman Hausherr <TH...@t-online.de>.
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


RE: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by "Vassallo, Fabio" <Fa...@wuerth-phoenix.com>.
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)


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: Wednesday, April 12, 2017 6:56 PM
To: users@pdfbox.apache.org
Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Am 12.04.2017 um 08:57 schrieb Vassallo, Fabio:
> Dear Tilman.
> I tried to remove the font file item from the font descriptor, but 
> apparently this has no effect in the generated file
>
>          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);
>          }

Your code looks good. But did you save the file first, reloaded it and THEN did this, and then resaved the file? I'm not sure if I mentioned this, if not, sorry.

To get the fonts for each page, get your PDPage objects, from the the resources, from there the font names, then get the fonts through their names.

Tilman


> 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: Thursday, April 6, 2017 11:04 PM
> To: users@pdfbox.apache.org
> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>
> Am 06.04.2017 um 13:37 schrieb Vassallo, Fabio:
>> Thank you for you answer, Tilman.
>>
>> As I would like to try to remove the embedded fonts from the PDF file, Is it possible to do it using a PDFBox code?
> Yes; from a PDFont object, then get the font descriptor, then can call
> .getCOSObject() on it and then manipulate from there, i.e. remove FontFile / FontFile2 / FontFile3 from the font descriptor.
>
> Tilman
>
>> Fabio
>>
>>> It might be possible to create your own different encoding as 
>>> described in page 264 of the PDF specification, and delete the 
>>> embedded font later. I haven't tested it and won't do it, and here's
>>> why: you should embed your fonts. Not embedding might result in 
>>> weird effects with some viewers, e.g. getting different glyphs, 
>>> squares or nothing at all. So it would be several hours of work to 
>>> create a bad PDF file with some code that is hard to understand.
>>>
>>> Are you aware that you can embed subsets? These are much smaller 
>>> than full fonts. Use PDType0Font.load().
>>> Tilman
>> 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: Tuesday, April 4, 2017 6:08 PM
>> To: users@pdfbox.apache.org
>> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>>
>> See my answer from 10.3.2017.
>>
>> Tilman
>>
>> Am 04.04.2017 um 12:01 schrieb Vassallo, Fabio:
>>> Good morning.
>>>
>>> I'm currently using PDFBox to build documents for the company I’m 
>>> working for, and I need to print strings with generic character, 
>>> also non in the WinAnsiEncoding range (e.g. “ł”).
>>>
>>> And I shouldn’t embed fonts in the PDF documents.
>>>
>>> If I use the internal PDFBox fonts (e.g. PDType1Font.HELVETICA) 
>>> apparently no fonts are than embedded in the document.
>>>
>>> So I assume that the document, when displayed, refers to Fonts 
>>> present in the PC (Arial?); nevertheless
>>> PDPageContentStream.showText() throws an IllegalArgumentException for such “special” characters.
>>>
>>> Using iText I could use the following call:
>>>
>>> *Font myFont = com.itextpdf.text.FontFactory.getFont(name, size, 
>>> style, color);*
>>>
>>> Using variable “myFont”, now I can refer to the font with no font 
>>> embedding, and I can use also non-WinAnsiEncoding characters.
>>>
>>> Is there any way or workaround in PDFBox to generate a file with no 
>>> embedded files and with “special” characters?
>>>
>>> If not, will it be possible in one of the next PDFBox releases?
>>>
>>> Thank you very much in advance,
>>>
>>> Fabio Vassallo
>>>
>>> *Fabio Vassallo*
>>> Product Development (CIS)
>>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDiv
>>> i
>>> d
>>> erLine.png
>>>
>>> cid:image001.png@01D18B3E.92F52E70
>>>
>>> Würth Phoenix S.r.l.
>>> via Kravogl 4, 39100 Bolzano
>>>
>>> T: +39 0471 564 116
>>>
>>> F: +39 0471 564 122
>>>
>>> Website <http://www.wuerth-phoenix.com/>| e-Mail 
>>> <ma...@wuerth-phoenix.com>| Map 
>>> <https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.
>>> 33141,15z/data=%214m2%213m1%211s0x0:0x98a5db69edb2a02?hl=en>
>>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDiv
>>> i
>>> d
>>> erLine.png
>>>
>>> twitter-2 <https://twitter.com/WuerthPhoenix>wordpress-2
>>> <http://www.neteye-blog.com/>linkedin
>>> <https://www.linkedin.com/company/wuerth-phoenix>youtube
>>> <https://www.youtube.com/user/WuerthPhoenix>http://feng-shui-web.net
>>> / b log2/wp-content/uploads/2016/02/xing-icon.png
>>> <https://www.xing.com/companies/w%C3%BCrthphoenixsrl>facebook
>>> <https://www.facebook.com/wuerthphoenix>
>>>
>> ---------------------------------------------------------------------
>> 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
>


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


Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 12.04.2017 um 08:57 schrieb Vassallo, Fabio:
> Dear Tilman.
> I tried to remove the font file item from the font descriptor, but apparently this has no effect in the generated file
>
>          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);
>          }

Your code looks good. But did you save the file first, reloaded it and 
THEN did this, and then resaved the file? I'm not sure if I mentioned 
this, if not, sorry.

To get the fonts for each page, get your PDPage objects, from the the 
resources, from there the font names, then get the fonts through their 
names.

Tilman


> 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: Thursday, April 6, 2017 11:04 PM
> To: users@pdfbox.apache.org
> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>
> Am 06.04.2017 um 13:37 schrieb Vassallo, Fabio:
>> Thank you for you answer, Tilman.
>>
>> As I would like to try to remove the embedded fonts from the PDF file, Is it possible to do it using a PDFBox code?
> Yes; from a PDFont object, then get the font descriptor, then can call
> .getCOSObject() on it and then manipulate from there, i.e. remove FontFile / FontFile2 / FontFile3 from the font descriptor.
>
> Tilman
>
>> Fabio
>>
>>> It might be possible to create your own different encoding as
>>> described in page 264 of the PDF specification, and delete the
>>> embedded font later. I haven't tested it and won't do it, and here's
>>> why: you should embed your fonts. Not embedding might result in weird
>>> effects with some viewers, e.g. getting different glyphs, squares or
>>> nothing at all. So it would be several hours of work to create a bad
>>> PDF file with some code that is hard to understand.
>>>
>>> Are you aware that you can embed subsets? These are much smaller than
>>> full fonts. Use PDType0Font.load().
>>> Tilman
>> 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: Tuesday, April 4, 2017 6:08 PM
>> To: users@pdfbox.apache.org
>> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>>
>> See my answer from 10.3.2017.
>>
>> Tilman
>>
>> Am 04.04.2017 um 12:01 schrieb Vassallo, Fabio:
>>> Good morning.
>>>
>>> I'm currently using PDFBox to build documents for the company I\u2019m
>>> working for, and I need to print strings with generic character, also
>>> non in the WinAnsiEncoding range (e.g. \u201c\u0142\u201d).
>>>
>>> And I shouldn\u2019t embed fonts in the PDF documents.
>>>
>>> If I use the internal PDFBox fonts (e.g. PDType1Font.HELVETICA)
>>> apparently no fonts are than embedded in the document.
>>>
>>> So I assume that the document, when displayed, refers to Fonts
>>> present in the PC (Arial?); nevertheless
>>> PDPageContentStream.showText() throws an IllegalArgumentException for such \u201cspecial\u201d characters.
>>>
>>> Using iText I could use the following call:
>>>
>>> *Font myFont = com.itextpdf.text.FontFactory.getFont(name, size,
>>> style, color);*
>>>
>>> Using variable \u201cmyFont\u201d, now I can refer to the font with no font
>>> embedding, and I can use also non-WinAnsiEncoding characters.
>>>
>>> Is there any way or workaround in PDFBox to generate a file with no
>>> embedded files and with \u201cspecial\u201d characters?
>>>
>>> If not, will it be possible in one of the next PDFBox releases?
>>>
>>> Thank you very much in advance,
>>>
>>> Fabio Vassallo
>>>
>>> *Fabio Vassallo*
>>> Product Development (CIS)
>>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivi
>>> d
>>> erLine.png
>>>
>>> cid:image001.png@01D18B3E.92F52E70
>>>
>>> W�rth Phoenix S.r.l.
>>> via Kravogl 4, 39100 Bolzano
>>>
>>> T: +39 0471 564 116
>>>
>>> F: +39 0471 564 122
>>>
>>> Website <http://www.wuerth-phoenix.com/>| e-Mail
>>> <ma...@wuerth-phoenix.com>| Map
>>> <https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.
>>> 33141,15z/data=%214m2%213m1%211s0x0:0x98a5db69edb2a02?hl=en>
>>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivi
>>> d
>>> erLine.png
>>>
>>> twitter-2 <https://twitter.com/WuerthPhoenix>wordpress-2
>>> <http://www.neteye-blog.com/>linkedin
>>> <https://www.linkedin.com/company/wuerth-phoenix>youtube
>>> <https://www.youtube.com/user/WuerthPhoenix>http://feng-shui-web.net/
>>> b log2/wp-content/uploads/2016/02/xing-icon.png
>>> <https://www.xing.com/companies/w%C3%BCrthphoenixsrl>facebook
>>> <https://www.facebook.com/wuerthphoenix>
>>>
>> ---------------------------------------------------------------------
>> 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
>


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


RE: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by "Vassallo, Fabio" <Fa...@wuerth-phoenix.com>.
Dear Tilman.
I tried to remove the font file item from the font descriptor, but apparently this has no effect in the generated file

        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: Thursday, April 6, 2017 11:04 PM
To: users@pdfbox.apache.org
Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Am 06.04.2017 um 13:37 schrieb Vassallo, Fabio:
> Thank you for you answer, Tilman.
>
> As I would like to try to remove the embedded fonts from the PDF file, Is it possible to do it using a PDFBox code?

Yes; from a PDFont object, then get the font descriptor, then can call
.getCOSObject() on it and then manipulate from there, i.e. remove FontFile / FontFile2 / FontFile3 from the font descriptor.

Tilman

>
> Fabio
>
>> It might be possible to create your own different encoding as 
>> described in page 264 of the PDF specification, and delete the 
>> embedded font later. I haven't tested it and won't do it, and here's 
>> why: you should embed your fonts. Not embedding might result in weird 
>> effects with some viewers, e.g. getting different glyphs, squares or 
>> nothing at all. So it would be several hours of work to create a bad 
>> PDF file with some code that is hard to understand.
>>
>> Are you aware that you can embed subsets? These are much smaller than 
>> full fonts. Use PDType0Font.load().
>> Tilman
>
> 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: Tuesday, April 4, 2017 6:08 PM
> To: users@pdfbox.apache.org
> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>
> See my answer from 10.3.2017.
>
> Tilman
>
> Am 04.04.2017 um 12:01 schrieb Vassallo, Fabio:
>> Good morning.
>>
>> I'm currently using PDFBox to build documents for the company I’m 
>> working for, and I need to print strings with generic character, also 
>> non in the WinAnsiEncoding range (e.g. “ł”).
>>
>> And I shouldn’t embed fonts in the PDF documents.
>>
>> If I use the internal PDFBox fonts (e.g. PDType1Font.HELVETICA) 
>> apparently no fonts are than embedded in the document.
>>
>> So I assume that the document, when displayed, refers to Fonts 
>> present in the PC (Arial?); nevertheless 
>> PDPageContentStream.showText() throws an IllegalArgumentException for such “special” characters.
>>
>> Using iText I could use the following call:
>>
>> *Font myFont = com.itextpdf.text.FontFactory.getFont(name, size, 
>> style, color);*
>>
>> Using variable “myFont”, now I can refer to the font with no font 
>> embedding, and I can use also non-WinAnsiEncoding characters.
>>
>> Is there any way or workaround in PDFBox to generate a file with no 
>> embedded files and with “special” characters?
>>
>> If not, will it be possible in one of the next PDFBox releases?
>>
>> Thank you very much in advance,
>>
>> Fabio Vassallo
>>
>> *Fabio Vassallo*
>> Product Development (CIS)
>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivi
>> d
>> erLine.png
>>
>> cid:image001.png@01D18B3E.92F52E70
>>
>> Würth Phoenix S.r.l.
>> via Kravogl 4, 39100 Bolzano
>>
>> T: +39 0471 564 116
>>
>> F: +39 0471 564 122
>>
>> Website <http://www.wuerth-phoenix.com/>| e-Mail 
>> <ma...@wuerth-phoenix.com>| Map 
>> <https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.
>> 33141,15z/data=%214m2%213m1%211s0x0:0x98a5db69edb2a02?hl=en>
>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivi
>> d
>> erLine.png
>>
>> twitter-2 <https://twitter.com/WuerthPhoenix>wordpress-2
>> <http://www.neteye-blog.com/>linkedin
>> <https://www.linkedin.com/company/wuerth-phoenix>youtube
>> <https://www.youtube.com/user/WuerthPhoenix>http://feng-shui-web.net/
>> b log2/wp-content/uploads/2016/02/xing-icon.png
>> <https://www.xing.com/companies/w%C3%BCrthphoenixsrl>facebook
>> <https://www.facebook.com/wuerthphoenix>
>>
>
> ---------------------------------------------------------------------
> 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


Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 06.04.2017 um 13:37 schrieb Vassallo, Fabio:
> Thank you for you answer, Tilman.
>
> As I would like to try to remove the embedded fonts from the PDF file, Is it possible to do it using a PDFBox code?

Yes; from a PDFont object, then get the font descriptor, then can call 
.getCOSObject() on it and then manipulate from there, i.e. remove 
FontFile / FontFile2 / FontFile3 from the font descriptor.

Tilman

>
> Fabio
>
>> It might be possible to create your own different encoding as described
>> in page 264 of the PDF specification, and delete the embedded font
>> later. I haven't tested it and won't do it, and here's why: you should
>> embed your fonts. Not embedding might result in weird effects with some
>> viewers, e.g. getting different glyphs, squares or nothing at all. So it
>> would be several hours of work to create a bad PDF file with some code
>> that is hard to understand.
>>
>> Are you aware that you can embed subsets? These are much smaller than
>> full fonts. Use PDType0Font.load().
>> Tilman
>
> 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: Tuesday, April 4, 2017 6:08 PM
> To: users@pdfbox.apache.org
> Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)
>
> See my answer from 10.3.2017.
>
> Tilman
>
> Am 04.04.2017 um 12:01 schrieb Vassallo, Fabio:
>> Good morning.
>>
>> I'm currently using PDFBox to build documents for the company I\u2019m
>> working for, and I need to print strings with generic character, also
>> non in the WinAnsiEncoding range (e.g. \u201c\u0142\u201d).
>>
>> And I shouldn\u2019t embed fonts in the PDF documents.
>>
>> If I use the internal PDFBox fonts (e.g. PDType1Font.HELVETICA)
>> apparently no fonts are than embedded in the document.
>>
>> So I assume that the document, when displayed, refers to Fonts present
>> in the PC (Arial?); nevertheless PDPageContentStream.showText() throws
>> an IllegalArgumentException for such \u201cspecial\u201d characters.
>>
>> Using iText I could use the following call:
>>
>> *Font myFont = com.itextpdf.text.FontFactory.getFont(name, size,
>> style, color);*
>>
>> Using variable \u201cmyFont\u201d, now I can refer to the font with no font
>> embedding, and I can use also non-WinAnsiEncoding characters.
>>
>> Is there any way or workaround in PDFBox to generate a file with no
>> embedded files and with \u201cspecial\u201d characters?
>>
>> If not, will it be possible in one of the next PDFBox releases?
>>
>> Thank you very much in advance,
>>
>> Fabio Vassallo
>>
>> *Fabio Vassallo*
>> Product Development (CIS)
>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivid
>> erLine.png
>>
>> cid:image001.png@01D18B3E.92F52E70
>>
>> W�rth Phoenix S.r.l.
>> via Kravogl 4, 39100 Bolzano
>>
>> T: +39 0471 564 116
>>
>> F: +39 0471 564 122
>>
>> Website <http://www.wuerth-phoenix.com/>| e-Mail
>> <ma...@wuerth-phoenix.com>| Map
>> <https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.
>> 33141,15z/data=%214m2%213m1%211s0x0:0x98a5db69edb2a02?hl=en>
>> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivid
>> erLine.png
>>
>> twitter-2 <https://twitter.com/WuerthPhoenix>wordpress-2
>> <http://www.neteye-blog.com/>linkedin
>> <https://www.linkedin.com/company/wuerth-phoenix>youtube
>> <https://www.youtube.com/user/WuerthPhoenix>http://feng-shui-web.net/b
>> log2/wp-content/uploads/2016/02/xing-icon.png
>> <https://www.xing.com/companies/w%C3%BCrthphoenixsrl>facebook
>> <https://www.facebook.com/wuerthphoenix>
>>
>
> ---------------------------------------------------------------------
> 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


RE: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by "Vassallo, Fabio" <Fa...@wuerth-phoenix.com>.
Thank you for you answer, Tilman.

As I would like to try to remove the embedded fonts from the PDF file, Is it possible to do it using a PDFBox code?

Fabio

> It might be possible to create your own different encoding as described 
> in page 264 of the PDF specification, and delete the embedded font 
> later. I haven't tested it and won't do it, and here's why: you should 
> embed your fonts. Not embedding might result in weird effects with some 
> viewers, e.g. getting different glyphs, squares or nothing at all. So it 
> would be several hours of work to create a bad PDF file with some code 
> that is hard to understand.
> 
> Are you aware that you can embed subsets? These are much smaller than 
> full fonts. Use PDType0Font.load().
> Tilman


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: Tuesday, April 4, 2017 6:08 PM
To: users@pdfbox.apache.org
Subject: Re: Embedded vs. non-embedded fonts (PDFBox & iText)

See my answer from 10.3.2017.

Tilman

Am 04.04.2017 um 12:01 schrieb Vassallo, Fabio:
>
> Good morning.
>
> I'm currently using PDFBox to build documents for the company I’m 
> working for, and I need to print strings with generic character, also 
> non in the WinAnsiEncoding range (e.g. “ł”).
>
> And I shouldn’t embed fonts in the PDF documents.
>
> If I use the internal PDFBox fonts (e.g. PDType1Font.HELVETICA) 
> apparently no fonts are than embedded in the document.
>
> So I assume that the document, when displayed, refers to Fonts present 
> in the PC (Arial?); nevertheless PDPageContentStream.showText() throws 
> an IllegalArgumentException for such “special” characters.
>
> Using iText I could use the following call:
>
> *Font myFont = com.itextpdf.text.FontFactory.getFont(name, size, 
> style, color);*
>
> Using variable “myFont”, now I can refer to the font with no font 
> embedding, and I can use also non-WinAnsiEncoding characters.
>
> Is there any way or workaround in PDFBox to generate a file with no 
> embedded files and with “special” characters?
>
> If not, will it be possible in one of the next PDFBox releases?
>
> Thank you very much in advance,
>
> Fabio Vassallo
>
> *Fabio Vassallo*
> Product Development (CIS)
> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivid
> erLine.png
>
> cid:image001.png@01D18B3E.92F52E70
>
> Würth Phoenix S.r.l.
> via Kravogl 4, 39100 Bolzano
>
> T: +39 0471 564 116
>
> F: +39 0471 564 122
>
> Website <http://www.wuerth-phoenix.com/>| e-Mail 
> <ma...@wuerth-phoenix.com>| Map 
> <https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.
> 33141,15z/data=%214m2%213m1%211s0x0:0x98a5db69edb2a02?hl=en>
> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDivid
> erLine.png
>
> twitter-2 <https://twitter.com/WuerthPhoenix>wordpress-2
> <http://www.neteye-blog.com/>linkedin
> <https://www.linkedin.com/company/wuerth-phoenix>youtube
> <https://www.youtube.com/user/WuerthPhoenix>http://feng-shui-web.net/b
> log2/wp-content/uploads/2016/02/xing-icon.png
> <https://www.xing.com/companies/w%C3%BCrthphoenixsrl>facebook
> <https://www.facebook.com/wuerthphoenix>
>


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


Re: Embedded vs. non-embedded fonts (PDFBox & iText)

Posted by Tilman Hausherr <TH...@t-online.de>.
See my answer from 10.3.2017.

Tilman

Am 04.04.2017 um 12:01 schrieb Vassallo, Fabio:
>
> Good morning.
>
> I'm currently using PDFBox to build documents for the company I\u2019m 
> working for, and I need to print strings with generic character, also 
> non in the WinAnsiEncoding range (e.g. \u201c\u0142\u201d).
>
> And I shouldn\u2019t embed fonts in the PDF documents.
>
> If I use the internal PDFBox fonts (e.g. PDType1Font.HELVETICA) 
> apparently no fonts are than embedded in the document.
>
> So I assume that the document, when displayed, refers to Fonts present 
> in the PC (Arial?); nevertheless PDPageContentStream.showText() throws 
> an IllegalArgumentException for such \u201cspecial\u201d characters.
>
> Using iText I could use the following call:
>
> *Font myFont = com.itextpdf.text.FontFactory.getFont(name, size, 
> style, color);*
>
> Using variable \u201cmyFont\u201d, now I can refer to the font with no font 
> embedding, and I can use also non-WinAnsiEncoding characters.
>
> Is there any way or workaround in PDFBox to generate a file with no 
> embedded files and with \u201cspecial\u201d characters?
>
> If not, will it be possible in one of the next PDFBox releases?
>
> Thank you very much in advance,
>
> Fabio Vassallo
>
> *Fabio Vassallo*
> Product Development (CIS)
> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDividerLine.png
>
> cid:image001.png@01D18B3E.92F52E70
>
> W�rth Phoenix S.r.l.
> via Kravogl 4, 39100 Bolzano
>
> T: +39 0471 564 116
>
> F: +39 0471 564 122
>
> Website <http://www.wuerth-phoenix.com/>| e-Mail 
> <ma...@wuerth-phoenix.com>| Map 
> <https://www.google.de/maps/place/Wuerth+Phoenix+S.R.L./@46.474192,11.33141,15z/data=%214m2%213m1%211s0x0:0x98a5db69edb2a02?hl=en>
> http://hafisherhomes.com/wp-content/themes/hughfisher/img/galleryDividerLine.png
>
> twitter-2 <https://twitter.com/WuerthPhoenix>wordpress-2 
> <http://www.neteye-blog.com/>linkedin 
> <https://www.linkedin.com/company/wuerth-phoenix>youtube 
> <https://www.youtube.com/user/WuerthPhoenix>http://feng-shui-web.net/blog2/wp-content/uploads/2016/02/xing-icon.png 
> <https://www.xing.com/companies/w%C3%BCrthphoenixsrl>facebook 
> <https://www.facebook.com/wuerthphoenix>
>