Automatic PageBreak
Question
Hello, How can i implement automatic pageBreak on GrapeJs. I want a pageBreak every 500px for example. how can i do that ? Sincerly Thanks for your answer @artf
Answers (2)
@lebonsavane As far as I know there isn't a feature to do that currently.
I would create a custom component called 'Page', set 'removable' to false and this component would be added after the editor is loaded. So there would always be at least one page. You could specify the height of this custom component as a style parameter.
Then, you will need custom logic to determine when to add a new page. I think there are only two ways a content could go over the 'height limit'. 1. Current content is increased For example when a text component's content length is increased. 2. New content added Obviously when you drop a new component into a given page, if the current height + the new component's height is more than the height of a page you would need an additional page where the new component would be added.
For the first case you could listen to the 'component:styleUpdate:height' on every page component, and when the height exceeds the allowed height, you would have to split the text into two components and the push one part onto a new page.
The second case is fairly easily covered by listening to the 'component:drag:end' event(https://grapesjs.com/docs/api/editor.html#available-events) and then making the necessary adjustments(adding the component onto a new page if it is the last page, otherwise shift everything, multiple pages).
If you don't need such a 'hard page-break' you could get away with CSS styling and just visual breaks after a certain height.
I'm assuming that you would want to use grapesjs as a PDF/document editor and use pages? Unless you are prepared to make a lot of development, I would suggest to add new pages manually, however I do see a value in a 'document' mode for grapesjs, but it would be most likely a plugin rather then a core feature.
I hope this helps.
Probably this thing might help with the logic http://marcj.github.io/css-element-queries/ (by attaching the ResizeSensor on the wrapper)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2261
load local html file into grapesjs
hello i am pretty new to grapejs i want to load a local html file in the assets folder into grapesjs editor ,pls tellme how i can load loca...
Issue #1748
How to prevent drag items inside the editor
Hello @artf You are doing great job with grapesjs and it's extremely helpful to make our functionality more user friendly. Thanks for creat...
Issue #697
Question: Dropping external element into blocks
Hello, I want to drop external elements ( for example, tree view node) into blocks. Can you please help me out to show a way, how to achiev...
Issue #2742
[QUESTION] How to prevent unique ids generation?
Hi! Thanks for your work @artf. This is a simplified code of how I use grapesjs, I want to save the styles and then want to apply them agai...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.