Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a PDF "inside" the Asciidoctor IntelliJ plugin #325

Closed
tindlebaum opened this issue Aug 29, 2019 · 17 comments
Closed

Generate a PDF "inside" the Asciidoctor IntelliJ plugin #325

tindlebaum opened this issue Aug 29, 2019 · 17 comments
Assignees

Comments

@tindlebaum
Copy link

Is it possible to generate a PDF directly from the Asciidoctor plugin? (Similar to AsciidocFX?).

Thank you.

@ahus1 ahus1 self-assigned this Aug 29, 2019
@ahus1
Copy link
Contributor

ahus1 commented Aug 29, 2019

Not yet, but it looks like a reasonable thing to add. I'll have a look.

@ahus1 ahus1 changed the title Is it possible to generate a PDF "inside" the Asciidoctor plugin? Generate a PDF "inside" the Asciidoctor IntelliJ plugin Sep 1, 2019
@ahus1
Copy link
Contributor

ahus1 commented Sep 1, 2019

This feature is available in the pre-release 0.30.0 of this plugin. From the docs:

The user can choose Create PDF from current file to convert the file in the current AsciiDoc editor to a PDF using AsciiDoctor PDF version 1.5.0-beta.2.
For now contents in .asciidoctorconfig are not automatically included when creating a PDF.
You'll have to include this file manually.
If creating the PDF succeeds, the PDF is opened in the system's PDF viewer.
To find out more how to configure the output and formatting, please visit https://asciidoctor.org/docs/asciidoctor-pdf/.

You'll find a new button to create a PDF in the action tool bar of the editor.

create-pdf

You find an example with PDF styling I've tested in one of my demo repositories: https://github.com/ahus1/asciidoctor-deepdive/blob/master/manual/src/main/asciidoc/manual.adoc

As usually I'm looking forward to feedback. As this feature is experimental, it might change its behavior according to user feedback.

The new pre-release of the plugin is available from GitHub releases and the IntelliJ AsciiDoc EAP repository.

@luvarqpp
Copy link

luvarqpp commented Sep 2, 2019

Hi @ahus1 ,
I have tried this and it have failed silently...

In "Event Log" I see two messages after click on "PDF" button:

6:30	Message during rendering api.adoc: Error during rendering api.adoc; FATAL  unable to read file

6:30	Error during rendering api.adoc
		unable to render AsciiDoc document
		java.lang.RuntimeException: unable to read file
		java.io.FileNotFoundException: asciidoctor-pdf (No such file or directory)
		(the full exception stack trace is available in the IDE's log file. Visit menu item 'Help | Show Log in Explorer' to see the log)

Than I have searched for "Show Log in Explorer" and I have no such menutitem in help menu. Nor "find action" know it.

I have clicked on "Show Log in Files" and it has taken me to some file-browser where I have opened log file. Its content is here:

2019-09-02 06:30:03,777 [ 707790]   INFO - rationStore.ComponentStoreImpl - Saving Project '/home/user/workspace/someProject' UnknownlibraryTable took 25 ms 
2019-09-02 06:30:03,778 [ 707791]   WARN - org.asciidoc.intellij.AsciiDoc - unable to render AsciiDoc document 
java.lang.RuntimeException: unable to read file
	at org.asciidoc.intellij.AsciiDoc.calcMd(AsciiDoc.java:207)
	at org.asciidoc.intellij.AsciiDoc.initWithExtensions(AsciiDoc.java:112)
	at org.asciidoc.intellij.AsciiDoc.renderPdf(AsciiDoc.java:422)
	at org.asciidoc.intellij.actions.asciidoc.CreatePdfAction.lambda$null$0(CreatePdfAction.java:72)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:591)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:537)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:59)
	at org.asciidoc.intellij.actions.asciidoc.CreatePdfAction.lambda$actionPerformed$1(CreatePdfAction.java:57)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:994)
	at org.asciidoc.intellij.actions.asciidoc.CreatePdfAction.actionPerformed(CreatePdfAction.java:56)
	at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:265)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:282)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAwareWithCallbacks(ActionUtil.java:256)
	at com.intellij.openapi.actionSystem.impl.ActionButton.actionPerformed(ActionButton.java:194)
	at com.intellij.openapi.actionSystem.impl.ActionButton.performAction(ActionButton.java:157)
	at com.intellij.openapi.actionSystem.impl.ActionButton.processMouseEvent(ActionButton.java:434)
	at java.desktop/java.awt.Component.processEvent(Component.java:6416)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5026)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4858)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4858)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:817)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:762)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:405)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:704)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:404)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.io.FileNotFoundException: asciidoctor-pdf (No such file or directory)
	at java.base/java.io.FileInputStream.open0(Native Method)
	at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
	at org.asciidoc.intellij.AsciiDoc.calcMd(AsciiDoc.java:193)
	... 48 more

I hope, this will help making this functionality work even for non-standard set-ups. Have on mind, that I have tried this on spring-docs project which require custom extension which you have improved a few weeks ago, #310.

@ahus1
Copy link
Contributor

ahus1 commented Sep 2, 2019

@luvarqpp - thanks for giving it a try. I triggered the build of another pre-release 0.30.1 that will prevent the exception you've seen above.
But this still doesn't support the .asciidoctorconfig files yet, and this is essential to set the snippets attribute. I have to make a decision on how to support this.

I will continue to look into this and will update the ticket once it is ready for a test run with spring-rest-docs.

@luvarqpp
Copy link

luvarqpp commented Sep 2, 2019

@ahus1 thanks for fast fix. Feedback:

  • file not found -> fixed (I have also installed asciidoctor-pdf just before upgrade of plugin... gem install asciidoctor-pdf --pre)
  • is it possible to somehow improve speed of download of new plugin update? It is slowest among any plugin I have updated in last few months (I have slower network, ~15mbps)
  • after copying .asciidoctorconfig to begining of my main document, generation has been mostly successful. Only missing snippets like this: Snippet http-request not found at {asciidoctorconfigdir}/target/generated-snippets/testCases/get/http-request.adoc for operation testCases/get and also include files 9:40 Message during rendering api.adoc: Error during rendering api.adoc; ERROR /home/luvar/workspace/qaronBackend/src/main/asciidoc/parts/_TestCaseEntity.adoc:59 include file not found: /home/luvar/workspace/qaronBackend/src/main/asciidoc/parts/{asciidoctorconfigdir}/src/test/java/sk/qpp/qaron/repository/TestCaseLifecycleHttpTest.java
  • a bit weird is that pdf file will appear next to adoc source file. I have maven project, where I have src directory and all outputs I expect to appear in "target" directory. In groovy project I would search in "build" directory. What about to ask (for the first time for each adoc file), where result should be saved? Or optionally make possible to pop-up "save-as" dialog after click on pdf button.

Thanks for great work.

@ahus1
Copy link
Contributor

ahus1 commented Sep 3, 2019

@luvarqpp - you don't need to install asciidoctor-pdf in order to create PDFs with the plugin. Everything is included in the plugin already.

Support for .asciidoctorconfig

Version 0.30.2 is now available as a pre-release that adds support for .asciidoctorconfig files. This should also fix the remaining errors you received when copying the contents to the beginning of your file that resulted from asciidoctorconfigdir being not set (it is set automatically by the plugin for the context of each .asciidoctorconfig file).

Download size/speed of the plugin

The AsciiDoc plugin for IntelliJ (this plugin) is quite "fat" as it includes a JRuby runtime to run Asciidoctor, plantuml plus dependencies for Diagrams, MathML for math formula rendering in the preview, fonts for the preview.

Adding PDF support by adding asciidoctor-pdf increased the size of the plugin from 44 MB to 48 MB.
The download size makes the download appear slow.

I know this is only an explanation of how it is today, not a solution for you. You might want to build it locally, as it will download the "big" elements only once. For building it downloads a full IntelliJ plus runtime, so this pays off only after multiple builds. And it lacks a lot of convenience of update notifications and "official" builds. Therefore I don't recommend it.

Weird Placement of PDF

The plugin doesn't know about Maven or Gradle project structures yet. I'd like to split this off to a different ticket once this is closed. Picking the "right" output folder (plus the right sub directory) might be an issue for a debate. Let's see where this issue ends up - before or after out-of-the-box spring-rest-docs support.

@luvarqpp
Copy link

luvarqpp commented Sep 4, 2019

@ahus1 Thanks for reply and all information.

According to download size/speed of plugin, is there any possibility to solve it by not downloading same things more times? i.e.:

  • make JRuby (and other dependencies) to be separate InteliJ plugin and be used as dependency for asciidoctor-intelij-plugin
  • download dependencies by plugin to some common directory (i.e. .m2/repository, or .IdeaIC2019.2/system/extResources)
  • use diff/patch for plugin updates (is it possible?) like Idea is using when minor version upgrade is done

Sidenote, what about to add this project to list located here? https://github.com/JetBrains/gradle-intellij-plugin/blob/master/README.md#examples

@ahus1
Copy link
Contributor

ahus1 commented Sep 6, 2019

Thank you for sharing these ideas. Using plugins to depend on plugins would using a mechanism that wasn't designed to support the proper needs: AFAIK the mechanism doesn't supply versioning of dependencies, and the plugin might end up with a wrong version of JRuby.

I know that some plugins download dependencies after they've been installed. Usually they do this for optional dependencies; in our case JRuby would be an essential dependency. Downloading dependencies after the installation usually gives rise to proxy issues. If you don't download them at the beginning, you might end up with a non-working feature with no access to the internet. Therefore I hesitate, it would make it more difficult for users to use the plugin. If someone wants give it a try, I'm happy to support. Any solution developed here shouldn't negatively affect ease-of-use.

Using diff/patch is not built into the JetBrains plugin system. I could automate supplying binary diff files on the GitHub repo. But it will be for the user to apply them manually.

I hesitate to list the project in the example list as I consider the other plugins on the list to using more functionality of the plugin already. Adding this plugin to the list wouldn't add value to the list, it would just make it longer.

@luvarqpp
Copy link

luvarqpp commented Sep 6, 2019

Ok, I see it from your point of view. I would probably try to ask directly Jetbrains for some solution if possible and if nothing can be done (to have good user experience like now), current state is fully acceptable. Thanks for reply with your opinion.

@ahus1
Copy link
Contributor

ahus1 commented Sep 7, 2019

Pre-Release 0.30.3 upgrades to asciidoctorj-pdf:1.5.0-beta.4. As the original scope of this ticket was to add PDF support, I consider this ticket closed.

@ahus1 ahus1 closed this as completed Sep 7, 2019
ahus1 added a commit that referenced this issue Sep 9, 2019
…PDF should use diagram in the format specified in the source (#325)
@gudaoxuri
Copy link

Chinese garbled in the PDF, but the preview in idea and the PDF generated through Maven are normal. What configuration do I need to do?

image

image

@ahus1
Copy link
Contributor

ahus1 commented Sep 10, 2019

@gudaoxuri - looking at the tree view of your project I see that you've added some fonts and a theme to your project. It might be similar to (or parts of) https://github.com/chloerei/asciidoctor-pdf-cjk-kai_gen_gothic

I assume that your maven build picks up the necessary fonts, while the IntelliJ configuration doesn't. Therefore Chinese characters don't appear in the PDF.

The document you turned to a PDF seems to be one part of a bigger document, and I assume that this sub-section doesn't have pdf-stylesdir or pdf-style set. It might be set in the parent document or in the maven plugin configuration.

Please give it a try by adding the necessary attributes to the file you are about to convert to a PDF.

Once your configuration works for one file, you can take it one step further and add a .asciidoctorconfig-file to your project. This allows you apply common configurations for all AsciiDoc documents in a folder and its subfolders. While it works out-of-the-box for the preview with this plugin, you'll need to specify an include when you run it with maven (usually once in the parent document).
See https://github.com/asciidoctor/asciidoctor-intellij-plugin/wiki/Support-project-specific-configurations for details how to do this.

I see that you have some GitHub repositories - is this issue about one of them? This would make it easier to support you if you could link it here.

@gudaoxuri
Copy link

@gudaoxuri - looking at the tree view of your project I see that you've added some fonts and a theme to your project. It might be similar to (or parts of) https://github.com/chloerei/asciidoctor-pdf-cjk-kai_gen_gothic

I assume that your maven build picks up the necessary fonts, while the IntelliJ configuration doesn't. Therefore Chinese characters don't appear in the PDF.

The document you turned to a PDF seems to be one part of a bigger document, and I assume that this sub-section doesn't have pdf-stylesdir or pdf-style set. It might be set in the parent document or in the maven plugin configuration.

Please give it a try by adding the necessary attributes to the file you are about to convert to a PDF.

Once your configuration works for one file, you can take it one step further and add a .asciidoctorconfig-file to your project. This allows you apply common configurations for all AsciiDoc documents in a folder and its subfolders. While it works out-of-the-box for the preview with this plugin, you'll need to specify an include when you run it with maven (usually once in the parent document).
See https://github.com/asciidoctor/asciidoctor-intellij-plugin/wiki/Support-project-specific-configurations for details how to do this.

I see that you have some GitHub repositories - is this issue about one of them? This would make it easier to support you if you could link it here.

I tried to test successfully on a single asciidoc file, but the idea reported an error when the pdf was generated by the entire project (consisting of multiple asciidoc files) (see log attachment), while the document could generate the pdf normally through maven.

idea_log.txt

@gudaoxuri
Copy link

@gudaoxuri - looking at the tree view of your project I see that you've added some fonts and a theme to your project. It might be similar to (or parts of) https://github.com/chloerei/asciidoctor-pdf-cjk-kai_gen_gothic
I assume that your maven build picks up the necessary fonts, while the IntelliJ configuration doesn't. Therefore Chinese characters don't appear in the PDF.
The document you turned to a PDF seems to be one part of a bigger document, and I assume that this sub-section doesn't have pdf-stylesdir or pdf-style set. It might be set in the parent document or in the maven plugin configuration.
Please give it a try by adding the necessary attributes to the file you are about to convert to a PDF.
Once your configuration works for one file, you can take it one step further and add a .asciidoctorconfig-file to your project. This allows you apply common configurations for all AsciiDoc documents in a folder and its subfolders. While it works out-of-the-box for the preview with this plugin, you'll need to specify an include when you run it with maven (usually once in the parent document).
See https://github.com/asciidoctor/asciidoctor-intellij-plugin/wiki/Support-project-specific-configurations for details how to do this.
I see that you have some GitHub repositories - is this issue about one of them? This would make it easier to support you if you could link it here.

I tried to test successfully on a single asciidoc file, but the idea reported an error when the pdf was generated by the entire project (consisting of multiple asciidoc files) (see log attachment), while the document could generate the pdf normally through maven.

idea_log.txt

The same problem occurs in another of my projects ( https://github.com/gudaoxuri/dew/blob/master/docs/src/main/asciidoc/book.adoc )where you can try to generate pdf on book.adoc

@ahus1
Copy link
Contributor

ahus1 commented Sep 10, 2019

It looking at the exception, it looks like an issue with prawn and syntax highlighting: prawn.text.formatted.wrap

I locked the trigger down to the quick-start.adoc file and reduced it to the following snippet that fails with the PDF generation in the IDE.

[source,java]
----
                    .exchange("http://" + Constants.REST_COMPUTE_SERVICE + "/compute", HttpMethod.PUT)
----

The project you referenced doesn't include a PDF generation, therefore I am not sure what versions you use to create a PDF.

The IntelliJ plugin uses asciidoctorj-pdf:1.5.0-beta.4 together with the latest AsciiDoctorJ runtime.

Please use the latest versions of asciidoctorj and asciidoctorj-pdf in your maven build. If you see the same problem there, please raise an issue with asciidoctor-pdf with a minimal example (usually not asciidoctorj-pdf, as this is just a re-packaging).

Once you have a working Maven build with the latest versions and still have a failing IntelliJ plugin, please raise an issue with the plugin.

@gudaoxuri
Copy link

gudaoxuri commented Sep 10, 2019

It looking at the exception, it looks like an issue with prawn and syntax highlighting: prawn.text.formatted.wrap

I locked the trigger down to the quick-start.adoc file and reduced it to the following snippet that fails with the PDF generation in the IDE.

[source,java]
----
                    .exchange("http://" + Constants.REST_COMPUTE_SERVICE + "/compute", HttpMethod.PUT)
----

The project you referenced doesn't include a PDF generation, therefore I am not sure what versions you use to create a PDF.

The IntelliJ plugin uses asciidoctorj-pdf:1.5.0-beta.4 together with the latest AsciiDoctorJ runtime.

Please use the latest versions of asciidoctorj and asciidoctorj-pdf in your maven build. If you see the same problem there, please raise an issue with asciidoctor-pdf with a minimal example (usually not asciidoctorj-pdf, as this is just a re-packaging).

Once you have a working Maven build with the latest versions and still have a failing IntelliJ plugin, please raise an issue with the plugin.

PDF cannot be generated related to this code, but the Maven plug-in is OK (see below for version)

Test pom.xml

Test asciidoc at src/docs/asciidoc/

@yunkaiOr2
Copy link

how about jck(pdf)? idea plugin 0.30.18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants