class

Hpdf::Page

Inherits Hpdf::Helper / Reference / Object

The page handle is used to operate an individual page. When Doc#add_page or Doc#insert_page is invoked, a page object is created.

Constructors

new(page : LibHaru::Page, doc : Doc)
Source

Instance methods

arc(x : Number, y : Number, ray : Number, ang1 : Number, ang2 : Number)

appends a circle to the current path. An application can invoke arc when the graphics_mode of the page is in GMode::PageDescription or GMode::PathObject.

  • x, y the center point of the circle.
  • ray the ray of the circle.
  • ang1 the angle of the begining of the arc.
  • ang2 the angle of the end of the arc. It must be greater than ang1.
Source
begin_text

begins a text object and sets the current text position to the point (0, 0). An application can invoke begin_text when the graphics mode of the page is in GMode::PageDescription. And it changes the graphics mode to GMode::TextObject.

Source
build

build enables DSL style access to building a page

Source
char_space

gets the current value of the page's character spacing.

Source
char_space=(value : Number)

sets the character spacing for text showing. The initial value of character spacing is 0. An application can invoke char_space= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

  • value the value of character spacing.
Source
circle(x : Number, y : Number, ray : Number)

appends a circle to the current path. An application can invoke circle when the graphics_mode of the page is in GMode::PageDescription or GMode::PathObject.

  • x, y the center point of the circle.
  • ray the ray of the circle.
Source
clip

clip modifies the current clipping path by intersecting it with the current path using the nonzero winding number rule. The clipping path is only modified after the succeeding painting operator. To avoid painting the current path, use the function end_path.

Following painting operations will only affect the regions of the page contained by the clipping path. Initially, the clipping path includes the entire page. There is no way to enlarge the current clipping path, or to replace the clipping path with a new one. The functions g_save and g_restore may be used to save and restore the current graphics state, including the clipping path.

Source
close_path

appends a strait line from the current point to the start point of sub path. The current point is moved to the start point of sub path. An application can invoke close_path when the graphics mode of the page is in GMode::PathObject.

Source
close_path_eofill_stroke

closes the current path, fills the current path using the even-odd rule, then it paints the path. An application can invoke close_path_eofill_stroke when the graphics_mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
close_path_fill_stroke

closes the current path, fills the current path using the nonzero winding number rule, then it paints the path. An application can invoke close_path_fill_stroke when the graphics mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
close_path_stroke

closes the current path, then it paints the path. An application can invoke close_path_stroke when the graphics mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
cmyk_fill

returns the current value of the page's filling color. cmyk_fill is valid only when the page's filling color space is ColorSpace::DeviceCmyk.

Source
cmyk_stroke

returns the current value of the page's stroking color. cmyk_stroke is valid only when the page's stroking color space is ColorSpace::DeviceCmyk.

Source
concat(a : Number, b : Number, c : Number, d : Number, x : Number, y : Number)

concatenates the page's current transformation matrix and specified matrix. For example, if you want to rotate the coordinate system of the page by 45 degrees, use concat as like demonstrated in the rotate method. An application can invoke concat when the graphics_mode of the page is in GMode::PageDescription.

Example to change the dpi using concat

concat 72 / dpi, 0, 0, 72 / dpi, 0, 0

Example rotate 45 degrees

rad1 = degree / 180 * Math::PI
context do
  concat Math.cos(rad1), Math.sin(rad1), -Math.sin(rad1),
    Math.cos(rad1), 0, 0
  text Hpdf::Base14::Helvetica, 70 do
    text_out 100, 100, "Hello World"
  end
end
Source
context

saves the current graphic state and restores it after the block is completed

Source
create_destination

creates a new destination object for the page.

Source
create_text_annotation(rect : Rectangle, text : String, encoder : Encoder | Nil = nil) : TextAnnotation

creates a new text annotation object for the page.

  • rect a rectangle where the annotation is displayed
  • text the text to be displayed.
  • encoder an encoder handle which is used to encode the text. If it is null, PDFDocEncoding is used.
Source
create_x_object_as_white_rect(rect : Rectangle) : XObject

creates a white rectangle form XObject within rect. The returned XObject can be drawn repeatedly with execute_x_object.

  • rect the bounding rectangle for the white rectangle XObject on the page.
Source
create_x_object_from_image(rect : Rectangle, image : Image, zoom : Bool = true) : XObject

wraps image as a form XObject within rect. If zoom is true, the image is scaled to fill the rectangle. The returned XObject can be drawn repeatedly with execute_x_object.

  • rect the bounding rectangle for the XObject on the page.
  • image the image to embed as a form XObject.
  • zoom if true, the image is scaled to fill rect.
Source
current_font

gets the handle of the page's current font.

Source
current_font_size

gets the size of the page's current font. It returns the size of the page's current font. Otherwise it returns 0.

Source
current_pos

gets the current position for path painting. It returns a Point struct indicating the current position for path painting of the page. Otherwise it returns a Point struct of {0, 0}.

An application can invoke #current_pos only when graphics mode is GMode::PathObject.

Source
current_text_pos

gets the current position for text showing. It returns a Point struct indicating the current position for text showing of the page. Otherwise it returns a Point struct of {0, 0}.

An application can invoke current_text_pos only when graphics mode is GMode::TextObject.

Source
curve_to(x1 : Number, y1 : Number, x2 : Number, y2 : Number, x3 : Number, y3 : Number)

appends a Bézier curve to the current path using two specified points. The point (x1, y1) and the point (x2, y2) are used as the control points for a Bézier curve and current point is moved to the point (x3, y3). An application can invoke curve_to when the graphics mode of the page is in GMode::PathObject.

  • x1, y1, x2, y2, x3, y3 the control points for a Bézier curve.

http://libharu.sourceforge.net/image/figure20.png

Source
curve_to(p1 : Point, p2 : Point, p3 : Point)

see curve_to

Source
curve_to2(x1 : Number, y1 : Number, x2 : Number, y2 : Number)

appends a Bézier curve to the current path using two spesified points. The current point and the point (x2, y2) are used as the control points for a Bézier curve and current point is moved to the point (x3, y3). An application can invoke curve_to2 when the graphics mode of the page is in GMode::PathObject.

http://libharu.sourceforge.net/image/figure21.png

Source
curve_to2(p1 : Point, p2 : Point)

see curve_to2

Source
curve_to3(x1 : Number, y1 : Number, x2 : Number, y2 : Number)

appends a Bézier curve to the current path using two spesified points. The point (x1, y1) and the point (x3, y3) are used as the control points for a Bézier curve and current point is moved to the point (x3, y3). An application can invoke curve_to3 when the graphics mode of the page is in GMode::PathObject.

http://libharu.sourceforge.net/image/figure22.png

Source
curve_to3(p1 : Point, p2 : Point)

see curve_to3

Source
dash

gets the current pattern of the page. First argument is the pattern, second is the phase.

Source
dpi=(dpi : Number)

change the DPI of the page using concat

Source
draw_image(image : Image, x : Number, y : Number, width : Number, height : Number)

shows an image in one operation. An application can invoke draw_image when the graphics_mode of the page is in GMode::PageDescription.

  • image the image object.
  • x, y the lower-left point of the region where image is displayed.
  • width the width of the region where image is displayed.
  • height the width of the region where image is displayed.
Source
draw_image(image : Image, rect : Rectangle)

see draw_image.

Source
draw_rectangle(x : Number, y : Number, w : Number, h : Number, *, line_width lw : Number = 1)

draws a rectangle with the given coordinates and linw width

Source
draw_rectangle(rect : Rectangle, *, line_width lw = 1)

draws a rectangle with the given rectangle and linw width

Source
ellipse(x : Number, y : Number, xray : Number, yray : Number)

appends an ellipse to the current path. An application can invoke ellipse when the graphics_mode of the page is in GMode::PageDescription or GMode::PathObject.

  • x, y the center point of the ellipse.
  • xray the horizontal radius.
  • yray the vertical radius.
Source
end_path

ends the path object without filling and painting operation. An application can invoke end_path when the graphics_mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
eoclip

clip modifies the current clipping path by intersecting it with the current path using the even-odd rule. The clipping path is only modified after the succeeding painting operator. To avoid painting the current path, use the function end_path.

Following painting operations will only affect the regions of the page contained by the clipping path. Initially, the clipping path includes the entire page. There is no way to enlarge the current clipping path, or to replace the clipping path with a new one. The functions g_save and g_restore may be used to save and restore the current graphics state, including the clipping path. HPDF_Page_Clip() modifies the current clipping path by intersecting it with the current path using the even-odd rule. The clipping path is only modified after the succeeding painting operator. To avoid painting the current path, use the function HPDF_Page_EndPath().

Source
eofill

fills the current path using the even-odd rule. An application can invoke eofill when the graphics_mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
eofill_stroke

fills the current path using the even-odd rule, then it paints the path. An application can invoke eofill_stroke when the graphics mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
execute_x_object(obj : XObject)

draws the XObject using the current graphics context.

Source
ext_g_state=(gs : ExtGState)

applys the graphics state to the page. An application can invoke ext_g_state= when the graphics_mode of the page is in GMode::PageDescription.

Source
fill

fills the current path using the nonzero winding number rule. An application can invoke fill when the graphics_mode of thepage is inGMode::PathObjectorGMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription`.

Source
fill_stroke

fills the current path using the nonzero winding number rule, then it paints the path. An application can invoke fill_stroke when the graphics_mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
filling_color_space

returns the current value of the page's stroking color space.

Source
flat

gets the current value of the page's flatness.

Source
flat=(value : Number)

sets the flatness tolerance for curve rendering. value must be in the range 0–100.

Source
font

get the current font if any

Source
g_mode

see graphics_mode.

Source
g_restore

restore the graphics state which is saved by g_save. An application can invoke g_save when the graphics_mode of the page is in GMode::PageDescription.

Source
g_save

saves the page's current graphics parameter to the stack. An application can invoke g_save up to 28 and can restore the saved parameter by invoking g_restore, when the graphics_mode of the page is in GMode::PageDescription.

Source
g_state_depth

returns the number of the page's graphics state stack.

Source
graphics_mode

gets the current graphics mode.

Source
gray_fill

returns the current value of the page's filling color. gray_fill is valid only when the page's stroking color space is ColorSpace::DeviceGray.

Source
gray_fill=(value : Number)

sets the filling color. An application can invoke gray_fill= when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • value the value of the gray level between 0 and 1.
Source
gray_stroke

returns the current value of the page's stroking color. gray_fill is valid only when the page's stroking color space is ColorSpace::DeviceGray.

Source
gray_stroke=(value : Number)

sets the stroking color. An application can invoke gray_stroke= when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • value the value of the gray level between 0 and 1.
Source
height

gets the height of a page.

Source
height=(h : Number)

changes the height of a page.

  • h Specify the new height of a page. The valid value is between 3 and 14400.
Source
horizontal_scaling

returns the current value of the page's horizontal scaling for text showing.

Source
horizontal_scalling=(value : Number)

sets the horizontal scalling for text showing. The initial value of horizontal scalling is 100. An application can invoke horizontal_scalling= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

Source
line_cap

gets the current line cap style of the page.

Source
line_cap=(line_cap : LineCap)

sets the shape to be used at the ends of line. An application can invoke line_cap= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

  • line_cap the style of line-cap.
Source
line_join

gets the current line join style of the page

Source
line_join=(line_join : LineJoin)

Sets the line join style in the page. An application can invoke line_join= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

  • line_join the style of line-join.
Source
line_to(x : Number, y : Number)

appends a path from the current point to the specified point. An application can invoke line_to when the graphics_mode of the page is in GMode::PathObject.

  • x, y the end point of the path
Source
line_to(p : Point)

see line_to

Source
line_width

gets the current line width of the page. It returns the current line width for path painting of the page. Otherwise it returns 1.

Source
line_width=(line_width : Number)

sets the width of the line used to stroke a path. An application can invoke line_width= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

  • line_width the width of line.
Source
measure_text(text : String, *, width : Number, word_wrap : Bool = true) : MeasuredText

calculates the byte length which can be included within the specified width.

  • text the text to get the width for.
  • width The width of the area to put the text.
  • word_wrap Assume there are three words "ABCDE FGH IJKL", and the substring until "J" can be included within the width. If word_wrap parameter is false, 12 characters can be included; if word_wrap is true, only 10 characters will fit, i.e. until the end of the previous word. This value is available as property len_included in the returned MeasuredText struct.
Source
measure_text_width(text : String) : MeasuredText

measures the passed text width using the current font and font size. An application can invoke measure_text_width when the graphics_mode of the page is in GMode::TextObject.

Source
miter_limit

gets the current value of the page's miter limit.

Source
miter_limit=(limit : Number)
Source
move_text_pos(x : Number, y : Number)

moves the current text position to the start of the next line with using specified offset values. If the start position of the current line is (x1, y1), the start of the next line is (x1 + x, y1 + y). An application can invoke move_text_pos when the graphics_mode of the page is in GMode::TextObject.

  • x, y the offset of the start of the next line.
Source
move_to(x : Number, y : Number)

starts a new subpath and move the current point for drawing path, move_to sets the start point for the path to the point (x, y) and changes the graphics mode to GMode::PathObject.

An application can invoke move_to when the graphics_mode of the page is in GMode::PageDescription or GMode::PathObject.

  • x, y the start point for drawing path
Source
move_to(p : Point)

see move_to

Source
move_to_next_line

moves the current text position to the start of the next line. If the start position of the current line is (x1, y1), the start of the next line is (x1, y1 - text leading). An application can invoke move_to_next_line when the graphics mode of the page is in GMode::TextObject.

NOTE: Since the default value of Text Leading is 0, an application has to invoke text_leading= before move_to_next_line to set text leading.

Source
page_move_text_pos2(x : Number, y : Number)

changes the current text position, using the specified offset values. If the current text position is (x1, y1), the new text position will be (x1 + x, y1 + y). Also, the text-leading is set to -y. An application can invoke move_text_pos when the graphics_mode of the page is in GMode::TextObject.

  • x, y the offset of the start of the next line.
Source
path(x : Number, y : Number, &)

create path at given coordinates and yields the block closes the path at the end and returns the result of the block

Source
rectangle(x : Number, y : Number, w : Number, h : Number)

appends a rectangle to the current path. An application can invoke rectangle when the graphics_mode of the page is in GMode::PageDescription or GMode::PathObject.

Source
rectangle(r : Rectangle)

see rectangle

Source
reset_dash!
Source
rgb_fill

returns the current value of the page's filling color. rgb_fill is valid only when the page's filling color space is ColorSpace::DeviceRgb.

Source
rgb_stroke

returns the current value of the page's stroking color. rgb_stroke is valid only when the page's stroking color space is ColorSpace::DeviceRgb.

Source
rotate=(angle : Number)

sets rotation angle of the page.

  • angle Specify the rotation angle of the page. It must be a multiple of 90 Degrees.
Source
set_boundary(boundary : PageBoundary, left : Number, bottom : Number, right : Number, top : Number)

sets one of the page's bounding boxes (media, crop, bleed, trim, or art).

  • boundary which box to set (see PageBoundary).
  • left, bottom, right, top the coordinates of the box.
Source
set_cmyk_fill(c : Number, m : Number, y : Number, k : Number)

sets the filling color. An application can invoke set_cmyk_fill when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • c, m, y, k the level of each color element. They must be between 0 and 1.
Source
set_cmyk_stroke(c : Number, m : Number, y : Number, k : Number)

sets the stroking color. An application can invoke set_cmyk_stroke when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • c, m, y, k the level of each color element. They must be between 0 and 1.
Source
set_dash(pattern : Array(Number), *, phase = 0)

Sets the line dash pattern in the page. An application can invoke set_dash when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • pattern pattern of dashes and gaps used to stroke paths, can have at most 8 elements.
  • phase the phase in which the pattern begins (default is 0).

Samples of the dash pattern:

  • set_dash [] http://libharu.sourceforge.net/image/figure16.png
  • set_dash [3], phase: 1 http://libharu.sourceforge.net/image/figure17.png
  • set_dash [7, 3], phase: 2 http://libharu.sourceforge.net/image/figure18.png
  • set_dash [8, 7, 2, 7] http://libharu.sourceforge.net/image/figure19.png
Source
set_font_and_size(font : Hpdf::Font, size : Number)

sets the type of font and size leading. An application can invoke set_font_and_size when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

Source
set_font_and_size(font : String, size : Number)

see set_font_and_size.

Source
set_rgb_fill(r : Number, g : Number, b : Number)

sets the filling color. An application can invoke set_rgb_fill when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • r, g, b the level of each color element. They must be between 0 and 1.
Source
set_rgb_stroke(r : Number, g : Number, b : Number)

sets the stroking color. An application can invoke set_rgb_stroke when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • r, g, b the level of each color element. They must be between 0 and 1.
Source
set_size(size : PageSizes, direction : PageDirection = PageDirection::Portrait)

changes the size and direction of a page to a predefined size.

  • size Specify a predefined page-size value. The following values are available.
  • direction Specify the direction of the page.
Source
set_slide_show(style : TransitionStyle, disp_time : Number, trans_time : Number = 1)

configures the setting for slide transition of the page.

  • style the transition style.
  • disp_time the display duration of the page. (in seconds)
  • trans_time the duration of the transition effect. Default value is 1 (second).
Source
set_text_matrix(a : Number, b : Number, c : Number, d : Number, x : Number, y : Number)

set_text_matrix sets a transformation matrix for text to be drawn in using show_text.

  • a the horizontal rotation of the text. Typically expressed as cosine(Angle)
  • b the vertical rotation of the text. Typically expressed as sine(Angle)
  • c, d ?? appear to be controlling offset adjustments after text drawn ???
  • x the page x coordinate
  • y the page y coordinate

If the parameter a or d is zero, then the parameters b or c cannot be zero.

Text is typically output using the show_text function. The function text_rect does not use the active text matrix. An application can invoke set_text_matrix when the graphics_mode of the page is in GMode::TextObject.

Source
shading=(shading : Shading)

paints a shading on the page. An application can invoke shading= when the graphics_mode of the page is in GMode::PageDescription.

Source
show_text(text : String)

prints the text at the current position on the page. An application can invoke show_text when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • text the text to print.
Source
show_text_next_line(text : String)

moves the current text position to the start of the next line, then prints the text at the current position on the page. An application can invoke show_text_next_line when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

Source
show_text_next_line_ex(text : String, word_space : Number, char_space : Number)

moves the current text position to the start of the next line, then sets the word spacing, character spacing and prints the text at the current position on the page. An application can invoke show_text_next_line_ex when the graphics mode of the page is in GMode::TextObject.

Source
stroke

paints the current path. An application can invoke stroke when the graphics_mode of the page is in GMode::PathObject or GMode::ClippingPath. And it changes the graphics mode to GMode::PageDescription.

Source
stroking_color_space

returns the current value of the page's stroking color space.

Source
table(rect : Rectangle, line_width lw : Number = 1, spacing sp : Number = 0, fixed_row_height fwh : Number = 0, &)

table creates a table at the given rect and yields the block in the context of the created table.

  • line_width changes the line with of the drawn cells
  • spacing spacing between the cells, by default there is no spacing
  • fixed_row_height allows to specify the row height instead of calculation
Source
table(*, x : Number, y : Number, width : Number, height : Number, line_width lw : Number = 1, fixed_row_height fwh : Number = 0, spacing sp : Number = 0, &)

table creates a table at the given coordinates and yields the block in the context of the created table.

  • line_width changes the line with of the drawn cells
  • spacing spacing between the cells, by default there is no spacing
  • fixed_row_height allows to specify the row height instead of calculation
Source
text(name = nil, size = nil, *, encoding enc : String = @encoding, &)
Source
text_end

ends a text object. An application can invoke text_end when the graphics_mode of the page is in GMode::TextObject. And it changes the graphics mode to GMode::PageDescription.

Source
text_leading

gets the current value of the page's text leading (line spacing).

Source
text_leading=(value : Number)

sets the text leading (line spacing) for text showing. The initial value of leading is 0. An application can invoke text_leading= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

Source
text_matrix

gets the current text transformation matrix.

Source
text_out(x : Number | Symbol, y : Number | Symbol, text : String)

prints the text on the specified position. An application can invoke text_out when the graphics_mode of the page is in GMode::TextObject.

  • x, y the point position where the text is displayed.
  • text the text to show.
Source
text_rect(left : Number, top : Number, right : Number, bottom : Number, text : String, *, align : TextAlignment = TextAlignment::Left) : Number

print the text inside the specified region. Some chars may not in the displayed in the space, the number of displayed chars is returned. An application can invoke text_rect when the graphics_mode of the page is in GMode::TextObject.

  • left, top, right, bottom coordinates of corners of the region to output text.
  • text the text to show.
  • align the alignment of the text.
Source
text_rect(rect : Rectangle, text : String, *, align : TextAlignment = TextAlignment::Left) : Number

see text_rect.

Source
text_rendering_mode

returns the current text rendering mode.

Source
text_rendering_mode=(mode : TextRenderingMode)

sets the text rendering mode. The initial value of text rendering mode is TextRenderingMode::Fill. An application can invoke text_rendering_mode= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

Source
text_rise

returns the current value of the page's text rising.

Source
text_rise=(value : Number)

moves the text position in vertical direction by the amount of value. Useful for making subscripts or superscripts. An application can invoke text_rise= when the graphics mode of the page is in GMode::PageDescription or GMode::TextObject.

  • value text rise, in user space units.
Source
text_width(text : String) : Float32

gets the width of the text in current fontsize, character spacing and word spacing.

Source
to_unsafe
Source
trans_matrix

gets the current transformation matrix of the page.

Source
use_encoding(encoding : String, &)

set encoding to be used for strings

Source
use_font(name, size, *, encoding enc : String | Nil = @encoding)
Source
width

gets the width of a page.

Source
width=(w : Number)

changes the width of a page.

  • w Specify the new width of a page. The valid value is between 3 and 14400.
Source
word_space

returns the current value of the page's word spacing.

Source
word_space=(value : Number)

sets the word spacing for text showing. The initial value of word spacing is 0. An application can invoke word_space= when the graphics_mode of the page is in GMode::PageDescription or GMode::TextObject.

  • value the value of word spacing.
Source
zoom=(zoom : Number)

sets the initial zoom factor shown when the page is opened in a viewer.

  • zoom the zoom factor. Must be between 0.08 and 32.
Source