Skip to content
Viral Ghelani edited this page Apr 6, 2023 · 3 revisions

Welcome to the sciter-pdf wiki!

This wiki is direct adaptation of https://github.com/libharu/libharu/wiki for Sciter.

Class Doc

Properties:

Doc doesn't have any Properties.

Methods:

addPage()

  • Description

    addPage() creates a new page and adds it after the last page of a document.

  • Return Value

    addPage() returns the handle of created page object on success. Otherwise, it returns error-code and error-handler is called.

newDoc()

  • Description

    newDoc() creates a new document. If Doc object already has a document, the current document is revoked.

  • Return Value

    newDoc () returns HPDF_OK on success. Otherwise, it returns error-code and error-handler is called.

save(file_name)

  • Description

    save() saves the current document to a file.

  • Parameters

    file_name - The name of file to save.

  • Return Value

    Returns HPDF_OK on success, otherwise it returns error-code and error-handler is called.

loadTTFontFromFile(file_name, embedding)

  • Description

    loadTTFontFromFile() loads a TrueType font from an external file and register it to a document object.

  • Parameters

    file_name - A path of a TrueType font file (.ttf).

    embedding - If this parameter is set to true, the glyph data of the font is embedded, otherwise only the matrix data is included in PDF file.

  • Return Value

    When loadTTFontFromFile() succeeds, it returns the name of a font. Otherwise, it returns NULL and error-handler is called.

getFont(name, encoding)

  • Description

    getFont gets the handle of a requested font object.

  • Parameters

    font_name - A valid font name. encoding_name - A valid encoding name.

  • Return Value

    When getFont() succeeds, it returns the handle of a font object. Otherwise, it returns NULL and error-handler is called.

setPassword(owner_password, user_password)

  • Description

    setPassword() sets a password for the document. If the password is set, document contents are encrypted.

  • Parameters

    owner_password - The password for the owner of the document. The owner can change the permission of the document. NULL, 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 may be set to NULL or zero length string.

  • Return Value

    When setPassword() succeeds, it returns HPDF_OK. Otherwise, it returns error code and error-handler is called.

loadPngImageFromFile(filename)

  • Description

    loadPngImageFromFile() loads an external PNG image file.

  • Parameters

    filename - A path to a PNG image file.

  • Return Value

    When loadPngImageFromFile() succeeds, it returns the handle of an image object. Otherwise, it returns NULL and error-handler is called.

loadJpegImageFromFile(filename)

  • Description

    loadJpegImageFromFile() loads an external JPEG image file.

  • Parameters

    filename - Path to a JPEG image file.

  • Return Value

    When loadJpegImageFromFile() succeeds, it returns the handle of an image object. Otherwise, it returns NULL and error-handler is called.

free()

  • Description

    free() revokes a document object and all resources.

 

Class Page

Properties

Page doesn't have any Properties.

Methods

getWidth()

  • Description

    getWidth() gets the width of the page.

  • Returns

    When getWidth() succeed, it returns the width of the page. Otherwise it returns 0.

setWidth(width)

  • Description

    setWidth() changes the width of a page.

  • Parameters

    width - The new page width. Valid value are between 3 and 14400.

  • Returns

    returns a handle of document object. If it failed, it returns NULL.

setHeight(height)

  • Description

    setHeight() changes the height of a page.

  • Parameters

    height - The new page height. Valid values are between 3 and 14400.

  • Returns

    returns a handle of document object. If it failed, it returns NULL.

setSize(size, direction)

  • Description

    setSize() changes the size and direction of a page to a predefined size.

  • Parameters

    size - Specify a predefined page-size value. The following values are available.

Value Size (mm or inches) Size (in pixels)
Page.SIZE_LETTER 8.5 x 11 (inches) 612 x 792
Page.SIZE_LEGAL 8.5 x 14 (inches) 612 x 1008
Page.SIZE_A3 297 x 420 (mm) 841.89 x 1199.551
Page.SIZE_A4 210 x 297 (mm) 595.276 x 841.89
Page.SIZE_A5 148 x 210 (mm) 419.528 x 595.276
Page.SIZE_B4 250 x 353 (mm) 708.661 x 1000.63
Page.SIZE_B5 176 x 250 (mm) 498.898 x 708.661
Page.SIZE_EXECUTIVE 7.25 x 10.5 (inches) 522 x 756
Page.SIZE_US4x6 4 x 6 (inches) 288 x 432
Page.SIZE_US4x8 4 x 8 (inches) 288 x 576
Page.SIZE_US5x7 5 x 7 (inches) 360 x 504
Page.SIZE_COMM10 4.125 x 9.5 (inches) 297 x 684

direction - Specify the direction of the page.

Value Description
Page.PORTRAIT Set the longer value to vertical.
Page,LANDSCAPE Set the longer value to horizontal.
  • Returns

    When setSize() succeeds, it returns HPDF_OK. Otherwise, it returns error-code and error-handler is called.

setLineWidth(width)

  • Description

    setLineWidth() sets the width of the line used to stroke a path.

  • Parameter

    width - The width of line.

  • Returns

    When setLineWidth() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

rectangle(x, y, width, height)

  • Description

    rectangle() appends a rectangle to the current path.

  • Parameter

    x, y - The lower-left point of the rectangle. width - The width of the rectangle. height - The height of the rectangle.

  • Returns

    When rectangle() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

stroke()

  • Description

    stroke() paints the current path.

  • Returns

    When stroke() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

beginText()

  • Description

    beginText() begins a text object and sets the current text position to the point (0, 0).

  • Returns

    When beginText() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

endText()

  • Description

    endText() ends a text object.

  • Returns

    When endText() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

textOut(x, y, text)

  • Description

    textOut() prints the text on the specified position.

  • Parameter

    x, y - The point position where the text is displayed. text - The text to show.

  • Returns

    When textOut() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

moveTextPos(x, y)

  • Description

    moveTextPos() 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).

  • Parameter

    x, y - The offset of the start of the next line. text - The text to show.

  • Returns

    When moveTextPos() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

showText(text)

  • Description

    showText() prints the text at the current position on the page.

  • Parameter

    text - The text to print.

  • Returns

    When showText() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

setFontAndSize(font, size)

  • Description

    setFontAndSize() sets the type of font and size leading.

  • Parameter

    font - The handle of a font object. size - The size of a font.

  • Returns

    When setFontAndSize() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

moveTo(x, y)

  • Description

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

  • Parameter

    x, y - The start point for drawing path

  • Returns

    When moveTo() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

lineTo(x, y)

  • Description

    lineTo() appends a path from the current point to the specified point.

  • Parameter

    x, y - The end point of the path

  • Returns

    When lineTo() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

measureText(text, width, wordwrap)

  • Description

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

  • Parameters

    text - The text to get width. width - The width of the area to put the text. wordwrap - When there are three words of "ABCDE", "FGH", and "IJKL", and the substring until "J" can be included within the width, if word_wrap parameter is HPDF_FALSE it returns 12, and if word_wrap parameter is HPDF_TRUE, it returns 10 (the end of the previous word).

  • Returns

    When measureText() succeed, it returns the byte length which can be included within the specified width in current fontsize, character spacing and word spacing. Otherwise it returns ZERO and error-handler is called.

textRect({left,top,right,bottom}, text, align)

  • Description

    textRect() print the text inside the specified region.

  • Parameter

    {left, top, right, bottom} : Object - Coordinates of corners of the region to output text.

    text - The text to show.

    align - The alignment of the text. VALUE Page.TALIGN_LEFT - The text is aligned to left. Page.TALIGN_RIGHT - The text is aligned to right. Page.TALIGN_CENTER - The text is aligned to center. Page.TALIGN_JUSTIFY - Add spaces between the words to justify both left and right side.

  • Returns

    When textRect() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

setRGBStroke(r, g, b)

  • Description

    setRGBStroke() sets the stroking color.

  • Parameter

    r, g, b - The level of each color element. They must be between 0 and 1.

  • Returns

    When setRGBStroke() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

setRGBFill(r, g, b)

  • Description

    setRGBFill() sets the fill color.

  • Parameter

    r, g, b - The level of each color element. They must be between 0 and 1.

  • Returns

    When setRGBFill() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

fill()

  • Description

    fill() fills the current path using the nonzero winding number rule.

  • Returns

    When fill() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

setCharSpace(value)

  • Description

    setCharSpace() sets the character spacing for text showing. The initial value of character spacing is 0.

  • Parameter

    value - The value of character spacing.

  • Returns

    When setCharSpace() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

setWordSpace(value)

  • Description

    setWordSpace() sets the word spacing for text showing. The initial value of word spacing is 0.

  • Parameter

    value - The value of word spacing.

  • Returns

    When setWordSpace() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

setTextLeading(value)

  • Description

    setTextLeading() sets the text leading (line spacing) for text showing. The initial value of leading is 0.

  • Parameter

    value - The value of text leading.

  • Returns

    When setTextLeading() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

drawImage(image, {x,y,w,h})

  • Description

    drawImage() shows an image in one operation.

  • Parameter

    image - The handle of an image object.

    x, y - The lower-left point of the region where image is displayed. w - The width of the region where image is displayed. h - The height of the region where image is displayed.

  • Returns

    When drawImage() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

circle(x, y, radius)

  • Description

    circle() appends a circle to the current path.

  • Parameter

    x, y - The center point of the circle. radius - The radius of the circle.

  • Returns

    When circle() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

setDash(dash_pattern, num_elem, phase)

  • Description

    setDash() sets the dash pattern for lines in the page.

  • Parameter

    dash_pattern - Pattern of dashes and gaps used to stroke paths. num_elem - Number of elements in dash_pattern. 0 <= num_param <= 8. phase - The phase in which the pattern begins (default is 0).

  • Returns

    When setDash() succeed, it returns HPDF_OK, Otherwise it returns error code and error-handler is invoked.

 

Class Image

Properties:

Image doesn't have any Properties.

Methods:

getSize()

  • Description

    getSize() gets the size of the image of an image object.

  • Returns

    When getSize() succeed, it returns an Object {width, height} which includes the size of the image. Otherwise, it returns a Object {width, height} whose value is (0, 0).

getWidth()

  • Description

    getWidth() gets the width of the image of an image object.

  • Returns

    When getWidth() succeed, it returns the width of the image. Otherwise, it returns 0.

getHeight()

  • Description

    getHeight() gets the height of the image of an image object.

  • Returns

    When getHeight() succeed, it returns the height of the image. Otherwise, it returns 0.

setMaskImage(mask_image)

  • Description

    setMaskImage() sets the mask image.

  • Parameters

    mask_image - Specify the handle of an image object which is used as image-mask. This image must be 1bit gray-scale color image.

  • Returns

    When setMaskImage() succeed, it returns HPDF_OK. Otherwise it returns error code and an error-handler will be invoked.

 

Class Font

Properties:

Font doesn't have any Properties.

Methods:

getUnicodeWidth(code)

  • Description

    getUnicodeWidth() gets the width of a Unicode character in a specific font. Actual width of the character on the page can be calculated as follows: char_width = Font.getUnicodeWidth(UNICODE); let actual_width = char_width * FONT_SIZE / 1000;

  • Parameters

    code - A Unicode character.

  • Returns

    Returns character width on success. Otherwise, returns null.