All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lowagie.text.pdf.UnembedFontPdfSmartCopy Maven / Gradle / Ivy

Go to download

Itext is a java library to create and manipulate PDFs. This is a fork of version 2.1.7 the last MPL/LGPL version. It's focused basically on mantain compatibility with newer bouncycastle releases and small bugfixes.

There is a newer version: 2.2.2
Show newest version
package com.lowagie.text.pdf;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;

/**
 * Makes a copy of a PDF, unembedding all embedded fonts. All font headers and descriptors are preserved and only the font file is removed.
 */
public class UnembedFontPdfSmartCopy extends PdfSmartCopy {
	
	public UnembedFontPdfSmartCopy(Document document, OutputStream os)
			throws DocumentException {
		super(document, os);
	}

	protected PdfDictionary copyDictionary(PdfDictionary in)
        throws IOException, BadPdfFormatException {

		PdfDictionary out = new PdfDictionary();
		PdfReader.getPdfObjectRelease(in.get(PdfName.TYPE));

		for (Iterator it = in.getKeys().iterator(); it.hasNext();) {
			PdfName key = (PdfName) it.next();
			PdfObject value = in.get(key);

            if ((PdfName.FONTFILE.equals(key)
                    || PdfName.FONTFILE2.equals(key)
                    || PdfName.FONTFILE3.equals(key))
                && !isFontSubset(PdfReader.getFontNameFromDescriptor(in)))
            {
                continue;
            }
            else
            {
                out.put(key, copyObject(value));
            }
		}

		return out;
	}

	private static boolean isFontSubset(String fontName) {
		return fontName != null && fontName.length() >= 8 && fontName.charAt(6) == '+';
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy