new ElementBuilder()
ElementBuilder is used to build new PDF::Elements (e.g. image, text, path, etc) from scratch. In conjunction with ElementWriter, ElementBuilder can be used to create new page content.
Methods
-
<static> create()
-
Constructor for an ElementBuilder object that can be used to build new PDF::Elements (eg. image, text, path, etc.) from scratch. In conjunction with ElementWriter, ElementBuilder can be used to create new page content.
Returns:
A promise that resolves to Returns an ElementBuilder object
-
arcTo(x, y, width, height, start, extent)
-
Draw an arc with the specified parameters (lower left corner, width, height and angles).
Parameters:
Name Type Description xnumber The horizontal x coordinate of the lower left corner of the ellipse encompassing rectangle
ynumber The horizontal y coordinate of the lower left corner of the ellipse encompassing rectangle
widthnumber overall width of the full ellipse (not considering the angular extents).
heightnumber overall height of the full ellipse (not considering the angular extents).
startnumber starting angle of the arc in degrees
extentnumber angular extent of the arc in degrees
-
arcTo2(xr, yr, rx, isLargeArc, sweep, endX, endY)
-
Draw an arc from the current point to the end point.
Parameters:
Name Type Description xrnumber x radius for the arc
yrnumber y radius for the arc
rxnumber x-axis rotation in degrees
isLargeArcboolean indicates if smaller or larger arc is chosen 1 one of the two larger arc sweeps is chosen 0 one of the two smaller arc sweeps is chosen
sweepboolean direction in which arc is drawn (1 clockwise, 0 counterclockwise)
endXnumber x coordinate of end point
endYnumber y coordinate of end point
-
closePath()
-
Closes the current subpath.
-
createEllipse(x, y, width, height)
-
Create an ellipse (or circle, if width == height) path Element.
Parameters:
Name Type Description xnumber The horizontal x coordinate of the ellipse center.
ynumber The vertical y coordinate of the ellipse center.
widthnumber The width of the ellipse rectangle.
heightnumber The height of the ellipse rectangle.
Returns:
A promise that resolves to the path Element
- Type
- PDFNet.Element
-
createFormFromDoc(page, doc)
-
Create a Form XObject Element using the content of the existing page. Unlike CreateForm(Page) method, you can use this method to create form in another document.
Parameters:
Name Type Description pagePDFNet.Page A page used to create the Form XObject.
docPDFNet.PDFDoc Destination document for the Form XObject.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createFormFromPage(page)
-
Create a Form XObject Element using the content of the existing page. This method assumes that the XObject will be used in the same document as the given page. If you need to create the Form XObject in a different document use CreateForm(Page, Doc) method.
Parameters:
Name Type Description pagePDFNet.Page A page used to create the Form XObject.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createFormFromStream(form)
-
Create a Form XObject Element.
Parameters:
Name Type Description formPDFNet.Obj a Form XObject content stream
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createGroupBegin()
-
Create e_group_begin Element (i.e. 'q' operator in PDF content stream). The function saves the current graphics state.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createGroupEnd()
-
Create e_group_end Element (i.e. 'Q' operator in PDF content stream). The function restores the previous graphics state.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createImage(img)
-
Create a content image Element out of a given document Image.
Parameters:
Name Type Description imgPDFNet.Image the given image.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createImageFromMatrix(img, mtx)
-
Create a content image Element out of a given document Image.
Parameters:
Name Type Description imgPDFNet.Image the given image.
mtxPDFNet.matrix2d the image transformation matrix.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createImageScaled(img, x, y, hscale, vscale)
-
Create a content image Element out of a given document Image with the lower left corner at (x, y), and scale factors (hscale, vscale).
Parameters:
Name Type Description imgPDFNet.Image the given image.
xnumber The horizontal x position to place the lower left corner of the image
ynumber The vertical x position to place the lower left corner of the image
hscalenumber The horizontal scale of the image
vscalenumber The vertical scale of the image
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createNewTextRun(text_data)
-
Create a new text run.
Parameters:
Name Type Description text_datastring text to initialize the text run with.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createNewTextRunUnsigned(text_data)
-
Create a new text run.
Parameters:
Name Type Description text_datastring text to initialize the text run with. Uses unsigned characters.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createNewTextRunWithSize(text_data, text_data_sz)
-
Create a new text run.
Parameters:
Name Type Description text_datastring text to initialize the text run with.
text_data_sznumber size pf the text run.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createPath(buf_points, buf_seg_types)
-
Create a path Element using the given path segment data
Parameters:
Name Type Description buf_pointsArray A buffer/array containing data on the points in the path. What each point represents is determined by the corresponding segment type.
buf_seg_typesArray A buffer/array containing data on the segment types. Possible segment types are as follows:
PDFNet.Element.PathSegmentType = { e_moveto : 1, e_lineto : 2, e_cubicto : 3, e_conicto : 4, e_rect : 5, e_closepath : 6 }Returns:
A promise that resolves to the path Element
- Type
- PDFNet.Element
-
createRect(x, y, width, height)
-
Create a rectangle path Element.
Parameters:
Name Type Description xnumber The horizontal coordinate of the lower left corner of the rectangle.
ynumber The vertical coordinate of the lower left corner of the rectangle.
widthnumber The width of the rectangle.
heightnumber The height of the rectangle.
Returns:
A promise that resolves to the path Element
- Type
- PDFNet.Element
-
createShading(sh)
-
Parameters:
Name Type Description shPDFNet.Shading A Shading object. Shading objects represent a flat interface around all PDF shading types (e_function_shading, e_axial_shading, etc.) Create a shading Element.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createTextBegin()
-
Start a text block ('BT' operator in PDF content stream).
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createTextBeginWithFont(font, font_sz)
-
Start a text block ('BT' operator in PDF content stream). The function installs the given font in the current graphics state.
Parameters:
Name Type Description fontPDFNet.Font font to set the text in the text block to
font_sznumber size to set the text in the text block to
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createTextEnd()
-
Ends a text block.
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createTextNewLine()
-
Create e_text_new_line Element (i.e. a T* operator in PDF content stream).
Returns:
A promise that resolves to the path Element
- Type
- PDFNet.Element
-
createTextNewLineWithOffset(dx, dy)
-
Create e_text_new_line Element (i.e. a Td operator in PDF content stream). Move to the start of the next line, offset from the start of the current line by (dx , dy). dx and dy are numbers expressed in unscaled text space units.
Parameters:
Name Type Description dxnumber The horizontal x offset from the start of the current line
dynumber The vertical y offset from the start of the current line
Returns:
A promise that resolves to the path Element
- Type
- PDFNet.Element
-
createTextRun(text_data, font, font_sz)
-
Create a text run using the given font.
Parameters:
Name Type Description text_datastring text to initialize the text run with
fontPDFNet.Font font of the text in the text run
font_sznumber size of the text in the text run
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createTextRunUnsigned(text_data, font, font_sz)
-
Create a text run using the given font.
Parameters:
Name Type Description text_datastring text to initialize the text run with. Uses unsigned characters.
fontPDFNet.Font font of the text in the text run
font_sznumber size of the text in the text run
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
createTextRunWithSize(text_data, text_data_sz, font, font_sz)
-
Create a text run using the given font.
Parameters:
Name Type Description text_datastring text to initialize the text run with
text_data_sznumber size of the text run
fontPDFNet.Font font of the text in the text run
font_sznumber size of the text in the text run
Returns:
A promise that resolves to an object of type: "Element"
- Type
- PDFNet.Element
-
curveTo(cx1, cy1, cx2, cy2, x2, y2)
-
Draw a Bezier curve from the current point to the given point (x2, y2) using (cx1, cy1) and (cx2, cy2) as control points.
Parameters:
Name Type Description cx1number The x component of the first control point
cy1number The y component of the first control point
cx2number The x component of the second control point
cy2number The y component of the second control point
x2number The horizontal x component of the goal point
y2number The vertical y component of the goal point
-
destroy()
-
Frees the native memory of the object.
-
ellipse(x, y, width, height)
-
Add an ellipse (or circle, if rx == ry) to the current path as a complete subpath. Setting the current point is not required before using this function.
Parameters:
Name Type Description xnumber The x coordinate of the ellipse center.
ynumber The y coordinate of the ellipse center.
widthnumber The x radii of the ellipse.
heightnumber The y radii of the ellipse.
-
lineTo(x, y)
-
Draw a line from the current point to the given point.
Parameters:
Name Type Description xnumber The horizontal x component of the goal point
ynumber The vertical y component of the goal point
-
moveTo(x, y)
-
Set the current point.
Parameters:
Name Type Description xnumber The horizontal x component of the point
ynumber The vertical y component of the point
-
pathBegin()
-
Starts building a new path Element that can contain an arbitrary sequence of lines, curves, and rectangles.
-
pathEnd()
-
Finishes building of the path Element.
Returns:
A promise that resolves to the path Element
- Type
- PDFNet.Element
-
rect(x, y, width, height)
-
Add a rectangle to the current path as a complete subpath. Setting the current point is not required before using this function.
Parameters:
Name Type Description xnumber The x coordinate of the lower left corner of the rectangle.
ynumber The y coordinate of the lower left corner of the rectangle.
widthnumber The width of the rectangle.
heightnumber The height of the rectangle.
-
reset(gs)
-
The function sets the graphics state of this Element to the given value. If 'gs' parameter is not specified or is NULL the function resets the graphics state of this Element to the default graphics state (i.e. the graphics state at the beginning of the display list).
The function can be used in situations where the same ElementBuilder is used to create content on several pages, XObjects, etc. If the graphics state is not Reset() when moving to a new display list, the new Element will have the same graphics state as the last Element in the previous display list (and this may or may not be your intent).
Another use of Reset(gs) is to make sure that two Elements have the graphics state.
Parameters:
Name Type Description gsPDFNet.GState GState (graphics state) object. If NULL or unspecified, resets graphics state to default.