The article refers to exporting of dhtmlxScheduler 4.1+. If you use dhtmlxScheduler 4.0 or earlier versions, see details here.
Starting from version 4.1, dhtmlxScheduler provides a new approach for exporting the scheduler into the PDF format - an online export service.
The service is free, but the output PDF file will contain the library's watermark under the GPL license. In case you buy a license, the result of export will be available without a watermark during the valid support period (12 months for all PRO licenses).
There are several export services available. You can install them on your computer and export Scheduler to PDF locally.
Note that export services are not included into the Scheduler package, read the corresponding article to learn the terms of using each of them.
There is a common API endpoint https://export.dhtmlx.com/scheduler which serves for export methods (exportToPDF, exportToPNG, etc.). Max request size is 10 MB.
To export a scheduler as a PDF document, complete the following steps:
scheduler.plugins({
export_api: true
});
If you use the Scheduler version older than 7.0, you need to include the https://export.dhtmlx.com/scheduler/api.js file on your page to enable the online export service, e.g.:
<script src="codebase/dhtmlxscheduler.js"></script>
<script src="https://export.dhtmlx.com/scheduler/api.js"></script>
<input value="Export to PDF" type="button" onclick='scheduler.exportToPDF()'>
Related sample: Export to PDF/PNG
The exportToPDF() method takes as a parameter an object with a number of properties (all of the properties are optional):
name | (string) the name of the output file |
format | ('A0', 'A1', 'A2', 'A3', 'A4', 'A5') the format of the output PDF image |
orientation | ('portrait', 'landscape') sets the orientation of the output PDF image |
zoom | (number) sets the zoom coefficient of the output PDF image |
header | (string) specifies the header that will be added to the output PDF image. Note, you can use any HTML here |
footer | (string) specifies the footer that will be added to the output PDF image. Note, you can use any HTML here |
server | (string) sets the API endpoint for the request. Can be used with the local install of the export service. The default value is https://export.dhtmlx.com/scheduler |
additional_settings | (object) an object with additional settings. The object can contain the following attributes:
|
Calling the export method with optional properties
scheduler.exportToPDF({
name:"myscheduler.pdf",
format:"A4",
orientation:"portrait",
zoom:1,
header:"<h1>My company</h1>",
footer:"<h4>Bottom line</h4>",
server:"https://myapp.com/myexport/scheduler"
});
To set a custom name for the output file, use the name property in the in the parameter of the exportToPDF method:
scheduler.exportToPDF({
name:"my_beautiful_scheduler.pdf"});
To add a header/footer to the output PDF file, use the header/footer properties in the parameter of the exportToPDF method:
Note, you can use any HTML while specifying the parameters. While specifying images, remember that you need to set global paths as values of the "src" attribute.
scheduler.exportToPDF({
name:"myscheduler.pdf",
header:"<h1>My company</h1>", footer:"<h4>Bottom line</h4>"});
To apply a custom style for the scheduler, provide the stylesheet with your custom CSS classes:
scheduler.exportToPDF({
name:"calendar.pdf",
header:'<link rel="stylesheet" href="http://mysite.com/custom.css">' });
scheduler.exportToPDF({
name:"calendar.pdf",
header:'<style>... custom css classes here ...</style>' });
Note, the aforementioned solution works for the global HTTP reference. If you have CSS classes specified in an Intranet/local environment, you can embed all styles as in:
scheduler.exportToPDF({
header:"<style>.tier1{background: red; color:white;}</style>"
});
While exporting the Scheduler to the PDF format, you should note that export of HTML elements is limited due to their possible insecurity.
There are HTML elements which are not entirely allowed for export, such as <canvas>
, <svg>
, <script>
and images with the src attribute that contains a Base64 image. However, there are safe ways of exporting images in the SVG and Base64 formats:
<img>
element with the src attribute that contains a URL of the image in the SVG format (suitable for the PNG and JPG formats, doesn't work for the Base64 format), e.g.:<img src=https://www.svgrepo.com/download/530597/hat.svg>
url
attribute with the link to the image or an image in the Base64 format as its value (suitable for the PNG/JPG/SVG formats).red {
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH1ggDCwMADQ4NnwAAAFVJREFUGJWNkMEJADEIBEcbSDkXUnfSgnBVeZ8LSAjiwjyEQXSFEIcHGP9oAi+H0Bymgx9MhxbFdZE2a0s9kTZdw01ZhhYkABSwgmf1Z6r1SNyfFf4BZ+ZUExcNUQUAAAAASUVORK5CYII=") 100%/contain no-repeat;
display: inline-block;
width: 32px;
height: 32px;
}
If you have an export module and you need to export HTML elements that are not supported by our online export server, you can submit a support request to get instructions on the changes you need to make in your module to remove restrictions. However, you should take into account that your server will be vulnerable to XSS-attacks.
Back to top