EditorJS to DOCX/PDF
Exporting Reports from the HTML WYSIWYG Tool EditorJS Convert the JSON output of Editor.js to a PDF with Carbone
- Template type document docx simple
- Carbone min. v4.0.0+
- Features array filter
- Target editorjs conversion custom
Objectives
Convert the JSON output of Editor.js to a PDF using Carbone, with the following features:
- Header, title, subtitle
- Paragraph, Html
- List, table
- Annex, image
Solution
The best approach is to use a template with a main structure based on a table, where each style is predefined and conditionally displayed as needed.
Here’s how to construct a template to achieve this with Carbone:
Create a global table
Insert a table with a single column that spans the full width of the page.
Configure it with no borders for better integration.
Create a row per style
For each style (e.g., paragraph, header, list, table...), define a row to specify the format settings
Set parameters such as font, indentation and spacing within the Carbone tag
Example:
{d.blocks[i].data.text}
Test the type to keep the line if it matches
In each cell, use ifEQ formatter to test the data and control the display
Example:
{d.blocks[i].type:ifEQ('paragraph'):keep(row)}
And there you go!
Trusted by 600+ paid customers in 40+ countries














