From d66a1f7a4fb909ad5bd30680b2879a6416a49f71 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 28 Jul 2015 00:55:24 -0600 Subject: [PATCH] resolves #254 support writing to STDOUT (and other IO objects) - use Prawn's Document#render method if the target responds to the write method - wrap STDOUT to adapt it to work with Prawn / PDF Core --- lib/asciidoctor-pdf/converter.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/asciidoctor-pdf/converter.rb b/lib/asciidoctor-pdf/converter.rb index 5a40070b2..67b2df59e 100644 --- a/lib/asciidoctor-pdf/converter.rb +++ b/lib/asciidoctor-pdf/converter.rb @@ -2052,11 +2052,18 @@ def add_outline_level outline, sections, num_levels, page_num_labels, numbering_ end def write pdf_doc, target - pdf_doc.render_file target + if target.respond_to? :write + require_relative 'core_ext/quantifiable_stdout' unless defined? ::QuantifiableStdout + target = ::QuantifiableStdout.new STDOUT if target == STDOUT + pdf_doc.render target + else + pdf_doc.render_file target + # QUESTION restore attributes first? + @pdfmarks.generate_file target if @pdfmarks + end # write scratch document if debug is enabled (or perhaps DEBUG_STEPS env) #get_scratch_document.render_file 'scratch.pdf' - # QUESTION restore attributes first? - @pdfmarks.generate_file target if @pdfmarks + nil end def register_fonts font_catalog, scripts = 'latin', fonts_dir