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:[email protected]]
Sent: Friday, April 14, 2017 10:55 AM
To: [email protected]
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:[email protected]]
Sent: Friday, April 14, 2017 9:52 AM
To: [email protected]
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: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]