Сложность встраивания профиля ICC в PDF с помощью PDFBox, iText и GhostscripJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Сложность встраивания профиля ICC в PDF с помощью PDFBox, iText и Ghostscrip

Сообщение Anonymous »

Я работал над встраиванием профиля ICC (AdobeRGB1998.icc) в файл PDF. Несмотря на многочисленные попытки с использованием различных инструментов, мне не удалось отобразить профиль ICC в метаданных.
Я хочу добиться отображения тегов профиля ICC в метаданных, как показано на следующем снимке экрана:
Изображение

Я потратил бесчисленное количество часов и попробовал следующие подходы:
PDFBox
Java Code

Код: Выделить всё

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();
}
}

iText
Код Java

Код: Выделить всё

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();
}
}
}

GhostScript
Команда

Код: Выделить всё

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

Проблема:
Несмотря на сообщения об успешном внедрении, профиль ICC не обнаруживается ExifTool:

Код: Выделить всё

exiftool.exe -G1 "C:/PDFWorkFlow/output_done_PDFBox.pdf"
Что может быть причиной неправильного внедрения профиля ICC в PDF-файл? Существуют ли какие-либо дополнительные шаги или альтернативные методы, с помощью которых я могу попробовать обеспечить встраивание и обнаружение профиля ICC?
Будем очень признательны за любую информацию или предложения. Спасибо!

Подробнее здесь: https://stackoverflow.com/questions/793 ... ghostscrip
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Сложность встраивания профиля ICC в PDF с помощью PDFBox, iText и Ghostscrip
    Anonymous » » в форуме JAVA
    0 Ответы
    32 Просмотры
    Последнее сообщение Anonymous
  • Сложность встраивания профиля ICC в PDF с помощью PDFBox, iText и Ghostscrip
    Anonymous » » в форуме JAVA
    0 Ответы
    23 Просмотры
    Последнее сообщение Anonymous
  • Конвертируйте JPG из sRGB в CMYK с помощью профиля ICC в Python
    Anonymous » » в форуме Python
    0 Ответы
    31 Просмотры
    Последнее сообщение Anonymous
  • Конвертируйте JPG из sRGB в CMYK с помощью профиля ICC в Python
    Anonymous » » в форуме Python
    0 Ответы
    24 Просмотры
    Последнее сообщение Anonymous
  • Преобразование цветов C# из CMYK в Cielab или RGB в Cielab с использованием профиля ICC
    Anonymous » » в форуме C#
    0 Ответы
    32 Просмотры
    Последнее сообщение Anonymous

Вернуться в «JAVA»