PDFBox
Java Code
Code: Select all
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class EmbedICCWithPDFBox {
public static void main(String[] args) {
if (args.length != 3) {
System.err.println("Usage: java EmbedICCWithPDFBox
");
return;
}
String pdfPath = args[0];
String outputPdfPath = args[1];
String iccPath = args[2];
try {
embedICCProfile(pdfPath, outputPdfPath, iccPath);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void embedICCProfile(String pdfPath, String outputPdfPath, String iccPath) throws IOException {
PDDocument document = PDDocument.load(new File(pdfPath));
try (FileInputStream iccStream = new FileInputStream(iccPath)) {
PDStream iccPDStream = new PDStream(document, iccStream);
iccPDStream.addCompression();
PDOutputIntent outputIntent = new PDOutputIntent(document, iccPDStream);
outputIntent.setInfo("sRGB IEC61966-2.1");
outputIntent.setOutputCondition("sRGB IEC61966-2.1");
outputIntent.setOutputConditionIdentifier("sRGB IEC61966-2.1");
outputIntent.setRegistryName("http://www.color.org");
document.getDocumentCatalog().addOutputIntent(outputIntent);
System.out.println("ICC profile embedded successfully.");
}
document.save(outputPdfPath);
document.close();
}
}
Java-Code
Code: Select all
import com.itextpdf.kernel.pdf.*;
import java.io.FileInputStream;
import java.io.IOException;
public class EmbedICCWithIText {
public static void embedICCProfile(String pdfPath, String outputPdfPath, String iccPath) throws IOException {
PdfDocument pdfDoc = new PdfDocument(new PdfReader(pdfPath), new PdfWriter(outputPdfPath));
try (FileInputStream iccStream = new FileInputStream(iccPath)) {
byte[] iccProfileBytes = iccStream.readAllBytes();
PdfStream iccPdfStream = new PdfStream(iccProfileBytes);
iccPdfStream.put(PdfName.N, new PdfNumber(3));
iccPdfStream.put(PdfName.Length, new PdfNumber(iccProfileBytes.length));
iccPdfStream.put(PdfName.Filter, PdfName.FlateDecode);
PdfDictionary outputIntentDict = new PdfDictionary();
outputIntentDict.put(PdfName.Type, PdfName.OutputIntent);
outputIntentDict.put(PdfName.S, PdfName.GTS_PDFA1);
outputIntentDict.put(PdfName.OutputConditionIdentifier, new PdfString("AdobeRGB (1998)"));
outputIntentDict.put(PdfName.OutputCondition, new PdfString("Adobe RGB (1998)"));
outputIntentDict.put(PdfName.Info, new PdfString("Adobe RGB (1998)"));
outputIntentDict.put(PdfName.DestOutputProfile, iccPdfStream);
PdfArray outputIntents = new PdfArray();
outputIntents.add(outputIntentDict);
pdfDoc.getCatalog().put(PdfName.OutputIntents, outputIntents);
System.out.println("ICC profile embedded successfully.");
}
pdfDoc.close();
}
public static void main(String[] args) {
if (args.length != 3) {
System.err.println("Usage: java EmbedICCWithIText
");
return;
}
String pdfPath = args[0];
String outputPdfPath = args[1];
String iccPath = args[2];
try {
embedICCProfile(pdfPath, outputPdfPath, iccPath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Befehl
Code: Select all
gswin64c.exe -o C:/ghost/output_done_Ghostscript.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sProcessColorModel=DeviceRGB -sOutputICCProfile=C:/ghost/AdobeRGB1998.icc -dEmbedAllFonts=true -dSubsetFonts=true -dMaxSubsetPct=100 -dPDFX=true -dCompatibilityLevel=1.4 C:/ghost/test1_no_xref.pdf
Trotz der gemeldeten erfolgreichen Einbettung wird das ICC-Profil von ExifTool nicht erkannt:
Code: Select all
exiftool.exe -G1 "C:/PDFWorkFlow/output_done_PDFBox.pdf"
Für Einblicke oder Vorschläge wäre ich sehr dankbar. Danke!