asciidoctor / asciidoctor-intellij-plugin

AsciiDoc plugin for products on the IntelliJ platform (IDEA, RubyMine, etc)
https://intellij-asciidoc-plugin.ahus1.de/
Apache License 2.0
355 stars 145 forks source link

Use JCEF integration/preview to render a PDF #592

Open ahus1 opened 3 years ago

ahus1 commented 3 years ago

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.

ahus1 commented 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?

image

ggrossetie commented 3 years ago

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?

ahus1 commented 3 years ago

Hm, here my thoughts on these options:

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].

ahus1 commented 3 years ago

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