class PDF::Document

Overview

A canonical PDF file initially consists of four elements :

The body of a PDF file consists of a sequence of indirect objects representing the contents of a document. The objects, which are of the basic types described in Section 3.2, “Objects,” represent components of the document such as fonts, pages, and sampled images.

in the code we should pretain the document structure, not the actual text te output. the real form will be generated at render time

Defined in:

pdf/document/crossref.cr
pdf/document/document.cr
pdf/document/encrypt.cr
pdf/document/header.cr
pdf/document/trailer.cr

Constant Summary

EOF = "%%EOF"

Constructors

Instance Method Summary

Constructor Detail

def self.new(header : PDF::Document::Header, body : PDF::Catalog, crossrefs, trailers : PDF::Document::Trailer) #

[View source]

Instance Method Detail

def crossrefs(ids : Hash(Object, Int32)) : CrossRef #

[View source]
def render_to_pdf(io : IO) #

Outputing a pdf into bytes is easier than reading it. We needn't support all pdf formats,but just our subset to use.

writing a pdf is really fast,because it's just flatten objects into some bytes.

  • output header。
  • remove all unuesed objects
  • renumber objects from 1 to n
  • output objects from number 1, counting each obj in the crossref
  • output crossref
  • output trailer, and trailer dictionary
  • output EOF

[View source]