Integration with Export to PDF/Word
This guide is meant to be a point of reference for anyone integrating the Pagination
, Export to PDF
and Export to Word
features together. It describes the whole process from creating a custom editor and configuring it, up to the point of having a working solution.
We strongly advise you to get familiar with all three mentioned plugins’ user guides before reading this guide.
# Before you start
Pagination, Export to PDF and Export to Word are premium features. Please contact us if you would like to purchase a license. Let us know if you have any feedback or questions!
You can also sign up for the CKEditor Premium Features 30-day free trial.
# Accessing authorization data
Assuming you have signed up for the CKEditor Premium Features 30-day free trial or you already are a licensed user, you now need to get the authorization data from the CKEditor Ecosystem Dashboard.
To use the pagination feature you will need a license key to enable it in the editor. If this feature is used without it, the editor will initialize in a read-only mode, which prevents user from editing any content. Log in to your CKEditor Ecosystem Dashboard account and follow the guide on getting the license key.
For the export plugins you will need is a special token endpoint. In order to get it, log into your CKEditor Ecosystem Dashboard account and follow the guide on creating token URL. When export features are used without this token, all generated documents will contain a watermark at the bottom of every page.
After you have successfully obtained all the credentials needed, let’s create a custom editor and configure it.
# Creating a custom editor
For the purpose of this guide, we will create a simple editor from scratch. We will base the whole process on the quick start guide, but we will use a decoupled editor instead of classic. This guide assumes that you are familiar with npm and your project uses npm already.
First, install the packages needed to build CKEditor 5:
Next, create webpack.config.js
file with the following content:
Now let’s install all packages needed to actually create an editor:
With all the packages installed and the Webpack config taken care of, we can now proceed with creating our basic editor.
Create two files, first app.js
file:
And index.html
file:
The final step for this part of the guide is building the editor with the following command:
However, it will be more handy to add an npm script inside the package.json
file:
This way every time you will need to rebuild the editor, you can just run:
After the build process is complete, you can open the index.html
file (preferably using some simple server, like, for example http-server).
Now the editor is up and running, however it is very basic. In the next section we will add more plugins and see how to configure them properly.
# Configuration
# Installing additional plugins
Now it is time to install the @ckeditor/ckeditor5-pagination
, @ckeditor/ckeditor5-export-pdf
and @ckeditor/ckeditor5-export-word
packages using npm
. To use the full potential of the pagination plugin, we will also add the @ckeditor/ckeditor5-page-break
feature.
Apart from the plugins listed above, let’s add a few more and make our custom editor more versatile and rich:
Read more about this in the installing plugins guide.
Let’s update app.js
, which should now look like this:
# Adding proper configuration
Pagination configuration has to be in sync with the configuration of the exports plugins. All three configs need to have the same margin values and page format set. This is due to the handling of default editor styles which we will mention later. For the purpose of this guide, we will use A4 format but of course you can use other paper sizes as well.
You will also need to provide a license key for the pagination feature and also the Cloud Services configuration for the exports plugins (which you obtained in step one).
This guide assumes that we do not use any other plugin that needs a cloudServices
configuration. If we used, for example, real-time collaboration or the EasyImage plugin, we would have to provide all three values, which are: tokenUrl
, webSocketUrl
and uploadUrl
.
After the table
configuration add:
# Styling the editor
When using the decoupled editor (document editor), you need to make sure that the editor styles match precisely the configuration options that you provided to the feature and to the export to PDF or export to Word features. Additionally, we just want the editor to look good.
To address this issue, let’s create a new styles.css
file the following declarations:
# Styling the content
Apart from styling the editor’s editable element, there are also styles that control how the content inside the editor looks. When using the pagination feature together with export to PDF and export to Word, you need to make sure that these styles are sent to the converters (which means they will be actually applied to the content when generating the document) and that they do not create a discrepancy between the pagination lines in the editor and page breaks in the generated document.
Currently, our exports and pagination features use only default editor styles, which in case of PDF/Word export configs are defined as:
This means that only the default CKEditor styles are sent to the converter when generating the PDF/Word document. This default configuration might be enough in some simple scenarios, but more often than not it will need some adjustments (depending on the content that you create and the environment in which you use the editor).
We will now add a few declarations, that are specific to the pagination plugin and also adjust the line height:
To send the file with custom styles to the converter, update the PDF/Word export configurations like this:
And also do not forget to import the CSS file inside app.js
:
After updating the configuration and adding styles, rebuild the editor again:
You can read more about sending styles to the server in the troubleshooting section of Pagination overview.
# Demo
Presented below is a sample editor with the pagination
, export to PDF
and export to Word
features enabled (keep in mind, however, that this demo might be slightly different than the editor you just built because of the fonts and other styling, that is specific to the whole documentation page):
# Full implementation
After following this guide and building the editor, your application should now have the following structure:
# app.js
:
# index.html
:
# styles.css
:
# Troubleshooting
Please keep in mind that each of the plugins used in this guide has some known issues - this could be partial or missing support for other CKEditor 5 plugins, partial browser support, some known bugs, etc. When combined, these sometimes might cause problems for certain more complicated use cases. We strongly advise to go through all Known issues sections in the features’ respective documentation pages and make sure that you understand all their limitations.
If you would like to report a bug or propose enhancements for these plugins, we encourage you to use the CKEditor 5 issue tracker. If you would like to use CKEditor 5 as a part of a commercial solution or have a request for custom development, feel free to contact us through our support channel - our team will make sure to answer all your questions.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.