You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to paged.js and I am having some blocking issues with an implementation.
Basically, I am using paged.js with prosemirror. I want to change content of the preview to add a TOC feature. I tried using beforeParsed hook but the content did not get changed. I tried using beforePreview hook also but it wasn't triggered (document did mention that issue, so maybe this won't work). I am sharing the code below for reference.
customHandler.ts:
import {Handler, registerHandlers} from 'pagedjs';
import createToc from './exportPdf';
export default class customHandler extends Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
beforeParsed(content) {
let abcd = 1;
// Modify the content structure for the print preview
const tocElement = createToc({
content: content,
tocElement: '.tocHead',
titleElements: ['Chapter Header', 'Header 2'],
});
// Replace the content with the modified structure
content = tocElement;
return content;
}
}
In preview.tsx, I am registering the handlers:
import {Previewer, registerHandlers} from 'pagedjs';
import customHandler from './customHandler';
componentDidMount(): void {
const {editorView} = this.props;
let divContainer = document.getElementById('holder');
this.dataTrial = this.getContainer(editorView);
let newDiv = document.createElement('div');
newDiv.classList.add('tocHead');
// 2. Get the dataTrial element
let dataTrial = this.getContainer(editorView);
dataTrial.insertBefore(newDiv, dataTrial.firstChild);
registerHandlers(customHandler);
let paged = new Previewer();
paged
.preview(dataTrial.outerHTML, [{cssPath: './ui/paged.css'}], divContainer)
.then((flow) => {
console.log('Rendered', flow.total, 'pages.');
});
}
Is there any issues with the code? Can anyone point me in the correct direction. Thanks!
The text was updated successfully, but these errors were encountered:
I am new to paged.js and I am having some blocking issues with an implementation.
Basically, I am using paged.js with prosemirror. I want to change content of the preview to add a TOC feature. I tried using beforeParsed hook but the content did not get changed. I tried using beforePreview hook also but it wasn't triggered (document did mention that issue, so maybe this won't work). I am sharing the code below for reference.
customHandler.ts:
In preview.tsx, I am registering the handlers:
Is there any issues with the code? Can anyone point me in the correct direction. Thanks!
The text was updated successfully, but these errors were encountered: