Skip to content

Commit

Permalink
resolves #254 support writing to STDOUT (and other IO objects)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jun 30, 2015
1 parent dde94ce commit d321764
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1949,11 +1949,25 @@ def add_outline_level outline, sections, num_levels, page_num_labels, numbering_
end

def write pdf_doc, target
pdf_doc.render_file target
if ::IO === target
if target == STDOUT
# NOTE we must use a substitute for STDOUT as it doesn't support .size()
::StringIO.open do |io|
pdf_doc.render io
io.rewind
target.write io.read
end
else
pdf_doc.render target
end
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
Expand Down

0 comments on commit d321764

Please sign in to comment.