Skip to content

Commit

Permalink
Update README and add dependabot
Browse files Browse the repository at this point in the history
Signed-off-by: Songlin Jiang <songlin.jiang@csc.fi>
  • Loading branch information
HollowMan6 committed Feb 7, 2024
1 parent 9b06b58 commit 29de991
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

[Blog](https://hollowmansblog.wordpress.com/2022/01/30/mdbook-pdf-a-mdbook-backend-for-generating-pdf-files/)

A backend for [mdBook](https://github.com/rust-lang/mdBook) written in Rust for generating PDF based on [headless chrome](https://github.com/atroche/rust-headless-chrome) and [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF).
A backend for [mdBook](https://github.com/rust-lang/mdBook) written in Rust for generating PDF based on [headless chrome](https://github.com/rust-headless-chrome/rust-headless-chrome) and [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF).

## Installation & Usage
Since it's a plugin (backend) for [mdBook](https://github.com/rust-lang/mdBook), first of all you should ensure that `mdbook` is available.
Expand All @@ -30,8 +30,7 @@ If your machine's architecture is `x86_64`, or you are using Linux for `ARM64`,

Otherwise, make sure the [rust compiling environment](https://www.rust-lang.org/tools/install) is available, execute `cargo install mdbook-pdf` to compile and install.

If you want to compile the latest version, make sure the Rust build environment is available (`cargo build`).
Then run `git clone https://github.com/HollowMan6/mdbook-pdf.git`, in the cloned folder, run `cargo build --release` , get the executable in `target/release/`, and put it in PATH.
If you want to compile the latest version, make sure the Rust build environment is available (`cargo build`). Run `cargo install --git https://github.com/HollowMan6/mdbook-pdf.git`, or alternatively, you can clone the repository and compile it yourself. (Run `git clone https://github.com/HollowMan6/mdbook-pdf.git`, in the cloned folder, run `cargo build --release` , get the executable in `target/release/`, and put it in PATH)

For running, please have Google Chrome / Chromium / Microsoft Edge already available (installed at the default location, in PATH or binary location configured). If not, and `mdbook-pdf` has the `fetch` feature enabled (It is not enabled by default, you need to use `cargo install mdbook-pdf --features fetch` to recompile for enabling), the program will try to automatically download the Chromium browser and run it (Note: if you are on Linux, there may be problems if chromium dependencies are not satisfied / using non-x86_64 architectures).

Expand Down Expand Up @@ -83,24 +82,23 @@ docker run --rm -v /path/to/book:/book -v ~/.cargo/bin:/mdbook hollowman6/mdbook
## Configuration
Support customize PDF paper orientation, scale of the webpage rendering, paper width and height, page margins, generated PDF page ranges, whether to display header and footer as well as customize their formats, and more.

Check [book.toml](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L10-L36) and comments for details for the available configurations of `[output.pdf]`.
Check [book.toml](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L10-L39) and comments for details for the available configurations of `[output.pdf]`.

## Common Issues
1. Support for Firefox in `mdbook-pdf`!

Currently, according to [Puppeteer's documentation](https://pptr.dev/#?product=Puppeteer&show=api-pagepdfoptions), [Chrome DevTools Protocol Page.printToPDF](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF) is only supported in Chrome headless. An issue has already been filed for this [here](https://github.com/puppeteer/puppeteer/issues/7628).
Currently, although Puppeteer supports something similar to [Chrome DevTools Protocol Page.printToPDF](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF) according to its [documentation](https://pptr.dev/api/puppeteer.page.pdf), [rust-headless-chrome](https://github.com/rust-headless-chrome/rust-headless-chrome) doesn't.

2. Broken links!

I've already submitted [a PR for mdBook](https://github.com/rust-lang/mdBook/pull/1738) to fix this by making print page (print.html) links link to anchors on the print page, but it's not merged yet. You can try [my PR fork](https://github.com/HollowMan6/mdBook) for this to work.

If you have relative links that link outside the book, please provide the [static hosting site URL](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L17-L18) for it to get fixed.
If you have relative links that link outside the book, please provide the [static hosting site URL](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L19-L20) for it to get fixed.

3. Can you add the bookmark to the PDF reflecting the Table of Contents, just like what [wkhtmltopdf](https://wkhtmltopdf.org/) supported?
3. Can you add the bookmark to the PDF reflecting the Table of Contents, just like what [wkhtmltopdf](https://wkhtmltopdf.org/) is supported?

This should be realized by Chromium, and an issue has already been filed for this [here](https://bugs.chromium.org/p/chromium/issues/detail?id=781797).

Initial support for the bookmark/outline of the PDF file has already been available ([mdbook-pdf-outline](https://pypi.org/project/mdbook-pdf-outline/)). It is written in Python and is another backend for `mdbook` and should be used with `mdbook-pdf` and ***the [mdbook version](https://github.com/rust-lang/mdBook/pull/1738) mentioned in Common Issues 2 (by `cargo install --git https://github.com/HollowMan6/mdBook mdbook` instead) for fixing the broken links in `print.html`***.
~~This should be realized by Chromium, and an issue has already been filed for this [here](https://issues.chromium.org/issues/40038778).~~
Initial support for the bookmark/outline of the PDF file has already been available ([mdbook-pdf-outline](https://pypi.org/project/mdbook-pdf-outline/)). It is written in Python and is another backend for `mdbook` and should be used with `mdbook-pdf` and ***the [modified mdbook](https://github.com/rust-lang/mdBook/pull/1738) mentioned in Common Issues 2 (by `cargo install --git https://github.com/HollowMan6/mdBook mdbook` instead) for fixing the broken links in `print.html`***.

You can install this backend by `pip install mdbook-pdf-outline`.

Expand All @@ -121,7 +119,16 @@ like-wkhtmltopdf = true

Finally, you can find the outlined version at `book/pdf-outline/output.pdf`.

4. Failed to render my book for PDF in `mdbook-pdf`!
4. Force page breaks in the markdown source that is respected by mdbook-pdf!

Referring to [#9](https://github.com/HollowMan6/mdbook-pdf/discussions/9#discussioncomment-4895678), you can use the following syntax to force page breaks in the markdown source:

```markdown
<div style="page-break-before:always">&nbsp;</div>
<p></p>
```

5. Failed to render my book for PDF in `mdbook-pdf`!

Will appreciate if you can report it to the [issue tracker](https://github.com/HollowMan6/mdbook-pdf/issues/new) providing all the traces for `mdbook-pdf` rendering as well as your `book.toml`. You can also provide the link to your book's repository if it's open source.

Expand Down
27 changes: 18 additions & 9 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
![mdbook-pdf build](https://github.com/HollowMan6/mdbook-pdf/workflows/mdbook-pdf%20build/badge.svg)
![mdbook-pdf test](https://github.com/HollowMan6/mdbook-pdf/workflows/mdbook-pdf%20test/badge.svg)


[![Followers](https://img.shields.io/github/followers/HollowMan6?style=social)](https://github.com/HollowMan6?tab=followers)
[![watchers](https://img.shields.io/github/watchers/HollowMan6/mdbook-pdf?style=social)](https://github.com/HollowMan6/mdbook-pdf/watchers)
[![stars](https://img.shields.io/github/stars/HollowMan6/mdbook-pdf?style=social)](https://github.com/HollowMan6/mdbook-pdf/stargazers)
Expand All @@ -19,7 +20,7 @@

[博客](https://blog.csdn.net/qq_18572023/article/details/122753374)

用 Rust 编写的 [mdBook](https://github.com/rust-lang/mdBook) 后端,基于[headless chrome](https://github.com/atroche/rust-headless-chrome)[Chrome开发工具协议](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF)生成PDF。
用 Rust 编写的 [mdBook](https://github.com/rust-lang/mdBook) 后端,基于[headless chrome](https://github.com/rust-headless-chrome/rust-headless-chrome)[Chrome开发工具协议](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF)生成PDF。

## 安装和使用
由于它是 [mdBook](https://github.com/rust-lang/mdBook) 的插件(后端),首先您应该确保 `mdbook` 可用。
Expand All @@ -28,7 +29,7 @@

否则,确保 [rust 编译环境](https://www.rust-lang.org/tools/install)可用,执行`cargo install mdbook-pdf`编译安装即可。

如果需要最新版的编译二进制文件,请确保 Rust 编译环境可用(`cargo build`),然后执行`git clone https://github.com/HollowMan6/mdbook-pdf.git`,在然后在克隆下来的文件夹中运行`cargo build --release`,在`target/release/`中获取可执行文件,并将其放入PATH
如果需要最新版的编译二进制文件,请确保 Rust 编译环境可用(`cargo build`),运行 `cargo install --git https://github.com/HollowMan6/mdbook-pdf.git`,或者,您可以克隆存储库并自行编译。(执行`git clone https://github.com/HollowMan6/mdbook-pdf.git`,在然后在克隆下来的文件夹中运行`cargo build --release`,在`target/release/`中获取可执行文件,并将其放入PATH

为了使得程序能够正常运行,请确保计算机上在运行本程序之前已经安装了 Google Chrome / Chromium / Microsoft Edge,(安装在默认的位置,在当前的PATH中,或配置了二进制文件位置)。如果没有安装,并且程序启用了`fetch`功能(默认未开启,需使用`cargo install mdbook-pdf --features fetch`重新编译开启),程序将会尝试自动下载 Chromium 浏览器并运行(注意:如在Linux中使用可能会存在chromium依赖不满足/非x86_64无法适配的问题)。

Expand Down Expand Up @@ -80,7 +81,7 @@ docker run --rm -v /path/to/book:/book -v ~/.cargo/bin:/mdbook hollowman6/mdbook
## 配置
支持自定义PDF纸张方向、页面缩放比例、纸张宽度和高度、页面边距、生成的PDF页面范围、是否显示页眉和页脚以及自定义其格式等。

查看 [book.toml](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L10-L36) 以了解 `[output.pdf]` 可用配置的详细信息。
查看 [book.toml](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L10-L39) 以了解 `[output.pdf]` 可用配置的详细信息。

### 具体参数详解
- trying-times
Expand Down Expand Up @@ -171,20 +172,19 @@ docker run --rm -v /path/to/book:/book -v ~/.cargo/bin:/mdbook hollowman6/mdbook

## 常见问题
1.`mdbook-pdf`支持火狐!

目前,根据[Puppeteer的文档](https://pptr.dev/#?product=Puppeteer&show=api-pagepdfoptions)[Chrome 开发工具协议 Page.printToPDF](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF) 仅在 Chrome 无头模式中受支持。目前已经有人为此提交了一个[议题](https://github.com/puppeteer/puppeteer/issues/7628)
目前,尽管 Puppeteer 根据其[文档](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF),已经支持类似于[Chrome 开发工具协议 Page.printToPDF](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF)的东西,[rust-headless-chrome](https://github.com/rust-headless-chrome/rust-headless-chrome) 并没有。

2. 链接损坏!

我已经提交了[一个 mdBook 的拉取请求](https://github.com/rust-lang/mdBook/pull/1738),该拉取请求通过将打印页面 (print.html) 上的链接指向打印页面上的锚点来解决此问题,但尚未合并。您可以尝试[我的拉取请求分支](https://github.com/HollowMan6/mdBook) 以使其正常工作。

如果你的书中有书以外的相对路径链接,请提供[静态网站托管URL](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L17-L18)以便修复。
如果你的书中有书以外的相对路径链接,请提供[静态网站托管URL](https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L19-L20)以便修复。

3. 可以像[wkhtmltopdf](https://wkhtmltopdf.org/)支持的那样,在PDF中添加书签来反映目录吗?

这应该由 Chromium 实现,并且目前已经有人为此提交了一个[议题](https://bugs.chromium.org/p/chromium/issues/detail?id=781797)
~~这应该由 Chromium 实现,并且目前已经有人为此提交了一个[议题](https://issues.chromium.org/issues/40038778)

已经初步实现了对PDF文件书签/大纲的支持([mdbook-pdf-outline](https://pypi.org/project/mdbook-pdf-outline/)). 它是`mdbook`的另一个后端,用Python编写,应与`mdbook-pdf`和常见问题2中提到的修复了`print.html`中损坏链接的[mdbook版本](https://github.com/rust-lang/mdBook/pull/1738) (通过 `cargo install --git https://github.com/HollowMan6/mdBook mdbook`安装) 一起使用。
已经初步实现了对PDF文件书签/大纲的支持([mdbook-pdf-outline](https://pypi.org/project/mdbook-pdf-outline/). 它是`mdbook`的另一个后端,用Python编写,应与`mdbook-pdf`和常见问题2中提到的修复了`print.html`中损坏链接的[mdbook版本](https://github.com/rust-lang/mdBook/pull/1738)通过 `cargo install --git https://github.com/HollowMan6/mdBook mdbook`安装一起使用。

您可以通过`pip install mdbook-pdf-outline`安装此后端。

Expand All @@ -205,7 +205,16 @@ like-wkhtmltopdf = true

最后,您可以在`book/pdfoutline/output.pdf`中找到带有大纲/目录的版本。

4. 无法在 `mdbook-pdf` 中将我的书呈现为 PDF!
4. 在 mdbook-pdf 所遵循的 Markdown 源中强制分页!

参考[#9](https://github.com/HollowMan6/mdbook-pdf/discussions/9#discussioncomment-4895678),您可以使用以下语法在markdown源中强制分页:

```markdown
<div style="page-break-before:always">&nbsp;</div>
<p></p>
```

5. 无法在 `mdbook-pdf` 中将我的书呈现为 PDF!

如果您能将它报告给[问题跟踪器](https://github.com/HollowMan6/mdbook-pdf/issues/new),并提供`mdbook-pdf`渲染时产生的所有跟踪,以及`book.toml`配置文件,和书的仓库地址(如果有的话),将不胜感激。

Expand Down

0 comments on commit 29de991

Please sign in to comment.