You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2016/06/21 18:16:58 UTC

[jira] [Commented] (PDFBOX-3243) Lost font after merge

    [ https://issues.apache.org/jira/browse/PDFBOX-3243?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15342366#comment-15342366 ] 

Tilman Hausherr commented on PDFBOX-3243:
-----------------------------------------

I first tried this:
{code}
for (int p = 0; p < doc.getNumberOfPages(); ++p)
{
    PDPage page = doc.getPage(p);
    PDResources resources = page.getResources();
    for (COSName fontName : resources.getFontNames())
    {
        PDFont font = resources.getFont(fontName);
        if (font.willBeSubset())
        {
            throw new IllegalStateException("this document has fonts that must be subsetted, please save and reload");
        }
    }
}
{code}
it doesn't work... the reason is that the PDFont object returned isn't the one used by the content stream, although the COSObject is the same. The PDFont object isn't taken from the cache, it is recreated from the COSObject in {{PDFontFactory.createFont(dict)}}.

2nd method:
{code}
if (!doc.getFontsToSubset().isEmpty())
{
    throw new IllegalStateException("this document has fonts that must be subsetted, please save and reload");
}
{code}
This is even simpler, but doesn't compile because {{getFontsToSubset()}} is not public. We could make it public, or create a new public method {{hasFontsToSubset()}}, or create some method that subsets all the fonts and has this as body
{code}
// subset designated fonts
for (PDFont font : fontsToSubset)
{
    font.subset();
}
fontsToSubset.clear();
{code}

> Lost font after merge
> ---------------------
>
>                 Key: PDFBOX-3243
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3243
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.0.0, 2.0.1, 2.1.0
>         Environment: Windows 7 Professional, 32 bit
>            Reporter: Matthias Braun
>
> Hi and thanks a lot for your great library!
> I've noticed that after I merge two or more PDFs that the font of the merged PDF differs from that of the input PDFs.
> I've created a minimal project that lets you reproduce the bug:
> https://github.com/mb720/PdfMerging
> When you start the program using "./gradlew run", it will create three PDFs in "~/Desktop/": Two simple PDFs with one page of text and a third one that is created by merging the first two PDFs.
> In the project the font I use is DroidSans.ttf. The version of PDFBox is 2.0.0-RC3.
> For reasons I don't know the problem does not occur on my Linux Mint Debian Edition 64 bit.
> Thanks a lot in advance,
> Matthias



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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