Apache License 2.0

项目介绍

bitcrowd/chromic_pdf 是一个托管在 GitHub 上的开源项目,主要使用 Elixir 编写,采用 Apache License 2.0 许可证,目前获得 485 个 Star、43 次 Fork。

仓库全名
bitcrowd/chromic_pdf
开源许可证
Apache License 2.0
Star 数
485
Fork 数
43
未关闭 Issue
11

README 摘要

ChromicPDF is a HTML-to-PDF renderer for Elixir, based on headless Chrome. Features Node-free: In contrast to many other packages, it does not use puppeteer, and hence does not require Node.js. It communicates directly with Chrome's DevTools API over pipes, offering the same performance as puppeteer, if not better. Header/Footer: Using the DevTools API allows to apply the full set of options of the printToPDF…

完整内容见 GitHub 原始 README 或本页 。

常见问题

chromic_pdf 用什么语言开发?

主要使用 Elixir 编写,采用 Apache License 2.0 许可证,目前有 485 个 Star。

chromic_pdf 可以免费商用吗?

仓库采用 Apache License 2.0 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 chromic_pdf 的源码?

可以直接克隆仓库:git clone https://github.com/bitcrowd/chromic_pdf.git,默认分支为 main;安装与运行步骤见仓库 README。

chromic_pdf 最近还在维护吗?

仓库最近一次更新为 3 周前,当前有 11 个未关闭 Issue;Star 数为 485,可作为社区活跃度的参考。

关于

Convenient HTML to PDF/A rendering library for Elixir based on Chrome & Ghostscript

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
584
价值分
304
活跃状态
活跃

语言占比

Elixir
HTML
PostScript

README

CircleCI Module Version Hex Docs Total Download License Last Updated

ChromicPDF is a HTML-to-PDF renderer for Elixir, based on headless Chrome.

Features

  • Node-free: In contrast to many other packages, it does not use puppeteer, and hence does not require Node.js. It communicates directly with Chrome’s DevTools API over pipes, offering the same performance as puppeteer, if not better.
  • Header/Footer: Using the DevTools API allows to apply the full set of options of the printToPDF function. Most notably, it supports header and footer HTML templates.
  • PDF/A: It can convert printed files to PDF/A using Ghostscript. Converted files pass the verapdf validator.

Requirements

  • Chromium or Chrome
  • Ghostscript (optional, for PDF/A support and concatenation of multiple sources)

ChromicPDF is tested in the following configurations:

Elixir Erlang/OTP Distribution Chromium Ghostscript
1.15.7 26.2 Alpine 3.18 119.0.6045.159 10.02.0
1.14.5 25.3.1 Alpine 3.17 112.0.5615.165 10.01.1
1.14.0 25.1 Debian Buster 90.0.4430.212-1 9.27

Installation

ChromicPDF is a supervision tree (rather than an application). You will need to inject it into the supervision tree of your application. First, add ChromicPDF to your runtime dependencies:

def deps do
  [
    {:chromic_pdf, "~> 1.17"}
  ]
end

Next, start ChromicPDF as part of your application:

# lib/my_app/application.ex
def MyApp.Application do
  def start(_type, _args) do
    children = [
      # other apps...
      ChromicPDF
    ]

    Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
  end
end

Usage

Main API

Here’s how you generate a PDF from an external URL and store it in the local filesystem.

# Prints a local HTML file to PDF.
ChromicPDF.print_to_pdf({:url, "https://example.net"}, output: "example.pdf")

The next example shows how to print a local HTML file to PDF/A, as well as the use of a callback function that receives the generated PDF as path to a temporary file.

ChromicPDF.print_to_pdfa({:url, "file:///example.html"}, output: fn pdf ->
  # Send pdf via mail, upload to S3, ...
end)

Template API

ChromicPDF.Template contains additional functionality for controlling page dimensions of your PDF.

[content: "<p>Hello Template</p>", size: :a4]
|> ChromicPDF.Template.source_and_options()
|> ChromicPDF.print_to_pdf()

Multiple sources

Multiple sources can be automatically concatenated using Ghostscript.

ChromicPDF.print_to_pdf([{:html, "page 1"}, {:html, "page 2"}], output: "joined.pdf")

Examples

  • There is an outdated example of how to integrate ChromicPDF in a Phoenix application, see examples/phoenix.

Development

This should get you started:

mix deps.get
mix test

For running the full suite of integration tests, please install and have in your $PATH:

  • verapdf
  • For pdfinfo and pdftotext, you need poppler-utils (most Linux distributions) or Xpdf (OSX)
  • For the odd ZUGFeRD test in zugferd_test.exs, you need to download ZUV and set the $ZUV_JAR environment variable.

Acknowledgements

Copyright © 2019–2023 Bitcrowd GmbH

Licensed under the Apache License 2.0. See LICENSE file for details.

评论

暂无评论