将更高分辨率(DPI)图像写入PDF [英] Write higher resolution (DPI) Images to PDF

查看:905
本文介绍了将更高分辨率(DPI)图像写入PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过基于图像DPI使用PDFBox提取图像的代码,如下所示

I have seen code to extract the images based on image DPI using PDFBox like below

    PDDocument  document = PDDocument.load(path);
    PDFImageWriter writer = new PDFImageWriter();
    boolean success = writer.writeImage(document, "jpg", "", 1, 1,
                 "C:\\Image Quality\\150", BufferedImage.TYPE_INT_RGB, 150);
    return document;

在上面的代码中,我可以在从pdf中提取图像时指定图像分辨率(150)。分辨率越高,我得到的图像越大。

In above code I can specify the image resolution(150) while extracting the image from pdf. With higher resolution I get larger image in return.

现在我想反过来意味着在将图像写入PDF时指定图像的分辨率/ dpi,但是下面的代码是没有提供指定DPI的选项?任何人都可以指导我缺少的地方

Now I want reverse of it means to specify the resolution/dpi of image while writing image to PDF, but following code is not providing such options to specify DPI ? Can anyone guide me where I am missing

PDPageContentStream contentStream = null;
contentStream = new PDPageContentStream(document, userPage);
contentStream.drawImage(img, 60, 60);       
contentStream.close();

请指导我在哪里可以传递分辨率/ DPI参数(因为图像大于pdf页面尺寸)同时将图像写入PDF?

Please guide me where I can pass the parameter of resolution/DPI (as image is larger than pdf page size) while writing image to PDF ?

谢谢,

推荐答案

你被告知回答你的问题之前的问题,dpi在PDF的上下文中几乎没有意义。

You have been told in answer to your previous question that dpi hardly has meaning in the context of PDF.

有人说,很难,你可以使用
PDPageContentStream.drawXObject方法实现你的目标( PDXObject xobject,float x,float y,float width,float height)

That been said, tough, you can achieve your objective using the method PDPageContentStream.drawXObject(PDXObject xobject, float x, float y, float width, float height)

以原始形式调整图像大小(即下采样),然后使用drawImage嵌入下采样图像。

Resizing (i.e. downsampling) the image in its original form and then using drawImage embeds the downsampled image.

另一方面,使用drawXObject会嵌入原始图像并对其进行缩放。因此,在高分辨率打印输出时,前者仅提供下采样的,较少分辨的图像,而后者允许输出较高分辨率的图像。

Using drawXObject on the other hand embeds the original image and scales it. Thus, at high resolution print-out the former only supplies the downsampled, less resolved image while the latter allows the higher resolved image to be output.

这篇关于将更高分辨率(DPI)图像写入PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆