class Hpdf::Doc
- Hpdf::Doc
- Reference
- Object
Included Modules
Defined in:
hpdf/doc.crConstructors
Class Method Summary
-
.build(&)
build enables DSL style access to building a doc
Instance Method Summary
-
#add_custom_page(klass)
custom pages are subclasses of
Page
that can have more methods for higher level page constructs. -
#add_page : Page
creates a new page and adds it after the last page of a document.
-
#add_page_label(page_num : Number, style : PageNumStyle, *, first_page = 1, prefix : String | Nil = nil)
adds a page labeling range for the document.
- #author : String | Nil
- #author=(v : String)
-
#build(&)
build enables DSL style access to building a doc
-
#compression_mode=(mode : CompressionMode)
set the mode of compression.
-
#create_outline(title : String, *, parent : Outline | Nil = nil, encoder : Encoder | Nil = nil) : Outline
creates a new outline object.
- #creation_date : Time | Nil
- #creation_date=(time : Time)
- #creator : String | Nil
- #creator=(v : String)
-
#current_page : Page | Nil
the handle of current page object.
-
#encoder : Encoder | Nil
gets the handle of the current encoder of the document object.
-
#encoder=(encoding_name : String)
sets the current encoder for the document.
-
#encoder=(enc : Encoder)
see
#encoder=
. -
#finalize
will free any related memory in case the document is not used any longer
-
#find_encoder(name : String) : Encoder
finds the handle of a corresponding encoder object by specified encoding name.
-
#font(name : String, encoding enc : String | Nil = nil)
gets the handle of a corresponding font object by specified name and encoding.
-
#insert_page(page : Page) : Page
creates a new page and inserts it just before the specified
#page
. - #keywords : String | Nil
- #keywords=(v : String)
-
#load_jpeg_image_from_file(file_name : String)
loads an external Jpeg image file.
-
#load_png_image_from_file(file_name : String, *, lazy : Bool = false) : Image
loads an external png image file.
-
#load_raw_image_from_file(file_name : String, width : Number, height : Number, color_space : ColorSpace) : Image
loads an image which has "raw" image format.
-
#load_raw_image_from_mem(buf, width : Number, height : Number, color_space : ColorSpace = ColorSpace::DeviceRgb, bits_per_component : UInt8 = 8)
loads an image which has "raw" image format from buffer.
-
#load_raw_image_from_mem(img : Raw::Image)
loads an image which has "raw" image format from buffer.
-
#load_tt_font_from_collection_file(file_name : String, index : Number, embedding : Bool = true) : String
loads a TrueType font from an TrueType collection file and register it to a document object.
-
#load_tt_font_from_file(file_name : String, embedding : Bool = true)
loads a TrueType font from an external file and register it to a document object.
-
#load_type1_font_from_file(afm_file : String, data_file : String | Nil = nil) : String
loads a type1 font from an external file and register it to a document object.
- #mod_date : Time | Nil
- #mod_date=(time : Time)
-
#open_action=(dst : Destination)
set the first page to appear when a document is opened.
-
#page(klass = Page, &)
page enables DSL style usage of the document.
-
#page_layout : PageLayout
the current setting for page layout.
-
#page_layout=(layout : PageLayout)
sets how the page should be displayed.
-
#page_mode : PageMode
the current setting for page mode.
-
#page_mode=(mode : PageMode)
sets how the document should be displayed.
-
#pages_configuration=(page_per_pages : Number)
In the default setting, a
Doc
object has one "Pages" object as root of pages. -
#save_to_file(path : String)
saves the current document to a file.
-
#set_password_and_permission(owner_password : String, *, user_password : String | Nil = nil, permission : Permission = Permission::EnableRead, encryption_mode : EncryptMode = EncryptMode::EncryptR3, encryption_key_len_bytes : Int32 = 16)
sets the pasword for the document.
- #subject : String | Nil
- #subject=(v : String)
- #title : String | Nil
- #title=(v : String)
-
#to_io : IO
writes the document to an in memory IO object.
- #to_unsafe : LibHaru::Doc
-
#use_cns_encodings
enables simplified Chinese encodings.
-
#use_cns_fonts
enables Japanese fonts.
-
#use_cnt_encodings
enables traditional Chinese encodings.
-
#use_cnt_fonts
enables Japanese fonts.
-
#use_jp_encodings
enables Japanese encodings.
-
#use_jp_fonts
enables Japanese fonts.
-
#use_kr_encodings
enables Korean encodings.
-
#use_kr_fonts
enables Japanese fonts.
Instance methods inherited from module Hpdf::Helper
bool(val : Bool) : Int32
bool,
nilable_str(v : Pointer(UInt8)) : String | Nil
nilable_str,
real(val : Number) : LibHaru::Real
real,
uint(val : Number) : LibHaru::UInt
uint,
uint16(val : Number) : UInt16
uint16
Constructor Detail
Class Method Detail
Instance Method Detail
custom pages are subclasses of Page
that can have more methods
for higher level page constructs.
class MyPage < Hpdf::Page
# ...
end
pdf = Hpdf::Doc.new do |pdf|
page = pdf.add_custom_page(MyPage)
# ...
creates a new page and adds it after the last page of a document.
adds a page labeling range for the document.
- page_num the first page that applies this labeling range.
- style the numbering style.
- first_page the first page number in this range.
- prefix the prefix for the page label.
creates a new outline object.
- title the caption of the outline object.
- parent the handle of an outline object which comes to the parent of the created outline object. If this parameter is 'nil', The outline is created as a root outline.
- encoder the handle of an encoding object applied to the title.
If 'nil' is set,
current_encoder
is used.
gets the handle of the current encoder of the document object.
The current encoder is set by invoking #encoder=
and it is used
to processing a text when an application changes document attributes.
The default value of it is 'nil'.
sets the current encoder for the document.
- encoding_name the name of an encoding. (See
Encodings
)
finds the handle of a corresponding encoder object by specified encoding name.
- name specify a valid encoding name, see
Encodings
gets the handle of a corresponding font object by specified name and encoding.
creates a new page and inserts it just before the specified #page
.
loads an external Jpeg image file.
- file_name path to a jpeg image file.
loads an external png image file.
- file_name path to a PNG image file.
- lazy if
true
does not load whole data immediately (only size and color properties is loaded). The main data is loaded just before the image object is written to PDF, and the loaded data is deleted immediately.
loads an image which has "raw" image format. This function loads the data without any conversion. So it is usually faster than the other functions.
#load_raw_image_from_file
can load 3 types of format described below.
- file_name path to a RAW image file.
- width the width of the image file.
- height the height of the image file.
- color_space
ColorSpace::DeviceGray
orColorSpace::DeviceRgb
orColorSpace::DeviceCmyk
is allowed.
ColorSpace::DeviceGray
The gray scale describes one pixel by one byte. And the size of the
image data is same as width * height
.
The sequence of the data is as follows.
1 |
2 |
3 |
4 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
ColorSpace::DeviceRgb
The 24bit RGB color image describes one pixel by 3 byte (each one byte
describes a value of either red, green or blue). And the size of the
image is same as width * height * 3
.
The sequence of the data is as follows.
1 |
1 |
1 |
2 |
2 |
2 |
3 |
3 |
3 |
4 |
4 |
4 |
6 |
6 |
6 |
7 |
7 |
7 |
8 |
8 |
8 |
9 |
9 |
9 |
11 |
11 |
11 |
12 |
12 |
12 |
13 |
13 |
13 |
14 |
14 |
14 |
ColorSpace::DeviceCmyk
The 36bit CMYK color image describes one pixel by 4 byte (each one
byte describes a value of either Cyan Magenta Yellow Black).
And the size of the image is same as width * height * 4
.
The sequence of the data is as follows.
1 |
1 |
1 |
1 |
2 |
2 |
2 |
2 |
3 |
3 |
3 |
3 |
4 |
4 |
4 |
4 |
6 |
6 |
6 |
6 |
7 |
7 |
7 |
7 |
8 |
8 |
8 |
8 |
9 |
9 |
9 |
9 |
11 |
11 |
11 |
11 |
12 |
12 |
12 |
12 |
13 |
13 |
13 |
13 |
14 |
14 |
14 |
14 |
loads an image which has "raw" image format from buffer. This function loads the data without any conversion. So it is usually faster than the other functions.
The formats that #load_raw_image_from_mem
can load is the same as #load_raw_image_from_file
.
- buf buffer with a raw memory image, has to implement
#unsafe
. - width the width of the image.
- height the height of the image.
- color_space
ColorSpace::DeviceGray
orColorSpace::DeviceRgb
orColorSpace::DeviceCmyk
is allowed. - bits_per_component The bit size of each color component. The valid value is either 1, 2, 4, 8.
loads an image which has "raw" image format from buffer. This function loads the data without any conversion. So it is usually faster than the other functions.
loads a TrueType font from an TrueType collection file and register it to a document object. Returns the name of a font.
- file_name path of a TrueType font collection file (.ttc).
- index index of font that wants to be loaded.
- embedding this parameter is set to
true
, the glyph data of the font is embedded, otherwise only the matrix data is included in PDF file.
loads a TrueType font from an external file and register it to a document object. Returns the name of a font.
- file_name path of a TrueType font file (.ttf).
- embedding this parameter is set to
true
, the glyph data of the font is embedded, otherwise only the matrix data is included in PDF file.
loads a type1 font from an external file and register it to a document object. Returns the name of a font.
- afm_file path of an AFM file.
- data_file path of a PFA/PFB file. If it is
nil
, the gryph data of font file is not embedded to a PDF file.
page enables DSL style usage of the document. It calls #add_page
and then executes the passed block in the context of the page.
- klass can be changed to a subclass of
Page
in order to create methods for higher level page constructs.
Example with custom page class
class MyPage < Hpdf::Page
# ...
end
Hpdf::Doc.build do |pdf|
page(MyPage) do |page|
# ...
end
end
sets how the page should be displayed. If this attribute is not set, the setting of the viewer application is used.
In the default setting, a Doc
object has one "Pages" object as root
of pages. All "Page" objects are created as a kid of the "Pages" object.
Since a "Pages" object can own only 8191 kids objects, the maximum number
of pages are 8191 page.
Additionally, the state that there are a lot of "Page" object under one "Pages" object is not good, because it causes performance degradation of a viewer application.
An application can change the setting of a pages tree by invoking
#pages_configuration=
. If page_per_pages parameter is set to more than
zero, a two-tier pages tree is created. A root "Pages" object can own
8191 "Pages" object, and each lower "Pages" object can own
page_per_pages "Page" objects. As a result, the maximum number of pages
becomes 8191 * page_per_pages page.
An application cannot invoke #pages_configuration=
after a page is added
to document.
sets the pasword for the document. If the password is set, contents in the document are encrypted.
- owner_password the password for the owner of the document.
The owner can change the permission of the document.
nil
, zero length string and the same value as user password are not allowed. - user_password the password for the user of the document.
The user_password is allowed to be set to
nil
or zero length string. - permission the flags specifying which operations are permitted. This parameter is set by logical addition of the following values.
writes the document to an in memory IO object. This will require memory for the size of the document.
enables simplified Chinese encodings. After #use_cns_encodings
is involed, an application can use the following simplified
Chinese encodings.
enables Japanese fonts. After #use_cns_fonts
is called, an application
can use the following simplified Chinese fonts: ChineseSimplifiedFonts::All
enables traditional Chinese encodings. After #use_cnt_encodings
is involed, an application can use the following traditional
Chinese encodings.
enables Japanese fonts. After #use_jp_fonts
is called, an application
can use the following traditional Chinese fonts: ChineseTraditionalFonts::All
enables Japanese encodings. After #use_jp_encodings
is involed,
an application can use the following Japanese encodings.
enables Japanese fonts. After #use_jp_fonts
is called, an application
can use the following Japanese fonts: JapaneseFonts::All
enables Korean encodings. After #use_kr_encodings
is involed, an application can use the following Korean encodings.
enables Japanese fonts. After #use_kr_fonts
is called, an application
can use the following Korean fonts: KoreanFonts::All