Editor Sessions
Introduction & Overview
CraftMyPDF's PDF editor solution supports embedding of our template editor right into your application. Our easy-to-use PDF template editor allows your customers to customize PDF templates and create pixel-perfect PDF documents.
The integration is cost-effective, seamless and easy - you just need to create an iframe page and make use of our REST API to create an editor-session. An editor-session provides a unique URL for embedding the PDF template editor in an iframe.
These sessions can be customized to control which features and functionality are available to users.
Key benefits:
- Embed the PDF editor directly in your application and give users freedom to edit their templates
- Customize the editor interface and capabilities
- Control user permissions and access
- Create time-limited editing sessions
- Reduce development costs
Prerequisites
Before you begin integrating the PDF editor, ensure you have the following requirements in place.
- CraftMyPDF API key
- Template ID for the PDF template you want to edit
- Basic knowledge of REST APIs
Steps to Create a Editor Session
Step 1. Configure the Editor Session Parameters
The first step involves setting up the configuration for your editor session. This determines what features and capabilities will be available to users when they access the editor.
Here is the editor session configuration:
{
template_id: YOUR_TEMPLATE_ID,
expiration: 1440, // Session duration in minutes (24 hours)
canSave: true,
canCreatePDF: true,
canViewSettings: true,
canPreview: true,
canEditJSON: true,
canShowHeader: true,
canShowLayers: true,
canShowPropertyPanel: true,
backURL: https://your-app.com/back
}
Key configuration options:
- template_id: The ID of your PDF template
- expiration: How long the session should remain active (in minutes)
- canSave: Allow saving template changes
- canCreatePDF: Allow PDF generation
- canEditJSON: Allow editing of JSON data
- backURL: URL to return to when clicking “Back”
Step 2. Create the Editor Session
Once you have your configuration ready, you'll need to make an API call to create the actual editor session.
Make a POST request to the create-editor-session endpoint:
curl -X POST \
--header Content-Type: application/json \
--header X-API-KEY: YOUR_API_KEY \
--data '{
template_id: YOUR_TEMPLATE_ID,
expiration: 1440,
canSave: true,
canCreatePDF: true,
canViewSettings: true,
canPreview: true,
canEditJSON: true,
canShowHeader: true
}' \
https://api.craftmypdf.com/v1/create-editor-session
Step 3. Handle the API Response
After creating the session, you'll receive a response containing important information about the session.
The API will return a response containing the editor session URL:
{
status: success,
url: https://craftmypdf.com/designer/?template_id=...&session_token=...,
expire_after_unix_timestamp: 1674097492,
expire_after: 2023-01-19T03:04:51.811Z,
token_uuid: 66b0e71d-5a72-4fee-b4a5-7f1713fd2fb5
}
Step 4. Embed the Editor
The final step is to integrate the editor into your application's interface. This is done by embedding the provided URL in an iframe within your application.
Add an iframe to your application using the returned URL:
<iframe src=EDITOR_SESSION_URL
width=100%
height=800px
frameborder=0
></iframe>
Considerations
Here are important aspects to consider when implementing the PDF editor:
- Editor sessions are temporary and expire after the configured duration
- Sessions can be deactivated early using the deactivate-editor-session endpoint
- Configure only the permissions needed for your use case
- Use HTTPS for secure communication
Additional Features
Beyond the basic implementation, CraftMyPDF offers several advanced features:
- jsonMode: Set JSON editor mode (1) or viewer mode (2)
- canShowHelp: Show/hide help documentation
- canShowData: Show/hide data tab
- canShowPropertyBinding: Show/hide property binding options
- canShowExpressionDoc: Show/hide expression documentation
Demo
Here is a demo app for creating editor session
https://app.craftmypdf.com/static/app-editor-session-demo/
Conclusion
Creating editor sessions with CraftMyPDF allows you to provide a seamless PDF editing experience within your application.
By carefully configuring the session parameters, you can control exactly how users interact with the editor while maintaining security and usability.
For more information, visit CraftMyPDF’s documentation.