We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert charts, graphs in Word to Image in PDF

I’m trying to convert Microsoft word 2016 document with charts and graphs into PDF. The conversion is successful. However, the charts and graphs are showing up as paragraphs and/or tables in the PDF.
Is there a way to convert them as images in to the PDF?

Thanks!

@naru.shiva,

Please ZIP and upload your input Word document and output PDF file showing the undesired behavior here for testing. We will investigate the issue on our end and provide you more information.

Here is the zipped folder with 2 files.
First: Word document with text, chart and image.
Second: PDF generated using ASPOSE words. The chart in this PDF is showing up as text/paragraph.

I would like to have this chart displayed as image. Let me know if this is possible.

Test Files.zip (59.6 KB)

Thanks!

@naru.shiva,

You can convert Chart to Image before saving it to PDF. Please see the following code:

Document doc = new Document(MyDir + @"Test1.docx");

Shape shape = (Shape)doc.GetChildNodes(NodeType.Shape, true)[0];
if (shape.HasChart)
{
    ShapeRenderer renderer = shape.GetShapeRenderer();
    using (MemoryStream ms = new MemoryStream())
    {
        renderer.Save(ms, new ImageSaveOptions(SaveFormat.Png));
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.MoveTo(shape);
        builder.InsertImage(ms);
        shape.Remove();
    }               
}

doc.Save(MyDir + @"18.1.pdf");

Hi Awais. very much appreciated. It worked and I was able to render chart as image.

One small glitch is, the image quality is low when compared.

I have attached the zipped folder of all the 3 files. Please let me know.

Thank you,
Shiva

Test1.zip (143.3 KB)

@naru.shiva,

But, when you copy the PNG image of Chart from PDF to MS Paint, the quality is fine. It seems PDF displays low quality raster image formats such as PNG. As a workaround, you can try SVG format:

renderer.Save(ms, new ImageSaveOptions(SaveFormat.Svg));

Awesome. That came out way better than PNG.
Really appreciated.

Thank you!

A post was split to a new topic: Convert charts, graphs in Word to Image in PDF - Aspose.Words

A post was split to a new topic: Provide Java equivalent of Aspose.Words code