Chart.ToPDF Set Page Size

Hello,

Is there a way to set the desired output page size when using Chart.ToPDF?

Right now I am using it with memory streams and Aspose.Pdf.Facades.PdfFileEditor to concatenate just the charts (embedded or chart sheets) from a workbook into a single PDF. When using Chart.PDF, the resulting page in the PDF is the size of the chart.

Thanks,

Sheri

@sheri_steeves

Thanks for using Aspose APIs.

We are afraid, this feature is not available at the moment. We have logged it in our database for evaluation and implementation. Once, we will have some fix or other news for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-46045 - Set Pdf Page Size while using Chart.ToPdf method

Thanks, I’ll keep watch to see if the feature gets added.

@sheri_steeves

FYI:
You should get email notification once we post some update here. It means, you do not need to keep watching this topic.

Please check your inbox, you must already be having two email notifications for two of my posts in this topic.

Thanks, @shakeel.faiz, I have been getting the emails.

@sheri_steeves

We have looked into this issue and found that you can set width and height of the chart to the desired width and height, then render it to pdf.

Please see the section Chart Position and Size that explains how to change chart position and size.

@shakeel.faiz

Thanks, I’ll give it a try and see if it is what I am looking for.

@shakeel.faiz

I was able to change the size of the chart but what am really looking for is for the chart to be placed in the middle (or wherever) of a standard sized page such as Letter, similar to the output of a chart tab when using Workbook.Save.

I was able to work around this by creating new chart sheets and placing the embedded charts on them, and then using hidden sheets and Workbook.Save to get my results.

I found it odd that the ToPDF created pages sized to the charts; I was expected some sort of default paper size. It makes sense for ToImage to maintain the pixel size of the chart since you are going to an image and not a document.

Sheri

@sheri_steeves

Thanks for your posting and using Aspose APIs.

We are clear about your needs and we will add an API for it that will fulfill your requirements. Once, we will have some fix for you, we will update you in this topic asap.

@sheri_steeves,

Please try our latest version/fix: Aspose.Cells for Java v18.3.9.

We have fixed your issue now.

We added new APIs:

  • Chart.ToPdf(string fileName, float desiredPageWidth, float desiredPageHeight, PageLayoutAlignmentType hAlignmentType, PageLayoutAlignmentType vAlignmentType)
  • Chart.ToPdf(Stream stream, float desiredPageWidth, float desiredPageHeight, PageLayoutAlignmentType hAlignmentType, PageLayoutAlignmentType vAlignmentType)

e.g
Sample code:

Workbook wb = new Workbook(srcFile);

//Set Paper A4 size.
wb.Worksheets[0].Charts[0].ToPdf(outputPdfFile, 8.27f, 11.69f, PageLayoutAlignmentType.Center, PageLayoutAlignmentType.Center);

Let us know your feedback.

I’m using the .NET library - do you know when this will be migrated to the .Net version? The NuGet package is still on 18.3.0.

Thanks,

Sheri

@sheri_steeves,

Sorry, the previous fix was for Java. Please try our latest Aspose.Cells for .NET v18.3.9 for your needs.

Let us know your feedback.

Thanks, I’ve downloaded the zip and will try shortly.

Works great!

An automatic FitToPage and/or margins would also be great but that is also something I can easily calculate. Now my PDF looks good.

@sheri_steeves

For your other issue i.e.

Please feel free to create a separate topic and elaborate your requirements there, we will evaluate them and if possible implement them in our future versions. Thanks for your cooperation in this regard and have a good day.

The issues you have found earlier (filed as CELLSNET-46045) have been fixed in this update. Please also check the document/article for your reference: Install Aspose Cells through NuGet|Documentation