---
title: "Exporting to PDF with K15t PDF Exporter"
canonical: "https://support.appfire.com/space/CDML/649859695/Exporting%20to%20PDF%20with%20K15t%20PDF%20Exporter"
format: markdown
---
> Macro (aura-html)


## Overview

> Macro (excerpt)
> 
> Export PDF macro and example of the use of `pdf-export-success` and `pdf-export-error` event triggers

<span style="color: #172b4d">This example requires the installation of the </span>[Scroll PDF Exporter app](https://marketplace.atlassian.com/apps/7019/scroll-pdf-exporter-for-confluence/version-history).

<span style="color: #172b4d">Once installed, the Comala </span><span style="color: #3366ff">**[pdf-export macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649955790)**</span><span style="color: #172b4d"> can be used as an </span>[action in a trigger macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649859133)<span style="color: #172b4d"> to </span>export a page or blog post in PDF format. The exported PDF is<span style="color: #172b4d"> </span>added to the page as an attachment<span style="color: #172b4d">.</span>

## Basic Example

```
{workflow:name=PDF export}
    {description}
        Pdf export macro example workflow
    {description}
    {state:Review|approved=Published|rejected=Review}
        {approval:Approve For Export}
    {state}
    {state:Published|final=true|submit=Review}
    {state}
    {trigger:pageapproved|approval=Approve For Export}
        {pdf-export}
    {trigger}
{workflow}
```

In this example, the **approved** decision will transition the content to the **Published** state.

When the **Approve for Export **content review is approved, the content is also exported as a pdf file and added to the content as an attachment

The transition does not wait for the pdf export of the content as a pdf and its addition as an attachment.

The export may take some time - it is queued in Confluence.

- the successful completion of the pdf export will be seen when the pdf is added as an attachment

![image](media://cd689133-1223-4ed0-aaa9-9c82405f6a49)

## Using `pdf-export` macro events

The [pdf-export macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649955790) action generates the workflow event `pdf-export-success`. This event occurs when the PDF export is successful.

This workflow [event](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649759655) can be used to help confirm the success of the PDF export.

A simple way is to add an on-screen message when the event is triggered.

```
{trigger:pdf-export-success}
        {set-message:style=info|duration=PT1M}
        ||PDF export completed|@datetime@|
        ||See| @attachmentURL@|
        {set-message}
{trigger}
```

This would display a confirmation message, the attachment URL, and the date and time the export was completed.

![image](media://0b694ac2-92d9-447f-b6cb-7f77e435d957)

A second workflow event can also be generated by the [pdf-export macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649955790), the `pdf-export-error `event.

This event occurs if the PDF export fails.

Again, this can be used, for example, to generate a custom notification.

```
{trigger:pdf-export-error}
        {set-message}
        There was an error in the pdf export @errormessage@
		{set-message}
{trigger}
```

The value reference `@errormessage@` in the `set-message` content displays the value for actual error recorded by Confluence.

![image](media://539e043b-482e-40c4-89b1-c07ff2ff0bdc)

This Confluence error message is also displayed, but can be removed by a user.

![image](media://8d02bceb-03f6-40d9-82dd-c3b3810217f6)

In this simple example, the actions of the [pdf-export macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649955790) are not recorded in the page activity report for the content  


![image](media://4eb09a77-557f-4505-881e-f0c8c3afa01a)

The on-screen message notifications might not appear on the transition to the **Published** state, as the PDF export is an asynchronous event and can take some time to be completed

## Manage the PDF export and add details to the page activity report

The [pdf-export macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649955790) events can be used in one or more triggers to

- Display a notification that content is being exported
- Add details of the PDF export to the page activity report
- Transition on the success of the PDF export

Remove the approval transition for the **approved** decision from the **Review** state. 

```
{state:Review|rejected=Review}
        {approval:Approve For Export}
{state}
```

  
An **approved** decision for the** Approve for Export** approval will now **NOT** action a content review transition. 

The `pageapproved` event trigger is still used to activate the `pdf-export` macro, but before the [pdf-export macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649955790), an on-screen message notification is added.

```
{trigger:pageapproved|approval=Approve For Export}
		{set-message}
		This content is currently being exported to pdf
		{set-message}
        {pdf-export}
{trigger}
```

The content now remains in the **Review** state after an approved decision.

![image](media://6167d912-1808-492d-acf2-5945b4b2e6af)

A transition is set to occur as an action in a `pdf-export-success` event trigger.

```
{trigger:pdf-export-success}
	{set-message:style=success|duration=PT2M}
	 PDF export completed!
	{set-message}
	{set-state:Published|comment=Approved page exported as pdf - see @attachmentURL@}
{trigger}
```

Completion of the PDF export causes the `pdf-export-success` event trigger to transition the content to the **Published** state using the **[set-state](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649727251)**[ macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649727251).

![image](media://94a659f9-9400-455d-abc7-dc1fa5e2a735)

The page activity report includes details of the PDF export that were added as the `comment` parameter value for the **[set-state](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649727251)**[ macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649727251).

![image](media://cc90fd33-dfdf-4565-af78-acf93d37519a)

## Create a '**waiting**' state for PDF export

<span style="color: #172b4d">Exporting to PDF can take some time. You can find it useful to have a 'waiting' state - a workflow state to wait for the completion of the PDF</span> export.

```
{state:Review|approved=Export PDF|rejected=Review}
        {approval:Approve For Export}
{state}
{state:Export PDF|submit=Published|description=Content is being exported to pdf, please wait ...|hideselection=true}
{state}
```

The **approved** decision in the Review state now causes the content to transition to the **Export PDF** state.

![image](media://2c60f2b3-ac8f-4a63-b116-cf36bc5edf73)

- `pageapproved` event trigger is still used to activate the `pdf-export` macro and add the on-screen message
- `pdf-export-success` event trigger is still used to transition the content to the **Published** state and add the details of the PDF export to the page activity report

A user can also simply move of this waiting state by choosing **Submit** to transition to the **Published** state. The `pdf-export-success` event trigger is still activated on the successful export of the PDF

## Create an '**error**' state

If the PDF export fails - for example, the K15t app can be disabled for the instance or space. It can be useful to create and use a workflow state to manage the export error.

The transition to the **Error** state is set to only occur if the `pdf-export-error `event occurs.

```
{trigger:pdf-export-error}
        {set-message}
        PDF export failed
		{set-message}
		{set-state:Error|comment=PDF export failed - @errormessage@}
{trigger}
```

  
The **Error** state will need to be added to the workflow. A review can be added to allow a user to decide if the export should be tried again or the error ignored and transition to the **Published** state.

![image](media://26b239c5-24cd-4a66-a0d5-17c8c0eeb5ad)

You can:

- Use the same approval name as the **Review** state approval, and the `pageapproved` trigger listens for the approval event in each state approval

- Customize the content review buttons displayed in the workflow state dialog box to help the user understand the content review decisions

```
{state:Error|approved=Export PDF|rejected=Published|description=PDF export failed. What do you want to do?|hidefrompath=true|color=#ff0000}
	{approval:Approve for Export|approvelabel=Retry Export|rejectlabel=Ignore Error}
{state}
```

  
The document activity report includes details from the `comment `parameter value for the **[set-state](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649727251)**[ macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649727251).

![image](media://e13e525e-5eb7-4189-b3b2-76833f78a0c8)

## Example complete workflow with '**waiting**' and '**error**' states

```
{workflow:name=Pdf Export workflow}
    {description}
        Pdf export macro example workflow with waiting Export for PDF state and Error state
    {description}
    {state:Review|approved=Export PDF|rejected=Review|colour=#0052CC}
        {approval:Approve For Export}
    {state}
    {state:Export PDF|submit=Published|description=Content is being exported to pdf, please wait ...|hideselection=true}
    {state}
    {state:Error|approved=Export PDF|rejected=Published|description=PDF export failed. What do you want to do?|hidefrompath=true|colour=#ff0000}
        {approval:Approve for Export|approvelabel=Retry Export|rejectlabel=Ignore Error}
    {state}
    {state:Published|final=true|submit=Review|updated=Review}
    {state}
    {trigger:pageapproved|approval=Approve For Export}
        {set-message} This content is currently being exported to pdf{set-message}
        {pdf-export}
    {trigger}
    {trigger:pdf-export-success}
        {set-message:style=success|duration=PT2M}
        PDF export completed!
        {set-message}
        {set-state:Published|comment=Approved page exported as pdf - see @attachmentURL@}
    {trigger}
    {trigger:pdf-export-error}
        {set-message}
        PDF export failed
        {set-message}
        {set-state:Error|comment=PDF export failed - @errormessage@}
    {trigger}
{workflow}
```

##   
See also

- [pdf-export macro](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649955790)
- [K15t Scroll PDF Exporter](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649923655)