Convert pdf to svg by pages


#1

Hi,

Aspose provides

(1)Convert All PDF Pages to PNG Images

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document(“input.pdf”);

// 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”.

Thanks!

Ruhong


#2

@ruhongcai

Thank you for contacting support.

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.


#3

Hi,

Thanks for the sample code and it works.
However, in some case, the result is not expected.

Please see the attached input.pdf and output_screenshot, you will see the problem.

Thanks for help!

RuhongpdfToSVG.zip (1.9 MB)


#4

@ruhongcai

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 sorry for the inconvenience.


#5

Any update on 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


Takes very long time to convert pdf to image
#6

@ruhongcai

Thank you for getting back to us.

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.