class Cairo::PdfSurface

Overview

The PDF surface is used to render cairo graphics to Adobe PDF files and is a multi-page vector surface backend.

The following mime types are supported:

###JBIG2 Images JBIG2 data in PDF must be in the embedded format as described in ISO/IEC 11544. Image specific JBIG2 data must be in Cairo::C::LibCairo::MIME_TYPE_JBIG2. Any global segments in the JBIG2 data (segments with page association field set to 0) must be in Cairo::C::LibCairo::MIME_TYPE_JBIG2_GLOBAL. The global data may be shared by multiple images. All images sharing the same global data must set Cairo::C::LibCairo::MIME_TYPE_JBIG2_GLOBAL_ID to a unique identifier. At least one of the images must provide the global data using Cairo::C::LibCairo::MIME_TYPE_JBIG2_GLOBAL. The global data will only be embedded once and shared by all JBIG2 images with the same Cairo::C::LibCairo::MIME_TYPE_JBIG2_GLOBAL_ID.

###CCITT Fax Images The Cairo::C::LibCairo::MIME_TYPE_CCITT_FAX mime data requires a number of decoding parameters These parameters are specified using Cairo::C::LibCairo::MIME_TYPE_CCITT_FAX_PARAMS.

Cairo::C::LibCairo::MIME_TYPE_CCITT_FAX_PARAMS mime data must contain a string of the form "param1=value1 param2=value2 ...".

Columns: [required] An integer specifying the width of the image in pixels.

Rows: [required] An integer specifying the height of the image in scan lines.

K : [optional] An integer identifying the encoding scheme used. < 0 is 2 dimensional Group 4, = 0 is Group3 1 dimensional, > 0 is mixed 1 and 2 dimensional encoding. Default is 0.

EndOfLine : [optional] If true end-of-line bit patterns are present. Default is false.

EncodedByteAlign : [optional] If true the end of line is padded with 0 bits so the next line begins on a byte boundary. Default is false.

EndOfBlock : [optional] If true the data contains an end-of-block pattern. Default is true.

BlackIs1 : [optional] If true 1 bits are black pixels. Default is false.

DamagedRowsBeforeError : [optional] An integer specifying the number of damages rows tolerated before an error occurs. Default is 0.

Boolean values may be "true" or "false", or 1 or 0.

These parameters are the same as the CCITTFaxDecode parameters in the PostScript Language Reference and Portable Document Format (PDF). Refer to these documents for further details.

An example Cairo::C::LibCairo::MIME_TYPE_CCITT_FAX_PARAMS string is: "Columns=10230 Rows=40000 K=1 EndOfLine=true EncodedByteAlign=1 BlackIs1=false"

Defined in:

cairo/pdf_surface.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Cairo::Surface

content : Content content, copy_page copy_page, create_for_rectangle(x : Float64, y : Float64, width : Float64, height : Float64) : Surface create_for_rectangle, create_observer(mode : SurfaceObserverMode) : Surface create_observer, create_similar(content : Content, width : Int32, height : Int32) : Surface create_similar, create_similar_image(format : Format, width : Int32, height : Int32) : Surface create_similar_image, data : Pointer(UInt8) data, device : Device device, device_offset : Point device_offset, device_offset=(offset : Point) device_offset=, device_scale : Point device_scale, device_scale=(scale : Point) device_scale=, extents : NamedTuple(extents: Rectangle, bounded: Bool) extents, fallback_resolution : Point fallback_resolution, fallback_resolution=(res : Point) fallback_resolution=, finalize finalize, finish finish, flush flush, font_options : FontOptions font_options, format : Format format, has_show_text_glyphs? : Bool has_show_text_glyphs?, height : Int32 height, ink_extents : Rectangle ink_extents, map_to_image(extents : RectangleInt | Nil) : Surface map_to_image, mark_dirty mark_dirty, mark_dirty_rectangle(x : Int32, y : Int32, width : Int32, height : Int32) mark_dirty_rectangle, mime_data(mime_type : String) : Bytes mime_data, observer_add_fill_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_fill_callback, observer_add_finish_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_finish_callback, observer_add_flush_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_flush_callback, observer_add_glyphs_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_glyphs_callback, observer_add_mask_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_mask_callback, observer_add_paint_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_paint_callback, observer_add_stroke_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_stroke_callback, observer_elapsed : Float64 observer_elapsed, observer_print(write_func : LibCairo::WriteFuncT, closure : Pointer(Void)) : Status observer_print, reference : Surface reference, reference_count : UInt32 reference_count, set_device_offset(x_offset : Float64, y_offset : Float64) set_device_offset, set_device_scale(x_scale : Float64, y_scale : Float64) set_device_scale, set_fallback_resolution(x_pixels_per_inch : Float64, y_pixels_per_inch : Float64) set_fallback_resolution, set_mime_data(mime_type : String, data : Bytes, destroy : LibCairo::DestroyFuncT, closure : Pointer(Void)) : Status set_mime_data, set_user_data(key : UserDataKey, user_data : Pointer(Void), destroy : LibCairo::DestroyFuncT) : Status set_user_data, status : Status status, stride : Int32 stride, supports_mime_type?(mime_type : String) : Bool supports_mime_type?, surface_show_page surface_show_page, to_unsafe : LibCairo::PSurfaceT to_unsafe, type : SurfaceType type, unmap_image(image : Surface) unmap_image, user_data(key : UserDataKey) : Pointer(Void) user_data, width : Int32 width, write_to_png(filename : String) : Status write_to_png, write_to_png_stream(write_func : LibCairo::WriteFuncT, closure : Pointer(Void)) : Status write_to_png_stream

Constructor methods inherited from class Cairo::Surface

new(data : Bytes, format : Format, width : Int32, height : Int32, stride : Int32)
new(format : Format, width : Int32, height : Int32)
new(read_func : LibCairo::ReadFuncT, closure : Pointer(Void))
new(content : Content, extents : Rectangle | Nil)
new(surface : LibCairo::PSurfaceT)
new(filename : String)
new

Constructor Detail

def self.new(write_func : LibCairo::WriteFuncT, closure : Pointer(Void), width_in_points : Float64, height_in_points : Float64) #

Creates a PDF surface of the specified size in points to be written incrementally to the stream represented by write_func and closure .

###Parameters

  • write_func a Cairo::C::LibCairo::WriteFuncT to accept the output data, may be nil to indicate a no-op write_func. With a no-op write_func, the surface may be queried or used as a source without generating any temporary files.
  • closure the closure argument for write_func
  • width_in_points width of the surface, in points (1 point == 1/72.0 inch)
  • height_in_points height of the surface, in points (1 point == 1/72.0 inch)

###Returns A pointer to the newly created Surface. The caller owns the surface and should call Surface#finalize when done with it.

This function always returns a valid pointer, but it will return a pointer to a "nil" surface if an error such as out of memory occurs. You can use Surface#status to check for this.


[View source]
def self.new(filename : String, width_in_points : Float64, height_in_points : Float64) #

Creates a PDF surface of the specified size in points to be written to filename.

###Parameters

  • filename a filename for the PDF output (must be writable), nil may be used to specify no output. This will generate a PDF surface that may be queried and used as a source, without generating a temporary file.
  • width_in_points width of the surface, in points (1 point == 1/72.0 inch)
  • height_in_points height of the surface, in points (1 point == 1/72.0 inch)

###Returns A pointer to the newly created Surface. The caller owns the surface and should call Surface#finalize when done with it.

This function always returns a valid pointer, but it will return a pointer to a "nil" surface if an error such as out of memory occurs. You can use Surface#status to check for this.


[View source]

Class Method Detail

def self.versions : Array(PdfVersion) #

Used to retrieve the list of supported versions. See PdfSurface#restrict_to_version.

###Returns Supported version list.


[View source]

Instance Method Detail

def add_outline(parent_id : Int32, name : String, link_attribs : String, flags : PdfOutlineFlags) : Int #

Add an item to the document outline hierarchy with the name that links to the location specified by link_attribs. Link attributes have the same keys and values as the Link Tag, excluding the "rect" attribute. The item will be a child of the item with id parent_id. Use Cairo::C::LibCaio::PDF_OUTLINE_ROOT as the parent id of top level items.

###Parameters

  • parent_id the id of the parent item or Cairo::C::LibCairo::PDF_OUTLINE_ROOT if this is a top level item.
  • name the name of the outline
  • link_attribs the link attributes specifying where this outline links to
  • flags outline item flags

###Returns The id for the added item.


[View source]
def page_label=(label : String) #

Set page label for the current page.

###Parameters

  • label The page label.

[View source]
def restrict_to_version(version : PdfVersion) #

Restricts the generated PDF file to version. See PdfSurface#versions for a list of available version values that can be used here.

This function should only be called before any drawing operations have been performed on the given surface. The simplest way to do this is to call this function immediately after creating the surface.

###Parameters

  • version PDF version

[View source]
def set_metadata(metadata : PdfMetadata, value : String) #

Set document metadata. The PdfMetadata::CreateDate and PdfMetadata::ModDate values must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss. An optional timezone of the form "[+/-]hh:mm" or "Z" for UTC time can be appended. All other metadata values can be any UTF-8 string.

For example:

surface.set_metadata(PdfMetadata::MetadataTitle, "My Document")
surface.set_metadata(PdfMetadata::CreateDate, "2015-12-31T23:59+02:00")

###Parameters

  • metadata The metadata item to set.
  • value metadata value

[View source]
def set_size(width_in_points : Float64, height_in_points : Float64) #

Changes the size of a PDF surface for the current (and subsequent) pages.

This function should only be called before any drawing operations have been performed on the current page. The simplest way to do this is to call this function immediately after creating the surface or immediately after completing a page with either Context#show_page or Context#copy_page.

###Parameters

  • width_in_points new surface width, in points (1 point == 1/72.0 inch)
  • height_in_points new surface height, in points (1 point == 1/72.0 inch)

[View source]
def set_thumbnail_size(width : Int32, height : Int32) #

Set the thumbnail image size for the current and all subsequent pages. Setting a width or height of 0 disables thumbnails for the current and subsequent pages.

###Parameters

  • width Thumbnail width.
  • height Thumbnail height

[View source]