Write higher resolution (DPI) Images to PDF

最后都变了- 提交于 2019-12-13 18:42:06

问题


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;

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.

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

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 ?

Thanks,


回答1:


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

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

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

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.



来源:https://stackoverflow.com/questions/25358147/write-higher-resolution-dpi-images-to-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!