Hello,
I need to convert a PDF file to an Image File, until now I used Aspose.PDF.
My problem is, I have to resize the created JPEG I can do that with Aspose.PDF passing the JpegDevice a size!
My problem is, I dont know how BIG is the original size, and i will pass the JpegDevice only the width value, and the high value should be the result of manting the relation between width and height setting only the width value.
There are not many things that I cand do on Image with Aspose.PDF library, so I tried to do the same thing using Aspose.Imaging.
On your product description you wirte Import/Export PDF, but I found nothing how to do this.
So can I export a PDF file into JPEG with Aspose.Imaging.
And what is the best way to create a new JPEG starting from a PDF setting only the WIDTH, RESOLUTION and the JPEG QUALITY for the new created JPEG??
thx
Michael
Hi Michael,
On the image here
Java Imaging API | Draw Manipulate and Transform Images | products.aspose.com
I understand I can Import AND export all this Files in each other directions!!
Se also attached file for better understanding:
So for my problem, if you can help me I am very happy:
I do this with Aspose.PDF
License licPdf = new License();
licPdf.setLicense(…);
OutputStream imageStreamThumb = new java.io.FileOutputStream(“/tmp/large.jpg”);
Resolution resolution = new Resolution(200);
JpegDevice jpegDeviceLarge = new JpegDevice(???, ???, resolution, 75);
Document pdfDocument = new com.aspose.pdf.Document(byte[] …);
jpegDeviceLarge.process(pdfDocument.getPages().get_Item(1), imageStreamLarge);
imageStreamLarge.close();
I have here two problems:
a)
How can I resize the JPEG by setting only the WIDTH, the HEIGHT should by calcolated in automatic mantaining the original relation between w and h.
b)
The other thing, I think you have a BUG on your libs! Stting the Resolution to 200DPI does not set the Resolution of 200DPI in the META INF of the JPEG! Open the created JPEG in a Imaging programm shows my the always the resolution of 72x72 dpi, and that is wrong!
can you help me?
thx
Michael
Hi Michael,
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(myDir + “sample.jpg”);
image.resize(newWidth, newHeight);
image.save();
Hi Michael,
Thanks for using our API’s
When using Aspose.PDF for Java to convert PDF pages to JPEG format, you may consider using an over load of com.aspose.pdf.devices.JpegDevice(…) which takes Width, Height, Resolution and Quality parameters as arguments. So as per your requirement, you can load the PDF file into Document object, get PDF file Width and Height information and use the same information as argument to JpegDevice(…) constructor.
But I am afraid in current release of Aspose.PDF for Java, there seems to be an issue while getting page dimensions information. For all the PDF files, a similar value of Page Height and Width is being returned. For the sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-34178.
Document pdfDocument = new com.aspose.pdf.Document("c:/pdftest/sample.pdf");
System.out.println("page Height = " + pdfDocument.getPageInfo().getHeight());
System.out.println("page Width = " + pdfDocument.getPageInfo().getWidth());
com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);
com.aspose.pdf.devices.JpegDevice jpegDeviceLarge = new com.aspose.pdf.devices.JpegDevice((int)pdfDocument.getPageInfo().getWidth(), (int)pdfDocument.getPageInfo().getHeight(), resolution, 100);
jpegDeviceLarge.process(pdfDocument.getPages().get_Item(1), "c:/pdftest/ImageConversion.jpeg");
I have tested this scenario and have observed that whatever value we specify for Resolution object, the resultant image is always in 96 dpi. For the sake of correction, I have separately logged it in our issue tracking system as PDFNEWJAVA-34179. We will investigate these issues in details and will keep you updated on the status of a correction.
We are sorry for this inconvenience.
So for now I can’t calculate me the right dimension, neither I can save a image with the right resolution?
Right?
Hi Michael,
Sorry for my hard words
But in German we say something like that:
If Aspose.Words is like heaven, Aspose.Pdf is like hell.
I do not use many function with .Pdf but I found uncountable errors, for really basic functions!
Ok there is the problem with Aspose PDF and resolution!
But if I try to change the meta information for the resolution by hand as you described, it doesn’t work to:
…
image.setResolution(200,200);
…
Image has always resoltuion by 72x72
Doing this
com.aspose.imaging.fileformats.jpeg.JpegImage imageLarge = (com.aspose.imaging.fileformats.jpeg.JpegImage)com.aspose.imaging.Image.load("/tmp/x/ddaLarge.jpg");
imageLarge.setResolution(200, 200);
System.out.println(imageLarge.getSize().getWidth());
System.out.println(imageLarge.getSize().getHeight());
System.out.println(imageLarge.getVerticalResolution());
System.out.println(imageLarge.getHorizontalResolution());
imageLarge.save(new FileOutputStream("/tmp/x/ddaLargeNew.jpg"));
getVerticalResoltuion() and getHorizontalResoltuion returns 200
BUT opening the image with any programm says me the resoltuio is 72x72
so I think you do not write the resolution meta inf to the right way?
Hi Michael,
The File ddaLarge.jpg in the attachement is a JPEG createt by a Resolution of 200dpi,
but as we know the created Image does always have 96dpi
So as suggested by you I use Aspose.Imaging to manipulate the Resolution by that
com.aspose.imaging.fileformats.jpeg.JpegImage imageLarge = (com.aspose.imaging.fileformats.jpeg.JpegImage)com.aspose.imaging.Image.load("/tmp/x/ddaLarge.jpg");
System.out.println("before -> " + imageLarge.getVerticalResolution());
System.out.println("after -> " + imageLarge.getHorizontalResolution());
imageLarge.setResolution(200, 200);
System.out.println(“before -> " + imageLarge.getVerticalResolution());
System.out.println(“after -> " + imageLarge.getHorizontalResolution());
imageLarge.save();
com.aspose.imaging.fileformats.jpeg.JpegImage imageTest = (com.aspose.imaging.fileformats.jpeg.JpegImage)com.aspose.imaging.Image.load(”/tmp/x/ddaLarge.jpg”);
System.out.println(imageTest.getVerticalResolution());
System.out.println(imageTest.getHorizontalResolution());
imageTest.dispose();
It doesn’t work!
Hi Michael,
michael.burger@siag.it:
Sorry for my hard words
But in German we say something like that:
If Aspose.Words is like heaven, Aspose.Pdf is like hell.
I do not use many function with .Pdf but I found uncountable errors, for really basic functions!
:(
I tried a workaround converting the PDF in a TIFF and using Imaging for converting the TIFF to JPEG!
The createt TIFF has a Resoltuion of 200 SO I WAS HAPPY!
But than converting the file from TIFF to JPEG the created jpeg is as usual only 72x72 (or 96)dpi
So two different libs and 3 different methods to get a JPEG with right resoltuion, but none of them works!
code=>
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.setCompression(CompressionType.LZW);
tiffSettings.setDepth(ColorDepth.Default);
tiffSettings.setSkipBlankPages(false);
TiffDevice tiffDevice = new TiffDevice(new Resolution(200), tiffSettings);
tiffDevice.process(pdfDocument, 1, 1, “/tmp/x/ddaTIFF.tif”);
com.aspose.imaging.fileformats.tiff.TiffImage imageConv = (com.aspose.imaging.fileformats.tiff.TiffImage)com.aspose.imaging.Image.load("/tmp/x/ddaTIFF.tif");
JpegOptions jpegOptions = new com.aspose.imaging.imageoptions.JpegOptions();
imageConv.save("/tmp/x/ddaTIFF.jpg", jpegOptions);
Hi Michael,
Yes, but I do not know what do you do in your libs!
My first error in this thread wos the conversion from PDF to JPEG!
Using ONLY Aspose.PDF and not including Aspose.Imaging by using the class JpegDevice which comes from com.aspose.pdf.devices!!!
So for my (becouse I don’t know and I can’t know how you do it) this are two different errors!!
If you use in your PDF lib your own Imaging lib and use the same methots so resolving one resolves the errors on BOTH libs!!!
But I don’t know what you do in your sources!
Hi Michael,
michael.burger@siag.it:
Yes, but I do not know what do you do in your libs!
My first error in this thread wos the conversion from PDF to JPEG!
Using ONLY Aspose.PDF and not including Aspose.Imaging by using the class JpegDevice which comes from com.aspose.pdf.devices!!!
michael.burger@siag.it:
So for my (becouse I don't know and I can't know how you do it) this are two different errors!!
If you use in your PDF lib your own Imaging lib and use the same methots so resolving one resolves the errors on BOTH libs!!!
The issues you have found earlier (filed as PDFNEWJAVA-34179) have been fixed in Aspose.Pdf for Java 9.1.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.