Module: Vivlio::PDF
- Defined in:
- lib/vivlio/pdf.rb,
lib/vivlio/pdf/result.rb,
lib/vivlio/pdf/source.rb,
lib/vivlio/pdf/viewer.rb,
lib/vivlio/pdf/outline.rb,
lib/vivlio/pdf/printer.rb,
lib/vivlio/pdf/session.rb,
lib/vivlio/pdf/version.rb,
lib/vivlio/pdf/document.rb,
lib/vivlio/pdf/metadata.rb,
lib/vivlio/pdf/toc_item.rb,
lib/vivlio/pdf/local_file.rb,
lib/vivlio/pdf/staged_file.rb
Overview
HTML, unzipped EPUB, or webpub → PDF, rendered by the Vivliostyle Viewer in a local Chrome/Chromium driven over CDP. No Node.js required.
Defined Under Namespace
Modules: Outline, StagedFile Classes: BrowserError, Document, Error, LocalFile, Metadata, Printer, RenderError, Result, Session, Source, TimeoutError, TocItem, Viewer
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
-
.print(source:, output:, **options) ⇒ Object
Converts one document, starting and stopping a browser around it.
-
.translate_browser_errors ⇒ Object
How we drive Chrome is an implementation detail, so Ferrum's exceptions are translated at every point they can escape: callers only ever have to rescue Vivlio::PDF::Error.
Class Method Details
.print(source:, output:, **options) ⇒ Object
Converts one document, starting and stopping a browser around it. Prefer a Printer when converting several documents in a row.
Options are split between the browser session and the conversion by Printer::SETUP_OPTIONS and Printer::PRINT_OPTIONS; anything else is a typo, and saying so beats silently ignoring it.
Vivlio::PDF.print(source: 'book/OEBPS/package.opf', output: 'book.pdf')
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vivlio/pdf.rb', line 45 def self.print(source:, output:, **) unknown = .keys - Printer::SETUP_OPTIONS - Printer::PRINT_OPTIONS unless unknown.empty? raise ArgumentError, "unknown keyword#{'s' if unknown.size > 1}: " \ "#{unknown.map(&:inspect).join(', ')}" end Printer.open(**.slice(*Printer::SETUP_OPTIONS)) do |printer| printer.print(source: source, output: output, **.slice(*Printer::PRINT_OPTIONS)) end end |
.translate_browser_errors ⇒ Object
How we drive Chrome is an implementation detail, so Ferrum's exceptions are translated at every point they can escape: callers only ever have to rescue Vivlio::PDF::Error.
SystemCallError too: spawning the browser raises Errno::ENOENT when browser_path points at nothing, and inside these blocks an OS-level failure is a browser failure.
29 30 31 32 33 34 35 |
# File 'lib/vivlio/pdf.rb', line 29 def self.translate_browser_errors yield rescue Ferrum::TimeoutError => e raise TimeoutError, e. rescue Ferrum::Error, SystemCallError => e raise BrowserError, e. end |