Forum How do I...?

Generate only layout

Miquik
Hello everybody,

I have a JS application with a nodejs backend that calls Prince to generate pdf of working document. I would like to implement a “real-time preview” of document on client-side (I’m mainly interest to have correct layout of pages).
Now, Prince is really fast but not so fast to generate an almost real-time layout, and that lead me to a poor “user-experience”.

Is there some I should try to increment speed (i’m not interesting in quality at this point).

Or better, is it possible to tell Prince to only generate layout (pdfboxes) without render pdf?

Thanks
mikeday
It is possible to tell Prince not to generate the PDF with some JavaScript like this:
Prince.trackBoxes = true;
Prince.registerPostLayoutFunc(function() {
    Prince.failStatus = true;
    for (let page of PDF.pages) {
        dump(page);
    }
});

function dump(box) {
    console.log(box);
}

However dumping all the box details will end up taking about the same time as just generating the PDF unless the PDF is applying a lot of expensive image filters or something like that.

How often do you need to update the layout? I don't think it's going to be practical to do it on every keystroke as the user is typing.
Miquik
Thanks mikeday,
No, layout will be update when user click on an “update” button, the “problem” is delay between click and result.

I’m also investigating control protocol to see if there is some performance increase.

In this case I have another question: html source (job-resource) can be html content or just html file?
mikeday
The control protocol allows you to send the HTML content directly to Prince without needing to save it as a file, please see the Java and C# wrappers for examples of this.

Perhaps if the user hasn't done anything for a while it can run Prince in the background so that the PDF is already ready when they click update. :)
Miquik
Yes, that was also my idea. Anyway translating those wrappers in nodejs is not so easy
Miquik
Is it possible (maybe through registerPostLayoutFunc) tell Prince not to include image content but just create placeholder (with correct position/size) for images?
mikeday
Hmm I don't think this is possible yet; perhaps if Prince supported more of the HTMLImageElement DOM API then it could be done with a script prior to typesetting that replaced the image with a blank canvas of the same size.