[
https://issues.apache.org/jira/browse/PDFBOX-3206?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15112271#comment-15112271
]
Tilman Hausherr edited comment on PDFBOX-3206 at 1/22/16 10:32 AM:
-------------------------------------------------------------------
The second method is wrong, {{JPEGFactory.createFromImage()}} is to use images
when *creating* a PDF. The first method is correct, assuming that convertDPI
does have "200" in it. The screenshot you have attached shows 96 dpi, but it is
unclear how the image was created. The migration guide explains how to save
images:
https://pdfbox.apache.org/2.0/migration.html
{code}
pdfRenderer.renderImageWithDPI(pageCounter, 300, ImageType.RGB);
// suffix in filename will be used as the file format
ImageIOUtil.writeImage(bim, pdfFilename + "-" + (pageCounter++) + ".png",
300);
{code}
The dpi value means two things here: in {{renderImageWithDPI}} it relates to a
factor, thus an image size. The second thing is when saving this image, then
the 200 is just meta data. While your screenshot has "96 dpi", its size 1654 x
2339 is the correct size for a 200dpi of that PDF. So in your file it's just
the meta data that is wrong - because you didn't use
{{ImageIOUtil.writeImage()}} which would insert the 200dpi into the meta data
of the image. I have attached the image with correct meta data for you to see.
was (Author: tilman):
The second method is wrong, {{JPEGFactory.createFromImage()}} is to use images
when *creating* a PDF. The first method is correct, assuming that convertDPI
does have "200" in it. The JPG file you have attached has 96 dpi, but it is
unclear how the image was created. The migration guide explains how to save
images:
https://pdfbox.apache.org/2.0/migration.html
{code}
pdfRenderer.renderImageWithDPI(pageCounter, 300, ImageType.RGB);
// suffix in filename will be used as the file format
ImageIOUtil.writeImage(bim, pdfFilename + "-" + (pageCounter++) + ".png",
300);
{code}
The dpi value means two things here: in {{renderImageWithDPI}} it relates to a
factor, thus an image size. The second thing is when saving this image, then
the 200 is just meta data. While your screenshot has "96 dpi", its size 1654 x
2339 is the correct size for a 200dpi of that PDF. So in your file it's just
the meta data that is wrong - because you didn't use
{{ImageIOUtil.writeImage()}} which would insert the 200dpi into the meta data
of the image. I have attached the image with correct meta data for you to see.
> Cannot change converted image's DPI
> -----------------------------------
>
> Key: PDFBOX-3206
> URL: https://issues.apache.org/jira/browse/PDFBOX-3206
> Project: PDFBox
> Issue Type: Bug
> Components: Documentation, Rendering
> Affects Versions: 2.0.0
> Environment: Windows 10, JDK 1.7
> Reporter: Jae Soon Kim
> Labels: newbie
> Fix For: 2.0.0
>
> Attachments: Granizo.pdf, Granizo1.jpg, 캡처.JPG
>
>
> When i convert pdf to jpg, i use "renderImageWithDPI" and
> "JPEGFactory.createFromImage".
> but DPI doesn't change.
> So, How can i change image's DPI in pdfbox 2.0.0
> please let me know that.
> This is my source.
> 1. using renderImageWithDPI
> {code}
> PDDocument document = PDDocument.load(sourceFile);
> PDFRenderer pdfRenderer = new PDFRenderer(document);
> int pageCounter = 0;
> for (PDPage page : document.getPages()){
> RenderedImage im = pdfRenderer.renderImageWithDPI(pageCounter,
> Integer.parseInt(convertDPI), ImageType.RGB);
> File f = new File(destinationDir +"/"+saveName+"_"+
> String.format("%03d", pageCounter)+"."+convertFormat);
> ImageIO.write(im, convertFormat,f);
> pageCounter++;
> }
> document.close();
> {code}
> 2. using "JPEGFactory.createFormImage"
> {code}
> PDDocument document = PDDocument.load(sourceFile);
> PDFRenderer pdfRenderer = new PDFRenderer(document);
> int pageCounter = 0;
> for (PDPage page : document.getPages()){
> BufferedImage image = pdfRenderer.renderImage(pageCounter, 1);
> PDImageXObject pdImage = JPEGFactory.createFromImage(document, image,
> Float.parseFloat(convertQuality), Integer.parseInt(convertDPI));
> File f = new File(destinationDir +"/"+saveName+"_"+ String.format("%03d",
> pageCounter)+"."+convertFormat);
> ImageIO.write(pdImage.getImage(), convertFormat,f);
> }
> document.close();
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]