Git Product home page Git Product logo

asciidoctor-web-pdf's Introduction

Asciidoctor Web PDF

Build npm version Docker image

A PDF converter for AsciiDoc based on web technologies. It allows complex layouts to be defined with CSS and JavaScript, while writing the content in AsciiDoc.

Document
source / PDF
Letter
Source / PDF
Book
source / PDF
Cheat sheet
Source / PDF
Resume
Source / PDF
Slides
Source / PDF

Asciidoctor Web PDF has support for LaTeX-style mathematical equations (via MathJax) and syntax highlighting (via highlight.js). Many more features can be added by importing an existing JavaScript or CSS framework.

Highlights

  • Complex layouts with CSS and JavaScript
  • SVG icons with Font Awesome 5
  • PDF document outline (i.e., bookmarks)
  • Table Of Contents
  • Document metadata (title, authors, subject, keywords, etc)
  • Fully customizable template
  • Syntax highlighting with Highlight.js
  • Page numbering
  • Preview mode
  • STEM support with MathJax 3

Installation

Run from pre-compiled binaries

Asciidoctor Web PDF is available for each release as a zip file for Windows 64-bit, Linux 64-bit and macOS 64-bit (x86-64).

Go to the releases page and download the appropriate binary for your platform (under "Assets"). Extract this to a folder of your choosing.

From a command line in this folder you can then run the asciidoctor-web-pdf command.

Install using npm

To run from source, you need Node installed on your machine to install and run Asciidoctor Web PDF. The best way to install Node is to use nvm (Node Version Manager).

How to set up nvm on my machine

Install nvm and Node on Linux or macOS

Follow these installation instructions to set up nvm on your machine.
Once you've installed nvm, open a new terminal and install the latest Node LTS release.

$ nvm install --lts

The above command will install the latest LTS release of Node and automatically set it as your default alias.

Install nvm and Node on Windows

Follow these installation instructions to set up nvm on your machine.
Once you've installed nvm, open a new, regular PowerShell terminal, and install Node using nvm.

$ nvm install 14.15.5
$ nvm use 14.15.5

The above commands will install Node v14.15.5 and enable it.

We recommend using the latest long term support (LTS) release of Node. While you can use other versions of Node, Asciidoctor Web PDF is only tested against active LTS releases.

Install in a project directory

You can opt to install Asciidoctor Web PDF in a project directory, such as the directory where your AsciiDoc files are stored. If you don't have a package.json file in your project directory, you can create one using:

$ npm init -y

To install Asciidoctor Web PDF in a project directory, move into your project directory and type:

$ npm i @asciidoctor/core asciidoctor-pdf --save-dev

The dependencies will be in installed under the node_modules folder in the current directory and npm will save all modules listed as devDependencies in the package.json file.

Verify that the asciidoctor-web-pdf command is available. If you are running a recent version of npm, you can use either: npm x asciidoctor-web-pdf --version (or npx asciidoctor-web-pdf --version)

TIP: If you are running an older version, you might need to use the longer format: $(npm bin)/asciidoctor-web-pdf --version.

If installation was successful, the command should report the version of Asciidoctor Web PDF.

$ npx asciidoctor-web-pdf --version
Asciidoctor Web PDF 1.0.0-alpha.12 using Asciidoctor.js 2.2.1 (Asciidoctor 2.0.12) [https://asciidoctor.org]
Runtime Environment (node v14.15.5 on linux)
CLI version 3.4.0

Install globally using npm

IMPORTANT: This installation procedure is only applicable if you are not using a Node.js version manager like nvm (Node Version Manager). Otherwise, npm will try to install Asciidoctor Web PDF in the system space which has proven to be unreliable!

To install Asciidoctor Web PDF package globally, open a terminal and type:

$ npm i -g @asciidoctor/core asciidoctor-pdf

NOTE: Installing Asciidoctor Web PDF globally makes asciidoctor-web-pdf command available on your PATH. In other words, the command asciidoctor-web-pdf will be available globally, so you can run it from any directory.

Verify that the asciidoctor-web-pdf command is available on your PATH by running:

$ asciidoctor-web-pdf --version

NOTE: If you get an error about Executions Policies when running this command on PowerShell, try to use the following command instead: $ asciidoctor-web-pdf.cmd --version.

TIP: If you prefer Yarn over npm, use this command to install the Asciidoctor Web PDF package:

$ yarn global add @asciidoctor/core asciidoctor-pdf

Using Docker

docker run --rm ggrossetie/asciidoctor-web-pdf --version

Asciidoctor Web PDF 1.0.0-alpha.16 using Asciidoctor.js 2.2.6 (Asciidoctor 2.0.17) [https://asciidoctor.org]
Runtime Environment (node v16.17.0 on linux)
CLI version 3.5.0

If you want to render the cheatsheet example, move to the root of this repository and type:

docker run -i --rm \
  --volume=$PWD/examples/cheat-sheet:"/usr/app" \
  -u $(id -u ${USER}):$(id -g ${USER}) \
  ggrossetie/asciidoctor-web-pdf:latest \
  --template-require ./snyk/template.js maven-security-cheat-sheet.adoc 

The --volume option will mount your local copy of the Asciidoctor Web PDF repository on the container. Since it is a non-root user we have to map our user to asciidoctor user in the container.

You can also use stdin and stdout without the need of volumes.

cat examples/document/basic-example.adoc | docker run -i --rm ggrossetie/asciidoctor-web-pdf:latest - > doc.pdf

Get started

Asciidoctor Web PDF provides a standard document layout. To convert an AsciiDoc document using this layout, open a terminal and type:

$ asciidoctor-web-pdf document.adoc

IMPORTANT: Asciidoctor Web PDF relies on Puppeteer to generate a PDF from a Web page. If you get the following error, make sure that all the necessary dependencies are installed.

> Unable to generate the PDF - Error: TimeoutError: Timed out after 30000 ms while trying to connect to Chrome!

Configuration

The standard document layout can be configured depending on your needs.

STEM support

To activate equation and formula support, set the stem attribute in the document's header (or by passing the attribute to the command line):

$ asciidoctor-web-pdf document.adoc -a stem

Title page

The title page is enabled if either of these conditions are met:

  • The document has the book doctype.
  • The title-page attribute is set (with an empty value) in the document header.
$ asciidoctor-web-pdf document.adoc -a title-page

Custom styles

You can provide a custom stylesheet using the stylesheet attribute. A custom stylesheet does completely replace the default stylesheet.

$ asciidoctor-web-pdf document.adoc -a stylesheet="custom.css"

TIP: You can also provide a custom stylesheet in addition to all the default styles using the + prefix:

$ asciidoctor-web-pdf document.adoc -a stylesheet="+custom.css"

Notice the + before custom.css, it means that the stylesheet will be included after all the default styles. This is particularly useful when you want to override a few styles.

The stylesheet attribute can accept multiple comma-delimited values (without spaces). This can be used to begin with a base stylesheet and then apply supplementary content.

$ asciidoctor-web-pdf document.adoc -a stylesheet="custom.css,override.css"

It's also possible to use the default stylesheet and add custom styles with a custom stylesheet. All default stylesheets are available under the prefix asciidoctor-pdf/css/:

$ asciidoctor-web-pdf document.adoc -a stylesheet="asciidoctor-pdf/css/asciidoctor.css,asciidoctor-pdf/css/document.css,custom.css"

You can also specify where the stylesheets are located with the stylesdir attribute.

$ asciidoctor-web-pdf document.adoc -a stylesdir=css -a stylesheet="custom.css,override.css"

Front cover image

When using a title page (see above), you might want to set a front cover image. To do that, you will need to add a few lines of CSS.

Here's a complete example:

  1. Create a file named orly.adoc with the following content:
= Hoping This Works
:doctype: book

== Guessing

The first step is guessing.

We are using :doctype: book to get a title page.

  1. Create a file named orly.css with the following content:
@page :first {
  background-size: contain;
  background-image: url("./orly.jpg");
}

/* move the book title to the correct location */
#cover > h1 {
  color: white;
  margin-top: 8cm;
  font-size: 7rem;
}
  1. Download the image orly.jpg and put it next to the orly.adoc file.

  2. Open a terminal and type:

    $ asciidoctor-web-pdf orly.adoc -a stylesheet="+orly.css"

The above command will create a file named orly.pdf which should look like:

front-cover-image

Docinfo

You can add custom content to the head, header or footer of the output document using docinfo files. Docinfo files are useful for injecting auxiliary metadata, stylesheet, and script information into the output not added by the converter.

In addition, you can add running content to the output document. Running content can then be positioned via CSS on the top, bottom, left or right margins of pages. This can come in handy when you want to repeat complex elements (address, contact...) on all pages for documents like invoices or reports. If you want to learn more about running elements, please read the following section Running elements.

IMPORTANT: You will need to declare running elements as running content via CSS. Otherwise, running elements will be visible on the page.

To enable docinfo files, you need to configure the scope using the docinfo attribute. The scope defines if the docinfo files apply for a specific document ("private") or for all documents in the same directory ("shared").

Mode Location Behavior Docinfo file name
Private Head Adds content to <head> for <docname>.adoc files. <docname>-docinfo-pdf.html
Private Header Adds content to start of document for <docname>.adoc files. <docname>-docinfo-header-pdf.html
Private Footer Adds content to end of document for <docname>.adoc files. Useful for supporting Paged.js hooks and custom JavaScript <docname>-docinfo-footer-pdf.html
Private Running Adds running content to start of document for <docname>.adoc files. <docname>-docinfo-running-pdf.html
Shared Head Adds content to <head> for any document in same directory. docinfo-pdf.html
Shared Header Adds content to start of document for any document in same directory. docinfo-header-pdf.html
Shared Footer Adds content to end of document for any document in same directory. Useful for supporting Paged.js hooks and custom JavaScript docinfo-footer-pdf.html
Shared Running Adds running content to start for any document in same directory. docinfo-running-pdf.html

To specify which file(s) you want to apply, set the docinfo attribute to any combination of these values:

  • private-head
  • private-header
  • private-footer
  • private-running
  • private (alias for private-head,private-header,private-footer,private-running)
  • shared-head
  • shared-header
  • shared-footer
  • shared-running
  • shared (alias for shared-head,shared-header,shared-footer,shared-running)

Setting docinfo with no value is equivalent to setting the value to private.

For example:

:docinfo: shared,private-footer

This docinfo configuration will apply the shared docinfo head, header, running and footer files, if they exist, as well as the private footer file, if it exists.

Running elements

Running elements can be positioned on the top, bottom, left or right margins of pages. Let's take a concrete example where we want to display an address block in the bottom left box of every page.

<address class="contact-us">
  <strong>Example Inc.</strong><br>
  1234 Example Street<br>
  Antartica, Example 0987<br>
  <abbr title="Phone">P:</abbr> (123) 456-7890
</address>

First, you will to define your element as running using the position property. Here, we are using runningContact as an identifier, but you can use any name that makes sense to you:

.contact-us {
  position: running(runningContact)
}

Then, place the element into a margin box with the element() function via the content property:

@page {
  @bottom-left {
    content: element(runningContact)
  }
}

As you can see, we are using the identifier runningContact defined earlier. The above definition will effectively remove the .contact-us element from the page and repeat it on every page in the bottom left box.

Here's a complete example:

  1. Create a file named report.adoc with the following content:
= 2021 Annual Report
:docinfo: private
  1. Create a file named report-docinfo-running-pdf.html with the following content:
<address class="contact-us">
  <strong>Handicap International</strong><br>
  138, avenue des Frères Lumière<br>
  69008 Lyon - France
</address>
  1. Create a file named report.css with the following content:
.contact-us {
  width: 6cm;
  position: running(runningContact)
}

@page {
  margin: 1cm 2cm 4cm 2cm;
}

@page :right {
  @bottom-left {
    content: element(runningContact)
  }

  @bottom-right {
    content: counter(page);
    margin: 10pt 10pt 30pt 0;
  }
}

@page :left {
  @bottom-right {
    content: element(runningContact)
  }

  @bottom-left {
    content: counter(page);
    margin: 10pt 0 30pt 10pt;
  }
}
  1. Open a terminal and type:

    $ asciidoctor-web-pdf report.adoc -a stylesheet="+report.css"

The above command will create a file named report.pdf which should look like:

complex-footer

TIP: Please note that, in this case, you don't need to use a docinfo file, you can declare the "contact us" block directly in the AsciiDoc file. In other words, you should get the same result if you are using the following content:

= 2021 Annual Report

[.contact-us]
--
*Handicap International* +
138, avenue des Frères Lumière +
69008 Lyon - France
--

Asciidoctor extensions

Asciidoctor Web PDF can use Asciidoctor extensions written in JavaScript from the CLI. For instance, if you want to use the Asciidoctor Kroki extension, you first need to install it:

$ npm i asciidoctor-kroki

Then, you can use the following command to load this extension:

$ asciidoctor-web-pdf --require asciidoctor-kroki document.adoc

It's also possible to use an extension from a JavaScript file. For instance, if you want to load a local extension declared in a JavaScript file named my-asciidoctor-extension.js, then you can use the following command:

$ asciidoctor-web-pdf --require ./my-asciidoctor-extension.js document.adoc

NOTE: Please note that the extension should export a function named register, otherwise the extension won't be registered:

module.exports.register = function (registry) {
  if (typeof registry.register === 'function') {
    registry.register(function () {
      this.block(function () {
        // ...
      })
    })
  } else if (typeof registry.block === 'function') {
    registry.block(function () {
      // ...
    })
  }
  return registry
}

Diagrams

You can use the Asciidoctor Kroki extension to render diagrams in your PDF. In this example, we create a file named piracy.adoc with the following content:

piracy.adoc

= Piracy

Piracy is an act of robbery or criminal violence by ship upon another ship,
typically with the goal of stealing rum and other valuable items or properties.

Here's what a pirate looks like!

[nomnoml]
....
[Pirate|eyeCount: Int|raid();pillage()|
  [beard]--[parrot]
  [beard]-:>[foul mouth]
]

[<abstract>Marauder]<:--[Pirate]
[Pirate]- 0..7[mischief]
[jollyness]->[Pirate]
[jollyness]->[rum]
[jollyness]->[singing]
[Pirate]-> *[rum|tastiness: Int|swig()]
[Pirate]->[singing]
[singing]<->[rum]
....

Kroki supports more than a dozen diagram libraries. In the above example, we are using the nomnoml UML diagram library.

NOTE: Please note, that you will need to install asciidoctor-kroki, using npm i asciidoctor-kroki.

You can use the following command to generate a PDF:

$ asciidoctor-web-pdf --require asciidoctor-kroki piracy.adoc

Here's the result: piracy.pdf

Custom layout

It's also possible to create your own layout by extending the default HTML 5 converter. To create a new layout you will need some JavaScript knowledge.

Let's say that we want to override how the document node is converted.

module.exports = {
  document: (node) => `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="./layout.css" rel="stylesheet">
</head>
<body>
${node.getContent()}
</body>`,
}

In the above example, we are using Template Literals but you can use your favorite template engine. You can also override other elements.

Complete list of elements
  • document
  • embedded
  • outline
  • section
  • admonition
  • audio
  • colist
  • dlist
  • example
  • floating-title
  • image
  • listing
  • literal
  • stem
  • olist
  • open
  • page_break
  • paragraph
  • preamble
  • quote
  • thematic_break
  • sidebar
  • table
  • toc
  • ulist
  • verse
  • video
  • inline_anchor
  • inline_break
  • inline_button
  • inline_callout
  • inline_footnote
  • inline_image
  • inline_indexterm
  • inline_kbd
  • inline_menu
  • inline_quoted

The function takes one parameter, called node. Depending on the context a node can be a Block, a Section, a List. or a Table. Block, Section, List and Table extends AbstractBlock which extends AbstractNode.
If you want to learn more, please read the Asciidoctor.js API documentation.

To help you get started, we provides a few alternative layouts in the examples directory:

Layout Template file
Letter examples/letter/template.js
Book examples/book/template.js
Slides examples/slides/template.js
Resume examples/resume/template.js
Cheat sheet (Snyk) examples/cheat-sheet/snyk/template.js

To enable a custom layout, use the --template-require command line option. For instance, if I want to use the cheat sheet layout on examples/cheat-sheet/maven-security-cheat-sheet.adoc:

$ asciidoctor-web-pdf ./examples/cheat-sheet/maven-security-cheat-sheet.adoc --template-require ./examples/cheat-sheet/snyk/template.js

It will produce a file named examples/cheat-sheet/maven-security-cheat-sheet.pdf.

How does it work?

Asciidoctor Web PDF is using an HTML 5 converter to convert an AsciiDoc document to an HTML 5 page. Puppeteer will then run a headless Chrome to generate a PDF from the HTML 5 page.

To paginate content in the browser, we are using Paged.js, an open-source library, that acts as a polyfill for Paged Media and Generated Content for Paged Media W3C specifications.

This project is heavily inspired by ReLaXed.

The file template.js defines how the AsciiDoc content should be converted to HTML 5. Puppeteer will then run an headless Chrome to generate a PDF from the HTML 5 page.

Contribute!

New contributors are always welcome! If you discover errors or omissions in the source code or documentation, please don't hesitate to submit an issue or open a pull request with a fix.

asciidoctor-web-pdf's People

Contributors

ablu avatar ahus1 avatar danyill avatar dependabot-preview[bot] avatar dependabot[bot] avatar djencks avatar ggrossetie avatar lordofthejars avatar lucianciolacu avatar lurch avatar makon avatar matklad avatar patrickluoyu avatar rdmueller avatar settermjd avatar siaccarino avatar webpigeon avatar wh81752 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asciidoctor-web-pdf's Issues

`--watch` option leaks browsers

Don't have time to write a detail bug-report, but TL;DR is that running

./node_modules/asciidoctor-pdf.js/bin/asciidoctorjs-pdf -v ./src/slides.adoc --template-require ./src/template.js  --watch

Eventually allocates 10GB of memory. Don't know what exactly is allocated: htop does not show that any particular process allocates a lot of memory, but the total mem usage is high, and system becomes unresponsive.

Hypothesis: we leave behind some processes, which don't use a ton of memory by themselves, thus dodging the htop.

Extend/reuse Asciidoctor.js CLI

Currently we are using a fork of Asciidoctor.js CLI. More specifically the code is copied and pasted 😳 😞

We should try to reuse and extend the Asciidoctor.js CLI as much as possible to avoid duplication and reduce maintenance.

Write temp html atomically

To enable reliable reloading of html in the brouser, we should replace this write with an atomic one (write to tmp file & atomically rename), otherwise browser might read only half of html and get confused.

API docs for what is available in templates

It would be cool to have some kind of API docs for which keys are allowed in module.export of template.js, and which methods are available on node. My understanding is that this API is mechanically generated from a ruby API, but I am having a hard time finding Ruby API docs as well :-)

Specifically, the problem I am trying to solve is that of syntax highlighting: I don't really like the results of hljs, and would prefer to do roll my own syntax highlighting instead. I understand how I can do that hljs way: add a JS snippet to the generated HTML which traverses all the <code> blocks and does the thing. However, I would prefer to do that at document-generation time, but I am not quite sure which node type I should add to the template to achieve that.

Distribute the default stylesheets in the package

node_modules/asciidoctor-pdf/css/asciidoctor.css	
node_modules/asciidoctor-pdf/css/document.css
node_modules/asciidoctor-pdf/css/features/title-document-numbering.css
node_modules/asciidoctor-pdf/css/features/title-page-numbering.css

Inline styles are ignored by Paged.js

The following does not create a page break when using Paged.js:

<div style="page-break-after: always;"></div>

We should also define a CSS class with an associated rule:

<div class="page-break" style="page-break-after: always;"></div>
.page-break {
  page-break-after: always;
}

Feedback regarding styling capabilities

Hi,

I now spent some time theming the document in order to get the same result as the purely pagedjs-cli based solution. I think there are some easy ways to improve the current situation:

  • currently it is not possible to disable the default CSS. While this makes it easy to get started, it can really be a pain if you want to completely customize the page. You do not only need to understand your own CSS, but also the default CSS. Some way to disable the default CSS would be great :)
  • There are some very specific rules in the default CSS which make it hard to override certain aspects of the default theme. For example, the font-name "Noto Serif" is mentioned in 5 places, changing the text-color or font-size is... hard :P. I think in many cases some CSS variables could greatly simplify the creation of themes inheriting from the default theme.

PDF Output is blank

Using the examples, I tried running a couple out of curiosity. The PDF is produced, but only the images render. There is no text. Is there something I'm needing to do or install beyond what asciidoc normally requires?

Also, it might not be a bad idea to put some additional information in the Readme about getting started (e.g. install npm, etc. - I can provide something if it would be worthwhile).

Sample file is located here

errors running `asciidoctorjs-pdf -v` on Win10 WSL node v10.15.0

After installing asciidoctor in a npm project with the following dependencies

  "dependencies": {
    "asciidoctor": "^2.0.3",
    "asciidoctor-pdf": "^1.0.0-alpha.1",
    "gulp-cli": "^2.2.0"
  },

I get the following error

require undefined
template-require undefined
backend undefined
doctype article
header-footer true
section-numbers false
quiet false
verbose true
timings false
trace false
base-dir undefined
destination-dir undefined
verbose-mode 2
attributes
options {"doctype":"article","safe":"unsafe","header_footer":true,"verbose":2,"timings":false,"trace":false,"to_file":false,"attributes":[]}
asciidoctorjs-pdf [files...]

Options:
  --help                  Show help                                                                            [boolean]
  --doctype, -d           document type to use when converting document
                                                  [choices: "article", "book", "manpage", "inline"] [default: "article"]
  --template-require      require the specified template script                                                 [string]
  --out-file, -o          output file (default: based on path of input file) use '' to output to STDOUT         [string]
  --safe-mode, -S         set safe mode level explicitly, disables potentially dangerous macros in source files, such as
                          include::[]                [choices: "unsafe", "safe", "server", "secure"] [default: "unsafe"]
  --no-header-footer, -s  suppress output of header and footer                                [boolean] [default: false]
  --section-numbers, -n   auto-number section titles in the HTML backend disabled by default  [boolean] [default: false]
  --base-dir, -B          base directory containing the document and resources (default: directory of source file)
                                                                                                                [string]
  --destination-dir, -D   destination output directory (default: directory of source file)                      [string]
  --quiet, -q             suppress warnings                                                   [boolean] [default: false]
  --trace                 include backtrace information on errors                             [boolean] [default: false]
  --verbose, -v           enable verbose mode                                                 [boolean] [default: false]
  --timings, -t           enable timings mode                                                 [boolean] [default: false]
  --attribute, -a         a document attribute to set in the form of key, key! or key=value pair                 [array]
  --require, -r           require the specified library before executing the processor, using the standard Node require
                                                                                                                 [array]
  --watch, -w             enable watch mode                                                   [boolean] [default: false]
  --version, -V           display the version and runtime environment (or -v if no other flags or arguments)
                                                                                              [boolean] [default: false]

when running node_modules/asciidoctor-pdf/bin/asciidoctorjs-pdf -v.

Using --version works fine 👍

Solving the assets path resolution maze

We have different layers of assets:

  • the ones relative to the template (JavaScript file)
  • the ones relative to the document (and/or its base-dir attribute)
  • the ones relative to the asciidoctor-pdf (embededd in the npm package)

The question is: what are the template assets relative to? The base-dir? The current working directory? The document?

Cannot reproduce all examples

Hi,

I'm trying out this tool, so far it's looking good with the default styles.
Then I wanted to try out the given examples (resume, book, etc), however not all documents look the same as in the readme (book and letter), also the slides one just doesn't work, it says : hljs is not defined. Do I need to install another global JS library to make it work?

Example with the book (left is mine, right is git repo) :
book

Example with letter (pdf on left, html on right which seems ok!) :
letter

For each file I used the following command line:
asciidoctor-pdf <file>.adoc --template-require ./template.js

So I was wondering if I'm missing some parameters in the command line or if the CSS files are not updated to what is seen on the repo.
They seem to have margins specified in it but for the book they just get ignored.

I'm using :

  • Ubuntu 18.04
  • Asciidoctor PDF 1.0.0-alpha.3 using Asciidoctor.js 2.0.3 (Asciidoctor 2.0.9)
  • node 13.1.0.

Can you reproduce the issue?

{indir} is not replaced in the content

Hello,

I was wondering what should be done to make the {indir} variable to be interpolated? I thought it was bound to -a safe=unsafe or -a experimental but it does not seem so.

I don't know if it's a limitation of this flavour of Asciidoctor.

How we should distribute this CLI

What I have in mind is something like:

npm i @asciidoctor/cli-pdf @asciidoctor/pdf-generator-default

Then you can convert a document to a PDF:

asciidoctorjs-pdf document.adoc

We could also publish other generator:

npm i @asciidoctor/pdf-generator-cheatsheet
asciidoctorjs-pdf document.adoc --generator cheatsheet

Of course it will be still possible to use local "generator":

asciidoctorjs-pdf document.adoc --generator ./generator.js

Please note that currently a generator is nothing more than a template converter but we could decide to introduce more features in the generator.

ping @oncletom @mojavelinux @matklad

Include the subtitle, the revision number, date, and remark on title page (if defined)

Warning "overflow on page" when late re-rendering of output occurs / missing content in PDF

Then testing the conversion of the "AsciiDoc Writer's guide" I had a situation when syntax highlighting on code snippets with highlightjs occurred after pagedjs already rendered the pages.
The warning "overflow on page" indicated something suspicious.

After some analysis it turned out that the late changes to the CSS after pagedjs layout changed the height of the contents of the page and trigged pagedjs' addResizeObserver. As the last paragraph didn't fit on the page any more, it was "overflowing". Looking at the resulting PDF it disappeared (!) from the page. That is: the complete last paragraph.

Expected behaviour: As this would leave the user with document that is missing content, rendering of the PDF shouldn't continue. Instead there should be an error.

I'll post a fix to remedy the situation with highlightjs. But This issue should be closed after this is no longer a warning, but an error that aborts creating the PDF.

Roles should be space-separated in templates

Currently, templates use

class="${node.getRoles()}"

This, however, joins roles via ,, which is not what we want. It should be this instead:

class="${node.getRoles().join(" ")}"

Is there some helper method we could use here instead of writing .join every time?

Rename repository?

Given that the project is now named Asciidoctor.js PDF, perhaps we should rename the repo?

Context: I am writing that promised blog post right now, and I want to name the project correctly.
By the way, here's the repository with slides: https://github.com/matklad/rust-course

Introduce a batch mode

When converting multiple documents it could be useful to launch the headless browser only once.
It could also reduce the time taken by the tests suite.

Create a layout inspired by the Pro Git 2nd Edition book

Source: https://github.com/progit/progit2
Result: https://progit2.s3.amazonaws.com/en/2016-03-22-f3531/progit-en.1084.pdf

Features:

  • Alternative offset if the page is on the left or on the right
  • Full width figure
  • Roman page numbers until the TOC
  • Chapter number and title on the top left corner (left page)
  • Title of the section on the top right corner (right page)
  • Page number on bottom right corner (right page)
  • Page number on bottom left corner (left page)
  • Appendix
  • Index

Provide ready to use templates

I did a workshop with a non-technical person and I think we should provide ready to use templates.
For instance a user could select a type of document : book, resume, letter, presentation, report...

We could also provide some presets about standard page A4, A5 with margins, bleeds...

We could expand this idea and also provide layouts : grid, columns 1/3 - 2/3.

Also I think we should by default use a more semantic HTML 5 converter.

And finally it can be hard at first to visually identify the document structure on a page. So maybe we could add an option to add a colored background or a border on each blocks... The same idea could be applied to bleeds and margins to make sure that a given text is not too close to a border (and won't be cut at printing).

Link to the custom stylesheet with a link element

We should use a <link> element to link to an external custom stylesheet (instead of inlining the content in a <style> element).
In debug mode, it will reduce the feedback loop as a user will be able to edit the custom stylesheet, refresh the browser and see the result.

Add admonitions example

This is googlable, but it's better to have this in one (all?) of the examples.

  • add :icons: font to doc attributes
  • add
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

to the <head> in the template.js

Apply a custom stylesheet/theme

We should introduce an attribute named pdf-style (or maybe use the stylesheet and stylesdir attributes ?) to provide a custom stylesheet.

I think the default style should be named default.css and we should support the @import directive. The idea is to be able to extend the default style:

@import 'default.css';

.role.red {
  color: #ff0000;
}

To avoid path resolution issues, we will probably need to replace the directive with the actual content.
default.css will be a reserved name.

It should also be possible to use @import to include stylesheets:

color.css

:root {
  --main-color: #2b2d2f;
}
@import 'default.css';
@import 'color.css';

.paragraph {
  color: var(--main-color);
}

.title {
  color: var(--main-color);
}

What are the OS requirements?

just tried to install asciidoctor-pdf.js on windows and had some problems.
So, here my quick question - has someone already tried to get it up and running on powershell or WSL?

Maybe it is also just because I am not used to node / npm, so I am missing some requirements.

I already figured out that I need to install

  • node.js which also installs npm from the website (https://nodejs.org/)
  • asciidoctor core (npm i -g asciidoctor core)
  • core needs "node-waf" which I can't find at the moment (seems to be deprecared and replaced by node-gyp, but installing this doesn't help)

any ideas? thanx!

Simple two column document

Hi,

I tried to create a simple two-column document with multiple pages, but I cannot make it work (using 1.0.0-alpha.3). The text does not flow as I want, see attached files.

Input:

Output (which does not look that nice):

Is two-column mode possible? If so, how?

It would be nice with a two column document example or pre-made styles/templates (#43) with multiple levels of sections and long paragraphs. The cheat-sheet example is close, but not simple to generalize.

Regards,
Mikael Brännström

Add a --watch option to the CLI to watch for changes and trigger the converter

We could rely on chokidar to watch for changes.
Since the template can reference external stylesheets/assets, we may need to parse the produced HTML to find out which file we need to monitor.

Another way to do it, would be to define the working directory in the command line (but if the stylesheets/assets is outside the working directory then it won't work)

Support of MathML

Out of curiosity I tried out how to enable Math support. The following quick hack worked surprisingly well using the "cheat-sheet" example.

I added to template.js the following snippet (copy and paste from AsciiDoc HTML document just before end of body tag):

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  messageStyle: "none",
  tex2jax: {
    inlineMath: [["\\(", "\\)"]],
    displayMath: [["\\[", "\\]"]],
    ignoreClass: "nostem|nolatexmath"
  },
  asciimath2jax: {
    delimiters: [["\\$", "\\$"]],
    ignoreClass: "nostem|noasciimath"
  },
  TeX: { equationNumbers: { autoNumber: "none" } }
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>

and some math to the maven-security-cheat-sheet.adoc file:

:stem: latexmath

[latexmath]
++++
\sqrt{4} = 2
++++

And I get a nice output:

math

I wonder:

  • should I add this to the default templates.js as a pull request so that creating PDFs with math works out of the box? Anything I should consider in the PR?
  • is there a way to extend the existing template? Or would the standard process copy the standard template first and the modify it?

Any advice is welcome, and I'm happy to provide a PR.

Add document metadata (title, author, subject, keywords...) to the PDF

Now that we are using pdf-lib, we can use the following functions to define document metadata:

PDFDocument.setTitle(string)
PDFDocument.setAuthor(string)
PDFDocument.setSubject(string)
PDFDocument.setKeywords(string[])
PDFDocument.setProducer(string)
PDFDocument.setCreator(string)
PDFDocument.setCreationDate(Date)
PDFDocument.setModificationDate(Date)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.