# Produce PDF reports (Xreport)

Spark can produce a PDF for selected worksheets. This is useful if calculations need to be included in a document as the final output. Spark is NOT designed to be a replacement for a document processing solution.

## Map the report

Syntax: `Xreport_<parameter>`

1. Define the [Print Area](https://support.microsoft.com/en-us/office/set-or-clear-a-print-area-on-a-worksheet-27048af8-a321-416d-ba1b-e99ae2182a7e) for the target sheets.
   * Print areas can include multiple pages.
   * Ensure that each `Xreport` worksheet has a worksheet scope variable called `Print_Area`.
   * It is suggested to add an extra row and column of padding around any cells with large text.
   * Please do not include any `Xinput`s in the worksheet - these will not be rendered correctly.
   * Spark does not support `Print_Area` ranges that are dynamically defined using formulas.
2. Rename the worksheet(s) to include the `Xreport` prefix. The name must match the above syntax exactly.
3. Upload the service to Spark and view the [API Tester](/navigation/api-tester.md).
4. In the *API request* *Field view*, there will be a list of all the `Xreport`s that have been defined in the workbook.
5. Next to the *Report Name* field, there is a *File Name* field, which corresponds to the `FileName` parameter of the API request. Enter the desired filename here (`customfilename.pdf` in the example above) to customize the filename of the resulting PDF. If no filename is provided then a UUID is used for the filename.
6. Click **Submit** to make the API request.
7. A hyperlink to the resulting PDF report can be found by expanding the response *Reports* section. The link can also be found in the *JSON view* and *Raw view*.
8. It is strongly recommended to inspect the PDF to ensure the contents match the intended outcome.

## Supported fonts

`Xreport` supports the following fonts:

* *AR PL UMing* (Chinese)
* *Angsana* (Thai)
* *Arial* (Default font)
* *Garuda* (Thai)
* *Halant* (Devanagari script)
* *HK Grotesque*
* *Montserrat*
* *Noto Sans CJK Regular* (Chinese/Japanese/Korean)
* *Open Sans*

If Spark detects any font other than the ones listed above, it will use the *Arial* font.

## **Example of `Xreport` mapping**

This service can be uploaded to Spark to use as a simple example.

{% file src="/files/PL0FH0qMyYv6pS0U3OgA" %}

## **Exclude certain rows in the report**

It is common to have Excel output content that may vary in length depending on the amount of data and number of calculations. If the content is shorter, it may be desirable to exclude extra empty pages at the end of the output.

Whether a row is included in an `Xreport` can be controlled by inserting a column within the Print Area with the heading `Hide in Report Output`. Within this column a value of `FALSE` will exclude that row from being included in the report.

This service can be uploaded to Spark to use as a simple example.

{% file src="/files/Evf8Sc4vD6P6TWLtI1qa" %}

## Include charts with `Xreport` PDF documents

{% hint style="warning" %}
Not all chart types are supported by Spark.
{% endhint %}

`Xreport`  is able to include charts into the published PDF documents. To make the data series for a chart visible, the data series must reference data that is within the `Xreport` worksheet's defined `Print_Area`.

## Control how  `Xreport` sheets are processed

[Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md) [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md#request_meta) `xreport_options` includes additional parameters to control how [Produce PDF reports (Xreport)](/build-spark-services/other-mapping-options/produce-pdf-reports.md) are produced.

* If no `xreport_options` are used in the request, the default is `{ "produce_pdfs": true, "multiple_docs": true, "page_numbers": true }` .
* By default, a Spark service with `Xreport` will return a PDF document on each execution. However, this may not be desirable for a more rapid response or if the PDF document is not required. Whether a PDF is returned is determined by the value of `produce_pdfs`.
* If `xreport_options` are used in the request, then the default is `"multiple_docs": false` . If a workbook has multiple worksheets tagged as `Xreport`, `multiple_docs` controls whether Spark will return one combined PDF or separate PDF documents for each `Xreport` worksheet.
* `page_numbers` controls whether the default page numbers will be included into the PDF documents.

## Change images displayed based upon an input

It may be desirable to change a particular image such as a logo upon different `Xinput` values. This file offers an example of how it can be done.

* Make sure that all the formulas that resolve the image are within the `Xreport` worksheet `PrintArea` named range.

{% file src="/files/6kuiDtlp6Cnc0O4Uiuiu" %}

## Troubleshoot `Xreport` inconsistencies

We have observed that saving Excel workbooks using different Windows Display Scaling settings (e.g. `100%`, `125%`, `150%`, etc., see [Display settings in Windows](https://support.microsoft.com/en-us/windows/change-your-screen-resolution-and-layout-in-windows-5effefe3-2eac-e306-0b5d-2073b765876b)) can lead to slightly different margin widths. When uploaded to Spark, this may lead to `Xreport` not rendering as intended by the user.

If you are experiencing margins shift between different iterations of a Spark service, check that all contributors are using a consistent Windows Display Scaling setting.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coherent.global/build-spark-services/other-mapping-options/produce-pdf-reports.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
