PDFBox转换现有pdf

时间:2017-03-01 09:26:34

标签: pdf pdfbox color-space

问题: 我有一个现有的pdf,它有一些图像和文字。此pdf具有混合色彩空间RGB和CMYK。我想将其转换为单色空间pdf,最好转换为CMYK。

使用:PDFBox 2.0.4

PDFBox有PDPageContentStream,可用于在向现有pdf添加数据时更改添加颜色空间,如下所示:

    PDDocument document = PDDocument.load(myPdfWithMixColorSpace);
    PDPage pdPage = document.getPage(0);
    PDPageContentStream imageContentStream = new PDPageContentStream(document, page);

    imageContentStream.setNonStrokingColor(0, 0, 0, 255); // for cmyk color space

    imageContentStream.beginText();
    imageContentStream.setFont(PDType1Font.TIMES_ROMAN, 20.15f);
    imageContentStream.newLineAtOffset(13.55f, 50f);
    imageContentStream.showText("this is test");
    imageContentStream.endText();

    imageContentStream.close();  
    document.save("D:\\newPDF.pdf");
    document.close();

newPDF.pdf以CMYK颜色添加了文本,但我不想在现有的pdf上添加CMYK颜色的文本或图像,而是要转换所有内容的颜色空间输入pdf本身。

总结我想要的是:

给出一个pdf,其中包含图像和文本的混合色彩空间。

然后使用pdfbox

创建新的pdf或使用cmyk颜色空间更新现有的pdf以获取其所有内容。

0 个答案:

没有答案