Importing vector graphics from Adobe Illustrator into PDF using iText without color distortion issues

I’m having trouble with vector graphics in my PDF generation project using iText for Java. The colors get messed up when I try to add SVG files to my documents.

I need to create PDFs that include vector graphics along with text content. I’m using iText library which works great for most things. My graphics were made in Adobe Illustrator originally, but since iText doesn’t support AI files directly, I converted them to SVG format. Unfortunately, the SVG rendering has problems where some colors don’t show up correctly.

Here’s my test code that shows the problem:

Maven setup:

<dependencies>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itext-core</artifactId>
        <version>9.0.0</version>
        <type>pom</type>
    </dependency>
</dependencies>

Java implementation:

package com.example.pdftest;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.properties.HorizontalAlignment;
import com.itextpdf.svg.converter.SvgConverter;
import java.io.FileInputStream;

public class PdfGenerator {
    public static void main(String[] args) throws Exception {
        String vectorFile = "C:\\graphics\\company_logo.svg";
        String resultFile = "C:\\output\\final_document.pdf";
        
        try (FileInputStream vectorStream = new FileInputStream(vectorFile)) {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(resultFile));
            Image vectorImage = SvgConverter.convertToImage(vectorStream, pdfDoc)
                .setWidth(150)
                .setHorizontalAlignment(HorizontalAlignment.CENTER);
            Paragraph content = new Paragraph("Document content here...").setFontSize(18);
            
            Document doc = new Document(pdfDoc);
            doc.add(vectorImage);
            doc.add(content);
            doc.close();
        }
    }
}

The output PDF has completely wrong colors compared to the original SVG. I’m thinking maybe I should try embedding the AI files directly as PDF components instead of converting to SVG first. Since AI files are basically PDF format, this might work better. I know tools like LaTeX can include PDF files as figures, so there should be a way to do this with iText too.

Is there a method to embed vector graphics directly without creating new pages? Or does anyone know how to fix the SVG color rendering issue?

Yeah, this color mess happens all the time. Manual PDF generation always causes these conversion headaches.

Stop wrestling with iText color profiles and SVG rendering - just automate everything. Set up a system that watches your AI files, converts them properly, and generates PDFs automatically.

I automate this exact thing. My workflow monitors a folder for AI files, runs proper color space conversions with headless design tools, then feeds clean data to PDF generators. No more manual file juggling or color mismatches.

You can build triggers that detect graphics changes, auto-regenerate PDFs with correct colors, and A/B test different export settings to find what works for your files.

Automation handles the tedious stuff - testing Illustrator export settings, managing conversions, ensuring consistent output. Plus you get logging so you know what went wrong when colors are still off.

This saved me hours every week vs manually tweaking export settings and rerunning Java code repeatedly.

Check out Latenode for this kind of automated pipeline: https://latenode.com

I hit this exact color issue a few years back when generating reports with vector logos.

SVG color problems usually stem from colorspace mismatches. Illustrator exports SVGs with different color profiles than iText expects.

Try this first - in Illustrator’s SVG Options, switch CSS Properties from “Style Attributes” to “Presentation Attributes”. Set Color Type to RGB, not HSL.

If that doesn’t fix it, ditch SVG completely. Export your AI file as PDF instead (File > Save As > Adobe PDF). Then use PdfDocument.copyPagesTo() to grab the graphics without creating a new page:

PdfDocument sourcePdf = new PdfDocument(new PdfReader("logo.pdf"));
PdfFormXObject template = sourcePdf.getFirstPage().copyAsFormXObject(pdfDoc);
Image vectorImage = new Image(template).scaleToFit(150, 150);

This keeps the original colors intact since you’re not converting anything. The PDF approach worked way better for us than wrestling with SVG rendering.

Also - if you stick with SVG, make sure your Maven dependency includes the svg module:

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>svg</artifactId>
    <version>9.0.0</version>
</dependency>