try {
Document pdfAsposeDocument;
Resolution resolution;
JpegDevice jpegDevice;
pdfAsposeDocument = new Document("C://test.pdf");
Page pageForAsposePdf = pdfAsposeDocument.getPages().get_Item(1);
resolution = new Resolution(162);
jpegDevice = new JpegDevice(resolution, 162);
OutputStream output = new FileOutputStream(new File("C://temp//out.svg"));
jpegDevice.process(pageForAsposePdf, output);
// Close the stream
output.close();
} catch (IOException e) {
//handling
}
}
Thank you for contacting support.
We have noticed that you are using JpegDevice
but saving the image as SVG which may be causing the trouble for you. Please try using below code snippet in your environment and then share your kind feedback with us. It takes about 8 seconds after loading the PDF document, with Aspose.PDF for Java 18.11 in our environment.
// load PDF document
Document doc = new Document("D:\\test.pdf");
long start = System.currentTimeMillis();
// instantiate an object of SvgSaveOptions
SvgSaveOptions saveOptions = new SvgSaveOptions();
// do not compress SVG image to Zip archive
saveOptions.CompressOutputToZipArchive = false;
// resultant file name
String outFileName = "D:\\Output.svg";
// save the output in SVG files
doc.save(outFileName, saveOptions);
long completed = System.currentTimeMillis();
System.out.println("Elapsed time: " + ((completed - start) / 1000) + " seconds.");
We hope this will be helpful. Please feel free to contact us if you need any further assistance.
Our company also facing same problem when we upload 40 pages of pdf. We have to use png type conversion instead of svg. Please give us solution for PNG file conversion.
// Convert
String outputFileNamePrefix = getRandomFileName();
for(int pageIndex = 0; pageIndex < this.documentPageCount; pageIndex++) {
// Random file
File randomFile = getRandomFile(".png", outputFileNamePrefix, pageIndex);
FileOutputStream randomFileOutputStream = null;
try {
randomFileOutputStream = new FileOutputStream(randomFile);
}
catch (Exception e) {
log.error(getWorkerIdLogPrefix(), e);
return postToWorkerWithError("Failed to open randomFile for pdf");
}
// Write
Resolution resolution = new Resolution(150);
PngDevice pngDevice = new PngDevice(resolution);
Page page = document.getPages().get_Item(pageIndex + 1); // get_Item is 1...n
pngDevice.process(page, randomFileOutputStream);
BufferedImage bufferedImage;
try {
bufferedImage = ImageIO.read(randomFile);
} catch (IOException e) {
return postToWorkerWithError("Failed to get bufferedImage from randomFile");
}
try {
randomFileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
return postToWorkerWithError("Failed to close pdf output stream");
}
this.outputResult.appendDimensionToPage(pageIndex, bufferedImage.getWidth(), bufferedImage.getHeight());
}
Thank you for contacting support.
Please visit Convert PDF Pages to PNG Images for your kind reference. If you still face any problem then share your PDF document with us so that we may investigate further to help you out.
Hi Farthan,
Thanks for the sample code, it solved the problem. Thanks!
Hi Farthan,
Your solution was for “svg” format, we also need to support “png” format , the
same test file and the following code run “long” time … Thanks for help!
// load PDF document
Document doc = new Document("C:\\temp\\test.pdf");
long start = System.currentTimeMillis();
Resolution resolution = new Resolution(300);
java.io.OutputStream imageStream = new
java.io.FileOutputStream("C:\\temp\\out.png");
// Create PngDevice object with particular resolution
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.process(doc.getPages().get_Item(1), imageStream);
long completed = System.currentTimeMillis();
System.out.println("Elapsed time: " + ((completed - start) / 1000) + " seconds.");
Thanks!
Ruhongtest.zip (536.6 KB)
We have been able to reproduce the issue in our environment. A ticket with ID PDFJAVA-38236 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.
We are sorry for the inconvenience.
Any update for this?
We convert pdf to png and have performance issue
, you recommended “convert pdf to svg” but result svg are not expected in some cases.
Thanks for help!
Ruhong
Thank you for getting back to us.
We are afraid PDFJAVA-38236 is still pending for investigations owing to previously logged and critical tickets. We will let you know as soon as any update will be available in this regard.
The issues you have found earlier (filed as PDFJAVA-38236) have been fixed in Aspose.PDF for Java 20.5.
We are facing the same issue with .Net version also, which is “Aspose.Pdf.11.4.0\lib\net40-client\Aspose.Pdf.dll”.
It is taking more than 2mins to convert the PDF doc to PNG image.
Could you please try using latest version i.e. Aspose.PDF for .NET 20.9 and in case issue still persists, please share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.
I have tried with the latest version as you suggested, but the issue still persist.
The tested PDF document is from the end customer. Could you please ensure the confidentiality of the document, so that I can share the document with you.
We assure you that your files are only used for testing purposes and as soon as we complete the investigation, the files are erased from our system. Furthermore, you may please share your document in a private message by clicking over username and pressing Blue Message Button.
Thanks for your response.
As you suggested, I have sent Private message with the sample document.
Please check the attached file for your reference and looking forward for the fix asap.
We were able to replicate the issue in our environment. The API took time more than expected while using following code snippet:
Document pdfDocument = new Document(dataDir + "Sample Doc.pdf");
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
string tmpImgToInsert = DateTime.Now.Ticks + ".png";
using (FileStream imageStream = new FileStream(dataDir + tmpImgToInsert, FileMode.Create))
{
var pngDevice = new PngDevice(new Resolution(300))
{
RenderingOptions = new RenderingOptions()
{
UseFontHinting = true,
//OptimizeDimensions = true,
//InterpolationHighQuality = true,
//UseNewImagingEngine = true
}
};
pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);
imageStream.Close();
}
}
sw.Stop();
Console.WriteLine("Total seconds taken : " + sw.Elapsed.TotalSeconds);
Therefore, we have logged an issue as PDFNET-48887 in our issue tracking system for API performance. We will further look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.
We are sorry for the inconvenience.
The ticket has been logged recently in our issue management system and will be investigated/resolved on first come first serve basis. As soon as we make some definite progress towards its resolution, we will surely inform you within this forum thread. Please give us some time.
We apologize for the inconvenience.
We are afraid that earlier logged issue has not been yet resolved due to previously logged issues in the queue. However, we will update you in this forum thread as soon as we have certain news about its fix. Please spare us some time.
We are sorry for the inconvenience.