Skip to main content
Skip table of contents

Improved HTML to PDF/A

With the latest advancements in pdfHTML 5.0.3, you can now generate PDF/A files directly from HTML even more easily than before! With just a few lines of code, the PDF/A conformance level and document output intent can be set directly in the HtmlConverter (Java/.NET) properties, creating fully compliant PDF/A files that adhere to archival standards.

What changed?

In earlier iterations of iText, while it was certainly feasible to generate PDF/A files through pdfHTML, the process was more complex than required, as developers were tasked with manually crafting a PdfADocument (Java/.NET) instance to add into the pdfHTML conversion process.

In our latest release, however, we've streamlined this procedure significantly: Now, developers can effortlessly create PDF/A documents by merely adjusting a few parameters to define the PDF/A conformance level and output intent in the ConverterProperties (Java/.NET) object. The underlying object instantiation processes are now handled seamlessly in the background, sparing developers the burden of manually setting up these objects.

Code Examples:

Java
JAVA
package com.itextpdf.samples.sandbox.pdfhtml;

import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
import com.itextpdf.kernel.pdf.PdfOutputIntent;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class HtmlToPdfA3Convert {
    public static final String SRC = "./src/main/resources/pdfhtml/HtmlToPdfA3Convert/";
    public static final String DEST = "./target/sandbox/pdfhtml/HtmlToPdfA3Convert.pdf";

    public static void main(String[] args) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();

        new HtmlToPdfA3Convert().manipulatePdf(DEST);
    }

    public void manipulatePdf(String pdfDest) throws IOException {
        String htmlSource = SRC + "MixedContent.html";

        InputStream inputStream = new FileInputStream(SRC + "sRGB Color Space Profile.icm");

        ConverterProperties converterProperties = new ConverterProperties();
        converterProperties.setBaseUri(SRC);
        converterProperties.setPdfAConformanceLevel(PdfAConformanceLevel.PDF_A_3B);
        converterProperties.setDocumentOutputIntent(
                new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1",
                        inputStream));


        converterProperties.setFontProvider(new DefaultFontProvider(false, true, false));

        HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest), converterProperties);
    }
}
C#
C#
using System;
using System.IO;
using iText.Html2pdf;
using iText.Html2pdf.Resolver.Font;
using iText.Kernel.Pdf;
using static iText.Kernel.Pdf.PdfAConformanceLevel;

namespace iText.Samples.Sandbox.Pdfhtml 
{
    public class HtmlToPdfA3Convert 
    {
        public static readonly string SRC = "../../../resources/pdfhtml/HtmlToPdfA3Convert/";
        public static readonly string DEST = "results/sandbox/pdfhtml/HtmlToPdfA3Convert.pdf";

        public static void Main(String[] args) 
        {
            var file = new FileInfo(DEST);
            file.Directory.Create();
            
            new HtmlToPdfA3Convert().ManipulatePdf(DEST);
        }

        public void ManipulatePdf(String pdfDest) 
        {
            var htmlSource = SRC + "MixedContent.html";
            
            var inputStream = new FileStream(SRC + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            
            var converterProperties = new ConverterProperties();
            converterProperties.SetBaseUri(SRC);
            converterProperties.SetPdfAConformanceLevel(PDF_A_3B);
            converterProperties.SetDocumentOutputIntent(new PdfOutputIntent("Custom", "", "http://www.color.org",
            "sRGB IEC61966-2.1", inputStream));
            converterProperties.SetFontProvider(new DefaultFontProvider(false, true, false));
            
            HtmlConverter.ConvertToPdf(new FileStream(htmlSource, FileMode.Open, FileAccess.Read), new FileStream(pdfDest, FileMode.Create), converterProperties);
        }
    }
}

JavaScript errors detected

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

If this problem persists, please contact our support.