Using scalable images in your documentation
When writing FlexCel documentation at tms, we often need to include document screenshots.
In many cases, a simple screen capture will do. But in others, we'd like something that can scale with the monitor resolution, and a bitmap is not enough. In those cases, we use FlexCel to export the images as SVG (scalar vector graphics).
We will discuss two different cases here:
Sometimes you want to render a simple object. Like for example the chart at the top of this blog post We created that image from the file in the Chart API example, using the following code:
var svg: String; ... svg := xls.RenderObjectAsSVG(-1, '@lines of code', 'Lines of code over time', 'This chart was rendered with RenderObjectAsSVG', TEncoding.UTF8); begin TFile.WriteAllText('flexcel-lines-of-code.svg', svg); end;
Other times, you might want to render a part of a sheet, as we did in the diagram at the end of this article. On those cases, we use code similar to the following:
var svg: TFlexCelSVGExport; ... svg := TFlexCelSVGExport.Create(xls, true); try // Set a page size that has the size of the image you want. // You will need to experiment a little to get the correct size. svg.PageSize := TPaperDimensions.Create('custom', $30C, $12C); svg.SaveAsImage( procedure (x: TSVGExportParameters) begin x.FileName := 'result' + IntToStr(x.PageNumber) + '.svg'; end); finally svg.Free; end;
You might change the print scaling of the xlsx file to get a smaller or bigger image.