Skip to main content
Skip table of contents

iText Core: Support Type3 fonts reading for stamping mode

Background:

Type3 fonts are user-defined fonts in which arbitrary characters are mapped to custom glyphs. For instance, a character A can be mapped into a colored image representing a character A.

However, in more complex cases these mappings can represent graphics that do not directly correspond to actual glyphs. This presents a challenge in cases where mappings/glyph names are used to represent glyphs, or in cases where glyphs are redacted or extracted in order to be mapped to actual glyph names.

The scenarios where this can be problematic is when attempting to extract or redact text that uses a Type3 font, or trying to read fonts for stamping mode in which standard glyph names are used to identify glyphs.

In version 7.1.16 of iText 7 Core you can now read and re-save Type3 glyphs that have non-standard names. In addition, these fonts can now be modified without implications during stamping/append mode.

Code Snippet:

Below is a code example that demonstrates a cleanup operation involving text written using Type3 fonts

JAVA

JAVA
import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.StampingProperties;
import com.itextpdf.licensekey.LicenseKey;
import com.itextpdf.pdfcleanup.PdfCleanUpLocation;
import com.itextpdf.pdfcleanup.PdfCleanUpTool;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CleanupTest {
    
    public static void main(String[] args) throws IOException {
       
        //Load the license file to use cleanup features
        LicenseKey.loadLicenseFile("license.xml");
        
        StampingProperties properties = new StampingProperties();
        properties.useAppendMode();

        PdfDocument pdfDocument = new PdfDocument(new PdfReader("base.pdf"), new PdfWriter("cleanupResult.pdf"), properties);
        PdfAcroForm pdfAcroForm = PdfAcroForm.getAcroForm(pdfDocument, false);

        if (pdfAcroForm != null) {
            pdfAcroForm.flattenFields();
        }
       
        DeviceRgb color = (DeviceRgb) ColorConstants.BLACK;

        List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
        cleanUpLocations.add(new PdfCleanUpLocation(1, new Rectangle(10, 300, 600, 400), color));
        PdfCleanUpTool cleaner = new PdfCleanUpTool(pdfDocument, cleanUpLocations);

        cleaner.cleanUp();

        pdfDocument.close();
    }
}

C#

C#
using System.Collections.Generic;
using iText.Forms;
using iText.Kernel.Colors;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.License;
using iText.PdfCleanup;

namespace TYPE3TEST
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            //Load the license file to use cleanup features
            LicenseKey.LoadLicenseFile("license.xml");
         
            var properties = new StampingProperties();
         
            using (var pdfDocument =
                new PdfDocument(new PdfReader("base.pdf"),
                    new PdfWriter("cleanupResult.pdf"), properties))
            {

                var form = PdfAcroForm.GetAcroForm(pdfDocument, false);
                form?.FlattenFields();

                DeviceRgb color = (DeviceRgb) ColorConstants.BLACK;

                IList<PdfCleanUpLocation> cleanUpLocations = new List<PdfCleanUpLocation>();
                cleanUpLocations.Add(new PdfCleanUpLocation(1, new Rectangle(50, 50, 500, 800), color));
                PdfCleanUpTool cleaner = new PdfCleanUpTool(pdfDocument, cleanUpLocations);

                cleaner.CleanUp();
            }
        }
    }
}

Resources

Right-click the link below and select "Save link as..." to download

resources.zip

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.