Quote from: 
http://www.nabble.com/Re%3A-contribution%3A-FontReplacingPdfSmartCopy%3A-duplicate-TTF-font-subset-merging-and-replacement-%28was%3A-How-to-remove-embedded-fonts-from-a-pdf-document%29-p16001839.html

Paulo Soares wrote:
> 
>  The bottom line is that I'll include your code in iText and hope that it
> will be improved later, by you or someone else.
> 
> Paulo
> 

Hello, 

Is there any chance that FontReplacingPdfSmartCopy
(http://www.nabble.com/How-to-remove-embedded-fonts-from-a-pdf-document-to14033717.html#a15203186)
 gets included in the iText main distribution? I contributed the patch over
a year ago (Jan 31, 2008) and you replied Mar 12, 2008 that you can include
it in iText.

I believe that there is a demand for this feature since I've been receiving
some questions about the contribution by email. I hope every iText user
could benefit from this feature. I believe that font replacement is a very
typical use case in pdf manipulation.

I can sign a Contributor agreement if that's a problem in including this
contribution.

Someone requested a change by email to be able to replace embedded fonts
with document fonts (type1) and that was possible by making a small change:

Here's an example (Junit4 test method) for replacing ComicSansMS with
Helvetica:


    @Test
    public void testDocFontReplace() throws Exception {
        FontReplacingPdfSmartCopy.logLevel=Level.INFO;
         PdfConcator pdfConcator=new PdfConcator();
         pdfConcator.setFonts(new
BaseFont[]{BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.NOT_EMBEDDED)});
         Map fontNameMapping = new HashMap();
         fontNameMapping.put("ComicSansMS", "Helvetica");
         pdfConcator.setFontNameMapping(fontNameMapping);
         pdfConcator.concat(Collections.singleton(new File("test1.pdf")),
new File("docfont-test2.pdf"));
    }


I had to make a small modification in FontReplacingPdfSmartCopy's setFonts
method:

    public void setFonts(BaseFont[] fonts) {
        this.fontmap = new HashMap(); //new HashMap<String, BaseFont>();
        for (int i = 0; i < fonts.length; i++) {
            switch (fonts[i].getFontType()) {
            case BaseFont.FONT_TYPE_T3:
            case BaseFont.FONT_TYPE_T1:
            case BaseFont.FONT_TYPE_TT:
                if (BaseFont.WINANSI.equals(fonts[i].getEncoding())) {
                    if (fonts[i].getFontType()==BaseFont.FONT_TYPE_T1 ||
Arrays.asList(fonts[i].getCodePagesSupported())
                            .contains("1252 Latin 1")) {
                        if (!fontmap.containsKey(fonts[i]
                                .getPostscriptFontName())) {
                            logger.log(logLevel, "Adding font {0}",
fonts[i].getPostscriptFontName());
                            fontmap.put(fonts[i].getPostscriptFontName(),
                                    fonts[i]);
                        } else {
                            logger.log(logLevel, "Discarding duplicate entry
for font {0}", fonts[i].getPostscriptFontName());
                        }
                    } else {
                        logger.log(logLevel, "Discarding font {0}. It
doesn't support Cp1252/ISO-8859-1/Latin1/WinAnsiEncoding.",
fonts[i].getPostscriptFontName());
                    }
                }
                break;
            default:
                logger.log(logLevel, "Discarding unsupported type of font
{0}. Only single byte TTF/OTF fonts are supported by now.",
fonts[i].getPostscriptFontName());
            }
        }
    }



Regards, 

Lari

-- 
View this message in context: 
http://www.nabble.com/How-to-remove-embedded-fonts-from-a-pdf-document-tp14033717p22753844.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to