Static PDF Export Settings

Overview

The PDF format settings are made in the configuration XML file, in a specially designated section. For exporting to PDF with static image, you can define a plenty of options, which are going to be covered further in this article.

All the settings are provided in the <pdf> node. Here is the listing showing the location of that node in relation to the root:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <pdf />
06     </export_settings>
07   </utils>
08 </stock>
01{
02  utils: {
03    exportSettings: {
04      pdf: {}
05    }
06  }
07}

Here is the table of attributes, descriptions and values available in the <pdf> node:

Attribute Possible Values Description
size Original
Custom
Sets exported image size mode:
Original - uses the original chart width and height it is embedded in the page with;
Custom - allows setting custom width and height for the exported image.
resizing_mode Fit
Recalculate
Stretch
RecalculateByProportions
Sets chart resizing mode when using custom size of exported image: This setting is applicable only when size="Custom". By default, it is set to Fit.
width Integer Sets custom image width in pixels. This setting is applicable only when size="Custom".
height Integer Sets custom image height in pixels. This setting is applicable only when size="Custom".
cut_extra_space true
false
If this attribute is set to true, the extra space without elements of the chart will be cropped when exporting. This setting is applicable only when the resizing_mode attribute is set to Fit or RecalculateByProportions. By default, it is set to false.
file_name String Sets name for the file the PDF image will be saved to. When changing this attribute, it is mandatory to specify the ".pdf" extension. By default, the value used is "AnyChartStock.pdf"
background_color Color This attribute sets background color. By default, it is set to #FFFFFF.

All the PDF settings specified in the configuration file apply when exporting the chart to the PSF format with a command from the context menu and are also considered when exporting by calling the JavaScript functions exportAsPDF and getPDFImageBase64Encoded.

to top

Setting Up File Name

By default, when a chart is saved to a PDF with static, the file gets the name "AnyChartStock.pdf".

To change the target file name, you need to use the file_name attribute. Here is a sample syntax for changing the default target file name:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <pdf file_name="StockChart_2009_11_28.pdf" />
06     </export_settings>
07   </utils>
08 </stock>
01{
02  utils: {
03    exportSettings: {
04      pdf: {
05        fileName: "StockChart_2009_11_28.pdf"
06      }
07    }
08  }
09}

Along with the file name, you need to specify the extension, i.e. append the ".pdf" string to the name.

to top

Background Color

When embedding the component in an HTML page, the background color to be used in the given instance of the chart is passed to the the Flash Player. When exporting the chart to an image, the component cannot obtain the given background color, and therefore, the background color for exporting is to be configured separately.

By default, the background color used for exporting is white, but you can customize it with the color attribute. Here is a sample syntax for setting the background color to light-red:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <pdf background_color="#FEAAAA" />
06     </export_settings>
07   </utils>
08 </stock>
01{
02  utils: {
03    exportSettings: {
04      pdf: {
05        backgroundColor: "#FEAAAA"
06      }
07    }
08  }
09}

The background_color attribute accepts color in different formats. A closer look at setting up color to elements in the AnyChart Stock component is provided in Color Settings.

to top

Using Custom Size

By default, the component exports the chart to PDF with chart image with the same dimensions and in the same scale as it is presented on the HTML page. When necessary, it allows using custom size (in pixels) when exporting using different chart scaling modes.

This functionality is identical for the PNG, JPG and PDF formats and is covered in detail in Using Custom Export Size.

to top

exportAsPDF and getPDFImageBase64Encoded Function Parameters

When exporting a chart by calling the JavaScript functions exportAsPDF or getPDFImageBase64Encoded, the settings used by default are the ones specified in the configuration file. For example:

Would save the chart with the settings specified in the configuration file.

You can also specify custom settings (as an XML String JavaScript Object). The settings structure is identical to the structure of the <pdf> node.

A sample for saving a chart using XML String settings:

A sample for saving a chart using JavaScript Object settings:

IMPORTANT! Settings passed in these methods' arguments do not reset current export settings. In other words, if the settings file contains:

XML/JSON Syntax
Plain code
02   <pdf background_color="Gray" />
01{
02  pdf: {
03    backgroundColor: "Gray"
04  }
05}

And when calling the method you have specified:

XML/JSON Syntax
Plain code
01 <pdf file_name="stock.pdf" />
01{
02  fileName: "stock.pdf"
03}

The image will be exported with a gray background.

Using the links below, you can try out these settings in action and obtain the archived example for reviewing the source code:

Online HTML/JavaScript Sample

to top