# Export to PDF (version 4.0)

*The article refers to exporting of dhtmlxScheduler 4.0 or earlier versions. If you use dhtmlxScheduler 4.1+, see details [here](export/pdf.md).*

Starting from version 4.1, dhtmlxScheduler provides a new approach for exporting the scheduler into the PDF format - 
an [online export service](export/pdf.md#default-export-to-pdf). 

## Installation 

The PHP version of the package: [https://github.com/DHTMLX/scheduler-to-pdf-php](https://github.com/DHTMLX/scheduler-to-pdf-php)
  
The Java version of the package: [https://github.com/DHTMLX/scheduler-to-pdf-java](https://github.com/DHTMLX/scheduler-to-pdf-java)
  
The .NET version of the package: [https://github.com/DHTMLX/scheduler-to-pdf-net](https://github.com/DHTMLX/scheduler-to-pdf-net)


[Export to PDF [Legacy]](https://docs.dhtmlx.com/scheduler/samples/04_export/05_standalone_export.html)


## Necessary includes 

On the scheduler page, enable one more extension:

~~~js
scheduler.plugins({
    pdf: true
});
~~~


## Triggering the export 

To export scheduler data to PDF, you just need to add on the page a button, which will call the **toPDF()** method. The parameter of the **toPDF()** method is the URL of the script, which has been installed previously:


~~~html
<input type="button" name="save" value="save" 
onclick="scheduler.toPDF('path/to/folder/generate.php')" 
style="right:300px; width:80px; position:absolute; top:1px;">

~~~


## Configuring service 

To configure the export options, you need to deal with both client and server sides.

### Client side 

As mentioned above, for export activation you should use the method **toPDF()**:

~~~js
scheduler.toPDF(path, color, header, footer);

~~~

**Parameters:**


- _**path**_ - (_url_) the path to the php file which generates PDF-file. See details [below](export/pdf.md#using-export-services).
- _**color**_ - (_'color', 'gray', 'bw', 'custom', 'fullcolor'_) specifies colormap.
    * '_color_' - full-color printing, default value.
    * '_gray_' - prints in shades of black and white.
    * '_bw_' - uses only black and white colors.
    * '_custom_' - can be used to enable a custom colormap ( requires php coding, see [below](export/pdf.md#using-export-services). 
    * '_fullcolor_' - actual background and text colors that are used while exporting.
- _**header**_ - (_boolean_, optional) defines whether a header will be added to the page. By default, _false_. See details [below](export/pdf.md#headerfooter-of-the-output-file).
- _**footer**_ - (_boolean_, optional) defines whether a footer will be added to the page. By default, _false_.
  
  See details [below](export/pdf.md#headerfooter-of-the-output-file).

So, to your HTML page add a code line that will call **toPDF()** method with the appropriate number of the parameters. For example, it may look like:

~~~js
scheduler.toPDF('path/to/folder/generate.php','gray');

~~~


## Server side

In the code snippet above _generate.php_ is a php file that defines export options.
  
  
The simplest sample of the file is:

~~~php
$scPDF = new schedulerPDF();
$scPDF->printScheduler($xml);

~~~


But before executing the **printScheduler()** method, you can apply some custom configuration options:

**Size of elements:**

~~~php
// the height of the header of the day container in the month mode
$scPDF->monthDayHeaderHeight = 6;
 // the height of the header in the month mode
$scPDF->monthHeaderHeight = 8;
 // the height of the month name container in the year mode
$scPDF->yearMonthHeaderHeight = 8;
 // height of the row in the agenda mode
$scPDF->agendaRowHeight = 6;
 // the height of the header in the day and week mode
$scPDF->dayTopHeight = 6;
 // the width of the left scale in the day and week mode
$scPDF->dayLeftWidth = 16;

~~~


**Font size:**

~~~php
 // font size settings
$scPDF->monthHeaderFontSize = 9;
$scPDF->monthDayHeaderFontSize = 8;
$scPDF->monthEventFontSize = 7;
$scPDF->yearHeaderFontSize = 8;
$scPDF->yearFontSize = 8;
$scPDF->agendaFontSize = 8;
$scPDF->dayHeaderFontSize = 7;
$scPDF->dayScaleFontSize = 8;
$scPDF->dayEventHeaderFontSize = 7;
$scPDF->dayEventBodyFontSize = 7;
$scPDF->todayFontSize = 11;

~~~


**Custom colors** (make sure, you use the 'custom' value as the name of the colormap on the client side):

~~~php
$scPDF->lineColor = '586A7E';
$scPDF->bgColor = 'C2D5FC';
$scPDF->dayHeaderColor = 'EBEFF4';
$scPDF->dayBodyColor = 'FFFFFF';
$scPDF->dayHeaderColorInactive = 'E2E3E6';
$scPDF->dayBodyColorInactive = 'ECECEC';
$scPDF->headerTextColor = '2F3A48';
$scPDF->textColor = '2F3A48';
$scPDF->eventTextColor = '887A2E';
$scPDF->eventBorderColor = 'B7A543';
$scPDF->eventColor = 'FFE763';
$scPDF->todayTextColor = '000000';
$scPDF->scaleColorOne = 'FCFEFC';
$scPDF->scaleColorTwo = 'DCE6F4';
$scPDF->yearDayColor = 'EBEFF4';
$scPDF->yearDayColorInactive = 'd6d6d6';

~~~

**Headers and footers:**

~~~php
// the height of the header
$scPDF->headerImgHeight = 40;
// the height of the footer
$scPDF->footerImgHeight = 40;
// the path to the header image
$scPDF->headerImg = './header.png';
// the path to the footer image
$scPDF->footerImg = './footer.png';
~~~


## Header and Footer 

It's possible to define custom header and footer for each page.
  
To achieve that, do the following steps: 


+ create images with the names  "_header.png_" and "_footer.png_".
+ copy those images to the same folder where _generate.php_ resides. 
+ on the client side, change the code's call as:
  
  
~~~js
scheduler.toPDF(url, "color", true, true);

~~~

As a result, you will have "_header.png_" and "_footer.png_" images as the header and footer on all pages in the generated PDF file. 

## Error reporting 

If output of PDF file is failed, there must be the file named as "error_report_xxxx.xml". Please, send this file with any bug-reports.

If output doesn't fail, but still has some problems, you can edit _generate.php_ and change

~~~php
$debug = false;

~~~

as

~~~php
$debug = true;

~~~

As a result, there will be a new file saved. It will be called like "debug_xxxxx.xml". Please, send it with the related error report. 
