Convert pdf files to image and then apply zoom to these pictures

Hi all!, I wanted to know if it is possible to convert pdf files to images and then apply zoom to these pictures.

My application has a feature that shows pictures in preview, and we want to add the possibility of increasing the size of the pictures with double click, like a zoom.

It is possible convert pdf files to images and then apply zoom to these picture with Aspose?

We use Aspose for Java.

Best Regards
Martin Fernandez
Java Developer

Hi Martin,


Thanks for contacting support.

Aspose.Pdf for Java supports the feature to convert PDF pages into Image format. However it does not support the feature to set zoom level for resultant image. As a workaround, you can first set the zoom level over PDF file and then convert PDF pages to Image format. Please take a look over following code snippet.

[Java]

// instantiate PdfPageEditor class to
get particular page region
<o:p></o:p>

com.aspose.pdf.facades.PdfPageEditor editor = new com.aspose.pdf.facades.PdfPageEditor();

// bind the source PDF file

editor.bindPdf("c:\\pdftest\\OptimizedFile.pdf");

// set zoom over PDF file

editor.setZoom(2);

// save the PDF file to temporary location

editor.save("c:/pdftest/ZoomLeverChanged.pdf");

//open document

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("c:/pdftest/ZoomLeverChanged.pdf");

// create stream object to save the output image

java.io.OutputStream imageStream = new java.io.FileOutputStream("c:/pdftest/New_Converted_Image.jpg");

//create JPEG device with specified attributes

//Quality [0-100], 100 is Maximum

//create Resolution object

com.aspose.pdf.Resolution resolution = new com.aspose.pdf.Resolution(300);

//create JpegDevice object where second argument indicates the quality of resultant image

com.aspose.pdf.JpegDevice jpegDevice = new com.aspose.pdf.JpegDevice(resolution, 100);

//convert a particular page and save the image to stream

jpegDevice.process(pdfDocument.getPages().get_Item(1), imageStream);

//close the stream

imageStream.close();



For further information, please visit Convert PDF pages to JPEG Image

Hi Nayyer, thank you very much for your help, now I’m converting pdf images with zoom, but now the images created, some of them appears in black, as you can see in the attachments.

I’m using the library Aspose.Pdf-new-4.0.0.jar.

Here I leave my test code, also tried not to use BufferedImage but the problem continued.

com.aspose.pdf.facades.PdfPageEditor editor = new com.aspose.pdf.facades.PdfPageEditor();
String pdfFileName = “c:/pdftest/originalTestDoc.pdf”;
editor.bindPdf(pdfFileName);
editor.setZoom(1.5f);
editor.save(“c:/pdftest/testdoc_zoom.pdf”);
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(“c:/pdftest/testdoc_zoom.pdf”);
File fileImage = new File(“c:/pdftest/testdocimage.png”);
java.io.OutputStream imageStream = new java.io.FileOutputStream(fileImage);
com.aspose.pdf.Resolution resolution = new com.aspose.pdf.Resolution(200);
com.aspose.pdf.PngDevice pngDevice = new com.aspose.pdf.PngDevice(resolution);
pngDevice.process(pdfDocument.getPages().get_Item(actualPage+1), imageStream);
BufferedImage bi = ImageIO.read(fileImage);
imageStream.close();

I attached 3 files, the original pdf, the pdf with zoom and the png file.

Could you help me, please?

Best regards
Martin Fernandez
Java Developer.

Hi, I want to know if you have any news about this topic.


Thank you very much
Martin Fernandez
Java Developer

I updated to the last version of Aspose pdf (aspose.pdf-new-4.1.0) but the problem continues.


Best Regards
Martin Fernandez

Hi Martin,


Thanks for sharing the resource files and sorry for the delayed response.

I have tested the scenario using Aspose.Pdf for Java 4.1.0 where I have JDK 1.7_09 installed over Windows 7 (X64) and during my testing in Eclipse Juno project, I am unable to notice any problem. The resultant Image is properly being generated. For your reference, I have also attached the resultant image which is generated over my end.

Can you please share some details regarding your working environment. We are sorry for your inconvenience.

Hi, thanks for the answer, Do you tested with the code snippet that I send you?
My environment is also win7 64bit, eclipse Juno but Java 6.

I tried with versions 4.0.0 and 4.1.0 of Aspose.Pdf but for this last, I had to take the package related to Servlets because they gave me compatibility problems with other servlet library that we have in our project.

It could be the resolution?
I will keep trying, if you have something to suggest me, will be welcome.
Best Regards
Martin Fernandez
Java Developer

Hi, I have origen.pdf file that was implemented a zoom, this conversion was not the best, if you see the resulting pdf file "origen_zoom.pdf", the pdf file was not correctly created, Could you help me with other example code?
In addition, I'm still having problems with some pdf files which when converted to images, these images appear in black.

thank you very much
Martin Fernandez
Java Developer

Hi Martin,


Sorry for the inconvenience faced. We are looking into the issue and will update you soon.

Best Regards,