Open ahus1 opened 3 years ago
@Mogztter - I did a first PoC to create a PDF from the JCEF preview. Works so far in a PoC stage.
There is a new button Web PDF in the toolbar. It is visible only if JCEF is active and internal mode is active. "Internal mode" is always active when you start the plugin when developing. Users can enable it manually as well, see the SDK DevGuide.
Once the PDF is created, the IDE opens it in the system's PDF viewer. The usual "Windows" effect: if the file is already open in a PDF viewer like Adobe Acrobat Reader, you need to close Adobe Acrobat Reader first to re-create the file.
I'm not sure how practical it is to use the real preview to create a PDF, but it's a start. Do you have suggestions where to go from here?
Wow this is nice! 👏 I believe that you are using the built-in HTML 5 converter (not the converter included in Asciidoctor Web PDF) right?
The usual "Windows" effect: if the file is already open in a PDF viewer like Adobe Acrobat Reader, you need to close Adobe Acrobat Reader first to re-create the file.
Windows strikes again! I do have the same issue with the CLI, it's annoying but what can we do...
I'm not sure how practical it is to use the real preview to create a PDF, but it's a start. Do you have suggestions where to go from here?
What do you mean by real preview? I think it could be nice to show the printable HTML preview. With a few lines of CSS you can display a nice preview with two pages side by side or linear pages. But we can do that later. I think the next step would be to use the converter from Asciidoctor Web PDF written in JavaScript. The easy way would probably to run the converter in the JCEF browser? Adding the GraalVM JavaScript engine would add significant "weight". Do you know if the Nashorn engine is available/packaged by default in the Intellij IDEA distribution?
Hm, here my thoughts on these options:
Browser: Running everything in a browser would be an option. I don't know how much re-work would be required to do that. There is a bridge from Java to JavaScript (I suppose that will be needed), and from JavaScript back to Java (don't know if that will be needed, but might be helpful to trigger callbacks). I used this APIs to render the preview, and I am happy to try out to do other things with it.
GraalVM: Would it be possible to package Asciidoctor-Web-PDF in a single-file executable that converts an AsciiDoc file to HTML, and leaves the HTML->PDF to the IntelliJ plugin and JCEF? Running it as stand-alone executable would allow no integration into IntelliJ IMHO (mabe a little HTML post processing, but that's it). I could add this as a on-demand download (as I did for plantuml and asciidoctor-pdf). I haven't worked with GraalVM before (neither Java nor JavaScript), so my knowledge is non-existant.
Java Re-implement the logic of Asciidoctor-Web-PDF's document-converter.js to make best use of PlantUML integration and Antora xref/include resolving, building on top of the JRuby runtime (like the current preview). First I thought that Asciidoctor-Web-PDF is all about adding header/footer including CSS and JavaScript to some HTML created by the standard converter. Now I see that it contains some more parts. Hm.
Nashorn is deprecated as of Java 11 and will be removed in Java 15, therefore I would consider it out-of-scope here.
I could need some help to decide whether it should be Browser, GraalVM or Java; including the design of a solution how the different moving parts come together. Please ping me if you are up for a design session during a late afternoon/evening [CEST timezone].
The latest version of asciidoctor-web-pdf ships pre-compiled binaries. It might be worth a try to download these on-demand and use them to create a PDF.
https://github.com/Mogztter/asciidoctor-web-pdf/releases/tag/v1.0.0-alpha.12
Why the new feature should be added
JCEF could provide a foundation to create PDFs using asciidoctor-web-pdf from the preview as an alternative to asciidoctor-pdf. This could support alternative layouts on CSS .
How the new feature should work
A new button in the toolbar to create a PDF from the preview. As with the current PDF integration the PDF would be placed in the documents current folder.
Thanks for @Mogztter for bringing up this idea.