// Loop through all the pages of PDF file
for (int pageCount = 1; pageCount <= pdfDocument.getPages().size(); pageCount++) {
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream(“Converted_Image” + pageCount + “.png”);
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create PngDevice object with particular resolution
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
// Close the stream
imageStream.close();
}
(2) Convert PDF to SVG
Document doc = new Document(“D:\test.pdf”);
// 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);
Do you show me the sample code for convert pdf all pages to SVG ? Just like (1) which has “PngDevice.process” for each page of pdf, looking for the similar way for “svg”. Now only “convert whole
pdf file to one SVG image”.
You may iterate through each page and save it to SVG format one after another. Below is a code snippet for your kind reference.
// Load PDF document
Document document = new Document(dataDir + "pdfSource_Greg.pdf");
foreach (Aspose.Pdf.Page page in document.Pages)
{
Document doc = new Document();
doc.Pages.Add(page);
// Instantiate an object of SvgSaveOptions
SvgSaveOptions saveOptions = new SvgSaveOptions();
// Do not compress SVG image to Zip archive
saveOptions.CompressOutputToZipArchive = false;
// Save the output in SVG files
doc.Save(dataDir + "PDFToSVG_"+ page.Number +"_out.svg", saveOptions);
}
We hope this will be helpful. Please feel free to contact us if you need any further assistance.
We have been able to reproduce the issue in our environment. A ticket with ID PDFNET-45833 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 afraid PDFNET-45833 has not been resolved yet. We have recorded your concerns and will let you know as soon as any update will be available in this regard.