How to convert asciidoc to pdf? - asciidoc

I attempted to convert my mybook.adoc to mybook.pdf using pandoc, and got the following error.
$ pandoc -s mybook.adoc -t asciidoc -o mybook.pdf
pandoc: cannot produce pdf output with asciidoc writer
Is there another tool that I should use instead of or in concert with pandoc?
How can I convert asciidoc to pdf?

Prerequisites: all that’s needed is Ruby (1.9.3 or above)
Install a native PDF converter for AsciiDoc - Asciidoctor PDF:
gem install asciidoctor-pdf --pre
Run:
asciidoctor-pdf mybook.adoc
You should get the file mybook.pdf in the same directory.

If you're using Visual Studio Code with AsciiDoc extension, Ctrl + SHFT + P (or Shift ⇧ + Cmd ⌘ + P in macOS) and type AsciiDoc: Export document as PDF.
You will need to have asciidoctor-pdf or wkhtmltopdf installed according to the command instructions.

If you have Docker installed, you can use the AsciiDoctor Docker Image. Then you can use the image interactively or in batch mode as explained below:
Prerequisites
Install Docker
Install the Docker image:
$ docker pull asciidoctor/docker-asciidoctor
Create the pdf by executing the following command:
$ cd [directory to where my book.adoc is located]
$ docker run --rm -v $(pwd):/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf mybook.adoc
Explanation
docker run starts a Docker container
--rm cleanup - removes the Docker container after the command has been executed
-v mount a volume to the image
$(pwd) get the path to the current directory, e.g. the value of [directory to where my book.adoc is located] above
documents the name of the mounted volume in the running container
asciidoctor/docker-asciidoctor the name of the Docker image that is used to create the Docker container
asciidoctor-pdf the command that actually triggers the pdf generation
mybook.adoc the name of the AsciiDoc source file to generate the pdf from
See also the docker run documentation

AsciiDoc has a couple of toolchains that will render PDFs from AsciiDoc source. You can use the Ruby-based AsciiDoc -> Prawn -> PDF toolchain developed by Asciidoctor, or you can use the older AsciiDoc -> DocBook -> FOP toolchain. These are rendering/publishing procedures, whereas Pandoc mainly provides for conversion and is best for converting from one o another type of source format.

I now realize the ideal route from asciidoc to pdf is to first convert the asciidoc to docbook. This employs the intended sphere of asciidoc and a docbook->pdf converter using each in its separate area of concern.
Furthermore, instead of pandoc I have found that when mathematical formulas are included, it was easier to use dblatex for docbook->pdf conversion. Thus my conversion pipeline is the following:
asciidoc -> asciidoctor -> docbook -> dblatex -> pdf
A sample make file:
make: my.adoc
asciidoc -b docbook my.adoc
dblatex my.xml
This discussion page suggests that asciidoc is primarily designed to compile to docbook.

The easiest way to convert AsciiDoc document to PDF is as follows -
Open AsciiDocLive
Paste your document in the editor and see the preview
save it as HTML
Open any online HTML to PDF convertor
Upload your newly generated HTML file
Convert to PDF and download it.
Done.

Following #Remis's answer, I used asciidoctor's pdf backend.
I could not figure out how to install asciidoctor-pdf on nixos, but managed to find the following alternative which worked:
asciidoctor -r asciidoctor-pdf -b pdf or asciidoctor-pdf

Another workflow, which I use a lot, is to create HTML from your AsciiDoc file using the AsciiDoctor processor, linking a custom CSS stylesheet with print styling rules:
asciidoctor -a stylesheet=path-to-stylesheet.css file.adoc
You can then open the HTML file in your browser and print to PDF.
For more advanced styling, such as page numbering, headers, footers, page breaks and columns, you can use PrinceXML (or other similar products). This is a commandline processor that will convert the HTML file to PDF using the styling rules in the CSS used by the HTML file. PrinceXML applies styling rules that are in the CSS3 standard but which aren't yet supported by browsers, allowing you to create finely styled layouts.

In case if you have AsciiDoc plugin in Intellij, here is the way you can generate -
create the adoc file ex - "tktds-dhs-e2e-gcp.adoc" and write your content.. or you may already have adoc file..
At top where file is opened in editor, click on PDF or HTML button to generate .pdf or .html files {need to click 1 at a time} refer below image -
Further you can find pdf / html file in same directory, refer below image -

Related

How to generate API Documentation using openapi-generator?

I'm new to the OpenAPI 3.0.0.
I have successfully created a java client library using an openapi-generator.
But OpenAPI Generator allows the generation of API client libraries (SDK generation), server stubs, documentation. So I want to know is there any commands or steps are available to generate HTML documentation and also to customize the documentation template.
Old question, but for those still bumping into it. OpenApi Generator can do generation of html documentation from your yaml or json definition of your API.
openapi-generator generate -i PathToMyInputDefinitionFile.yaml -g html -o /PathToOutputFolder
Where html is the generator you want to use. Other generators include dynamic-html and html2. Also can emit as markdown. See https://openapi-generator.tech/docs/generators/
If using Docker, a full example would look like this:
docker run --rm -v ${PWD}:/local openapitools/openapi-generator:tagname generate -i /local/input.yaml -g html -o /local
PWD is present working directory (current directory) in the host, which you are mapping on to /local in the container. Adjust 'tagname' to suit, from https://hub.docker.com/r/openapitools/openapi-generator/tags Adjust input.yaml to be your input file yaml definition of your API.

How to generate an image file of a workflow inside a Symfony controller?

I want to create an image file of a Symfony workflow from inside of a controller.
The documentation only shows how to do this inside the console. I already installed the GraphViz library via composer but I could not find a method that can convert the workflow definition to an image.
php bin/console workflow:dump workflow-name | dot -Tsvg -o graph.svg
I hope that this is not the only way to do it?!
Symfony provides you solution for dumping workflow as GraphViz(dot) or PlantUML(puml) format. It does not convert it to image. You must do it yourself with exec or with this alternatives for dot files:
Pear package(not maintained): https://pear.php.net/package/Image_GraphViz
PHP library(not maintained): https://code.google.com/archive/p/canviz/
Client side library: https://github.com/mdaines/viz.js/
I didn`t find any solution for converting puml to image without PlantUML binaries.

Mac OS installer package with Readme file containing images

I'm trying to set <readme> tag in Distribution.xml part of the package to contain something which may contain images. For now I've tried rtfd and pdf; for rtfd it compains that it can't open the file because of permissions lack and pdf is displayed as plain text.
So the question is: how to use something that may contain images with Distribution.xml
productbuild doesn't handle .rtfd files correctly but I have found that OS X 10.9 Mavericks doesn't handle HTML base 64 encoded images either.
My workaround is to use productbuild with dummmy .rtf files and then use pkgutil to repackage the installer.
Your distribution.xml file contains:
<welcome file='Welcome-ReplaceMe.rtf' />
and Welcome-ReplaceMe.rtf exists in a .lproj folder inside Resources. Once the installer is built, but before you sign it with productsign expand the package:
pkgutil --expand Installer.mpkg Installer.expanded
change the Distribution file inside Installer.expanded to use:
<welcome file='Welcome.rtfd' />
and delete the dummy Welcome-ReplaceMe.rtf and add Welcome.rftd. Finally repackage the installer:
pkgutil --flatten Installer.expanded Installer.mpkg
Since I didn't find solution I used some workaround:
Convert RTF to HTML
Use this site to convert image to embeded html image and replace all linked images in the original html
Use html instead of rtfd in the Distribution.xml
Drawback is that it require more work to be done and html is displayed differently in the package than I saw in browsers.
I have no solution, just a creative workaround :)
I tried to apply the existing answers.
An HTML file with embedded images (base64 encoded) didn't work in my case
So I tried to get the image file inside the package, right next to the HTML file and something like <img src="./success.png" alt="success">, which didn't work either :/
My out-of-the-box solution was to just use an emoji instead of the image. In my case all I wanted was this green checkmark you'd see on the conlusion screen anyways. There's an emoji (✅) that looks quite similar.

Missing xml tag SVG file (using Graphviz dot.exe)

My config is:
- Windows Vista
- XAMPP 1.7.1
- Media Wiki + Semantic MW
- an extension that uses Graphviz to create a SVG
- Graphviz 2.26.3 (install dir c:\graphviz.....)
Everything works fine but the problem is: the xml tag
'image xlink:href="some_image.png"....'
is missing from the SVG file created using a Media Wiki php page.
This is done by:
$cmdlinesvg = wfEscapeShellArg($cmd).' -T svg '.wfEscapeShellArg($src).' -o '.wfEscapeShellArg($svg);
$WshShell = new COM("WScript.Shell");
$WshShell->Exec($cmdlinesvg);
I've created a batch file that executes the same command line:
c:\graphviz2.26.3\bin\dot.exe -T svg filename.dot -o filename.svg
and if I run it manually it works, and the xml tag appears.
Anyone knows what is the problem? thanks in advance.
SOLVED
The problem is related to the image path that is in the .DOT file.
If you run the command line manually, the image path doesn't need to be a full path.
You can have only: shapefile="some_image.png"
If you run the command inside php code, the image path HAS to be a full path.
So you must have: shapefile="C:\xampp......\some_image.png"
Another problem arises: the resulting .SVG file doesn't show the images.
If you right-click and open the .SVG file with the browser (ie Firefox), the images are ok.
But, again, through a php page, the images are lost.
Solution: edit the .SVG file (this is XML) to change the paths.
On the original .SVG file we have:
On the modified .SVG file we must have:
PS: I'm doing my master thesis, so this is for a particular problem, but still I hope it helps someone.

poedit and xml files

How to configure poedit to extract strings from xml file?
I have Zend Framework navigation items in .xml like this:
<entry-i>
<label>Text to translate</label>
<params>
...
<params>
<entry-i>
And I want poedit to read just messages from <label>s.
I have been searching for a solution as well, and I have just gotten it to work!
In Poedit (I have 1.4.2), add a new parser (Edit > Preferences) with the following properties:
Language: XML
List of extensions separated by semicolons (e.g. .cpp;.h): *.xml
Parser command: xgettext --force-po -o %o %C %K %F -L glade
An item in keywords list: -k%k
An item in input files list: %f
Source code charset: --from-code=%c
In your translation project, add label and title to your keyword list and update the catalog.
The above advice to abuse the Glade extractor to parse non-Glade XML files is misguided. It’s never going to work well (case in point: some comments around here). Of course, it was better than nothing back in 2010.
Starting with gettext 0.19.7 (bundled with Poedit since 1.8.7), there’s a better way: there’s now builtin support in gettext for custom XML files via ITS rules.
The best way to extract strings from a custom XML file is to
Add a custom extractor with your extension, specifying standard gettext invocation, without the -L glade bit.
Write ITS rules for your file format.
Put them in the location of other .its and .loc files in Poedit’s installation.
For anyone running into problems with the configuration for Poedit on windows, specifically if you get an error message saying that glade and expat are not available, replace the supplied xgettext.exe with current one from the gnuwin32 project:
http://gnuwin32.sourceforge.net/packages/gettext.htm
You need to download the binaries and the dependencies. However, only the binary xgettext.exe must be extracted and related files (just run it and it will tell you what is missing)
Looks like PoEdit does not support XML yet.
I have created a little php script, to extract the labels to .php file,
which PoEdit does understand.
$xml = simplexml_load_file("../application/configs/navigation.xml")
or die("Error: Cannot open XML file");
echo '<?';
foreach($xml->xpath('//label') as $label){
echo 'echo _("'.$label.'");'. PHP_EOL;
}
It worked great!! I found the problem about "glade not supported" using Poedit 1.4.6 in Windows 7 but I fixed by downloading last gnuwin32 binaries and dependencies as user496209 said. Don't download the complet package because PoEdit comes with its own gettext library, so just donwload binaries and dependencies and replace the requested files into the poedit folder.

Resources