Render to Graphic Context

Hello,

I’m currently evaluating your products in order to integrate different document formats into our reporting solution.

In Aspose Words a method RenderToScale exists which can be used to render to System.Drawing.Graphics.

This is very convenient for integrating the tool into a report generator.

Unfortunately, your other products Cells, Slides and PDF lack this functionality.

Is it not possible to render to a Graphics context?

Could you add this functionality in a future release?

Best Regards,
Raphael

Hi,

Thanks for your posting and using Aspose APIs.

Regarding Aspose.Cells, this feature is already available. Using Aspose.Cells, you can render your chart or worksheet image to your desired size. Please check this article for your detailed reference. Let us know if it suits your requirements or you need a different feature.

( Export Worksheet or Chart into Image with Desired Width and Height|Documentation )

For other products, we will look into your issue further and log the tickets in our database to support this feature.

Thanks for the answer but I do not want to render an image I need to draw into a Graphic context.

The reason is that we convert the result into PDF later and I do not want to include pictures because they do not scale well.

Regards,
Raphael

Hi,

Thanks for your feedback and considering Aspose APIs.

Kindly provide us the sample code illustrating your requested feature with Aspose.Words. We will then add the similar API in other Aspose APIs like cells, pdf, slides etc.

Here is a bit sample code usings Words:

    public override void Paint(System.Drawing.Graphics context, Rectangle rect)
    {
            Doc.RenderToSize(0, context, (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height);
    }

Best Regards,
Raphael

Hi Raphael,

Thanks for the details. This requirement has been logged for Aspose.Pdf, Aspose.Slides and Aspose.Cells into our issue tracking system as PDFNEWNET-38951, SLIDESNET-36588 and CELLSNET-43758 respectively.

We will keep you updated on these issues in this thread.

Best Regards,

Hi,

Thanks for using Aspose.Cells.

We have added this feature in Aspose.Cells. Please download and use the latest fix: Aspose.Cells
for .NET v8.5.0.3
.

We have added new API in class SheetRender:
ToImage(int pageIndex, Graphics g, float x, float y)
ToImage(int pageIndex, Graphics g, float x, float y, float width, float height)

Code:
//Init workbook…

Workbook wb;
//render first sheet
SheetRender sr = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions { });
//Init Graphics…
Graphics g;
//render first page of the sheet
sr.ToImage(0, g, x, y, width, height);

Hello,

Thanks for the change, I have tested it.

But the rendering is still based on image. I assume, you are now rendering the content as image and then draw the image to the graphic content. For high (scalable) print quality the worksheet must be rendered directly on the Graphics context (like the Words component is doing it).

I hope, you can change it accordingly.

Best Regards,
Raphael

Hi,

Thanks for your feedback and using Aspose.Cells.

We have logged your comment in our database for product team consideration. We will evaluate it and see if it can be fixed/enhanced more. Once there is some fix or other news for you, we will let you know asap.

Hi,

Thanks for using Aspose.Cells.


We do render the sheet to graphics context directly and not render to image first and then draw the image to graphics context.

If I redirect the Graphics context to PostScript printer and create a PDF from the PostScript, the sheet looks like an image. If I do the same with Words, it is text.



I attach you two PDFs one from Cells (Cells.pdf) and one from Words (Words2.pdf).



In addition, if I use the ToPrinter method of SheetRender, this effect does not occur, see (Cells2.pdf)



Best Regards,

Raphael

Hi Raphael,

Thanks for your feedback and using Aspose.Cells.

It seems this is not image but a text but it is not selectable. However, I have logged your comment and files for product team consideration. We will investigate it and let you know if there is some error or why the text is not selectable. Once there is some update for you, we will let you know asap.

Hi Raphael,

Thanks for using Aspose.Cells.

Please try the following code, the result is ok.


C#


//Init workbook…

Workbook wb;

//render first sheet

SheetRender sr = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions { });

//Init Graphics…

Graphics g;

//render first page of the sheet

sr.ToImage(0, g, x, y);

We have found that if using the API sr.ToImage(0, g, x, y, width, height) instead, we will scale page width to the setting width, and scale page height to the setting height, this may cause different scaling in page width and height and the result looks like an image.

Hi,

I can confirm that without the scaling the output is ok.

But I need the scaling.

Because I need the same behaviour like Aspose.Words I did some testing with a word document and there it works because the aspect ratio is NOT changed. Means the Width and Height input is not fully honored and the function tries to get as close as possible without changing the aspect ratio.

Please consider to change the scaling in the same manner than Words (because changing the aspect ratio will never look good).

Thanks again
Raphael

Hi Raphael,

Thanks for your feedback and using Aspose.Cells.

We have logged your comment in our database against this issue for product team’s consideration. We will look into it and implement it if possible. Once there is some fix or other news for you, we will let you know asap.

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.5.1.1 and let us know your feedback.

Hi,

Thanks for the latest fix, this is exactly what I need, thank you.

May I ask if you also plan to change the PDF component in the same way? If you want I can also create a new Post in the Pdf forum…

If I also can use the PDF component from Aspose, I can then but the whole bundle.

Slides is also on the wishlist, but has lower priority than PDF.

Best Regards,
Raphael

Hi Raphael,

Thanks for your feedback and using Aspose APIs.

Yes, please create a new thread in Aspose.PDF forum, you can also give the reference to this thread too there. Aspose.PDF team will look into your requirements and implement your requested feature in future versions.

Thanks for your cooperation.

The issues you have found earlier (filed as CELLSNET-43758) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

The issues you have found earlier (filed as SLIDESNET-36588) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.