API Documentation for Painter

NoPoDoFo Painter

class Painter {
  new(doc: Base): Painter

  tabWidth: number
  readonly canvas: Stream
  font?: Font
  precision: number

  setPage(page: Page | XObject): void
  setColor(rgb: NPDFrgb): void
  setStrokeWidth(w: number): void
  setGrey(v: number): void
  setStrokingGrey(v: number): void
  setColorCMYK(cmyk: NPDFcmyk): void
  setStrokingColorCMYK(cmyk: NPDFcmyk): void
  setStrokeStyle(style: NPDFStokeStyle): void
  setLineCapStyle(style: NPDFLineCapStyle): void
  setLineJoinStyle(style: NPDFLineJoinStyle): void
  setClipRect(rect: Rect): void
  setMiterLimit(v: number): void
  rectangle(rect: Rect): void
  ellipse(points: NPDFPoint & { width: number, height: number }): void
  circle(points: NPDFPoint & { radius: number }): void
  closePath(): void
  lineTo(point: NPDFPoint): void
  moveTo(point: NPDFPoint): void
  cubicBezierTo(p1: NPDFPoint, p2: NPDFPoint, p3: NPDFPoint): void
  horizontalLineTo(v: number): void
  verticalLineTo(v: number): void
  smoothCurveTo(p1: NPDFPoint, p2: NPDFPoint): void
  quadCurveTo(p1: NPDFPoint, p2: NPDFPoint): void
  arcTo(p1: NPDFPoint, p2: NPDFPoint, rotation: number, large?: boolean, sweep?: boolean): void
  close(): void
  stroke(): void
  fill(): void
  strokeAndFill(): void
  endPath(): void
  clip(): void
  save(): void
  restore(): void
  setExtGState(state: ExtGState): void
  getCurrentPath(): string
  drawLine(p1: NPDFPoint, p2: NPDFPoint): void
  drawText(point: NPDFPoint, text: string): void
  drawTextAligned(point: NPDFPoint & { width: number }, text: string, alignment: NPDFAlignment): void
  drawMultiLineText(rect: Rect, value: string, alignment?: NPDFAlignment, vertical?: NPDFVerticalAlignment): void
  getMultiLineText(width: number, text: string, skipSpaces?: boolean): Array
  bt(point: NPDFPoint): void
  et(): void
  addText(text: string): void
  moveTextPosition(point: NPDFPoint): void
  drawGlyph(point: NPDFPoint, glyph: string): void
  finishPage(): void

  drawImage(img: Image, x: number, y: number, opts?: { width?: number, height?: number, scaleX?: number, scaleY?: number }): void

}

Constructors


new(doc: Base): Painter

Construct a new Painter object. To begin using the painter you must first set the page which the painter will apply painting/drawing operation on.

Properties


tabWidth

Set the tab width for the DrawText operation. Every tab '\t' is replaced with nTabWidth spaces before drawing text. Default is a value of 4

canvas

Readonly property, get the page's canvas which the painter is to draw on.

font

Get and set the Font the painter will use to draw text.

precision

Get and set the floating point precision for drawing operations.

Methods


setPage

setPage(page: Page | XObject): void

Set the a Page or XObject which the painter will draw on, paint/draw operations are applied to the contents Object. FinishPage must be called to finalize any draw operations applied to the page/xobject.

setColor

setColor(rgb: NPDFrgb): void

Set the color as NPDFrgb to be used in all non-stroking operations, this color is also used for text drawn to the page.

setStrokeWidth

setStrokeWidth(w: number): void

Set the line width of stroking operations.

setGrey

setGrey(v: number): void

Set grayscale color value, this must be between 0 and 1.

setStrokingGrey

setStrokingGrey(v: number): void

Set the color for all following stroking operations in grayscale colorspace. This operation used the 'G' PDF operator.

setColorCMYK

setColorCMYK(cmyk: NPDFcmyk): void

Set the NPDFcmyk color value

setStrokingColorCMYK

setStrokingColorCMYK(cmyk: NPDFcmyk): void

Set stroking color NPDFcmyk value.

setStrokeStyle

setStrokeStyle(style: NPDFStokeStyle): void

Set the stoke style as one of NPDFStrokeStyle.

setLineCapStyle

setLineCapStyle(style: NPDFLineCapStyle): void

Set the line cap style as one of NPDFLineCapStyle for stroking operations.

setLineJoinStyle

setLineJoinStyle(style: NPDFLineJoinStyle): void

Set the line join style as one of NPDFLineJoinStyle for stroking operations.

setClipRect

setClipRect(rect: Rect): void

Set the graphic clipping rect.

setMiterLimit

setMiterLimit(v: number): void

Set the miter limit for stroking operations.

rectangle

rectangle(rect: Rect): void

Add a rectangle to te current path.

ellipse

ellipse(points: NPDFPoint & { width: number, height: number }): void

Add an ellipse to the current path.

circle

circle(points: NPDFPoint & { radius: number }): void

Add a circle to the current path.

closePath

closePath(): void

Close the current path.

lineTo

lineTo(point: NPDFPoint): void

Append a line segement to the current path.

moveTo

moveTo(point: NPDFPoint): void

Begin a new path.

cubicBezierTo

cubicBezierTo(p1: NPDFPoint, p2: NPDFPoint, p3: NPDFPoint): void

Append a cubic bezier to the current path

horizontalLineTo

horizontalLineTo(v: number): void

Append a horizontal line to the current path

verticalLineTo

verticalLineTo(v: number): void

Append a vertical line to the current path

smoothCurveTo

smoothCurveTo(p1: NPDFPoint, p2: NPDFPoint): void

Append a smooth curve to the current path

quadCurveTo

quadCurveTo(p1: NPDFPoint, p2: NPDFPoint): void

Append a quad curve to the current path

arcTo

arcTo(p1: NPDFPoint, p2: NPDFPoint, rotation: number, large?: boolean, sweep?: boolean): void

Append an arc to the current path

close

close(): void

Close the current path

stroke

stroke(): void

Stroke the current path.

fill

fill(): void

Fill the current path

strokeAndFill

strokeAndFill(): void

Stroke and fill the current path.

endPath

endPath(): void

End the current path without filling or stroking.

clip

clip(): void

Clip the current path.

save

save(): void

Save the current graphics settings onto the graphics stack.

restore

restore(): void

Restore graphics settings from the graphics stack.

setExtGState

setExtGState(state: ExtGState): void

Set active ExtGState object.

getCurrentPath

getCurrentPath(): string

Get the current path as a string

drawLine

drawLine(p1: NPDFPoint, p2: NPDFPoint): void

Draw a line from NPDFPoint p1 to NPDFPoint p2

drawText

drawText(point: NPDFPoint, text: string): void

Draw text at the coordinates defined by the NPDFPoint

drawTextAligned

drawTextAligned(point: NPDFPoint & { width: number }, text: string, alignment: NPDFAlignment): void

Draw text at the coordinates NPDFPoint, align text as one of NPDFAlignment. Alignment is measured by the width of the container, as such width is required.

drawMultiLineText

drawMultiLineText(rect: Rect, value: string, alignment?: NPDFAlignment, vertical?: NPDFVerticalAlignment): void

Draw multiline text segment. Text is aligned vertically as one of NPDFVerticalAlignment and horizontally as one of NPDFAlignment within the Rect provided.

getMultiLineText

getMultiLineText(width: number, text: string, skipSpaces?: boolean): Array

Get multiline text

bt

bt(point: NPDFPoint): void

Begin text. The recommended method for adding simple text is drawText, drawMultiLineText, drawTextAligned.

et

et(): void

End text. The recommended method for adding simple text is drawText, drawMultiLineText, drawTextAligned.

addText

addText(text: string): void

Add text. The recommended method for adding simple text is drawText, drawMultiLineText, drawTextAligned.

moveTextPosition

moveTextPosition(point: NPDFPoint): void

Move position for text drawing, begin text bt must be called first. This method should only be used for advanced text positioning. The recommended method for adding simple text is drawText, drawMultiLineText, drawTextAligned.

drawGlyph

drawGlyph(point: NPDFPoint, glyph: string): void

Draw a single glyph on a page using the set Font

finishPage

finishPage(): void

Finish drawing on the page. This has to be called whenever drawing operations on the page are complete.

drawImage

drawImage(img: Image, x: number, y: number, opts?: { width?: number, height?: number, scaleX?: number, scaleY?: number }): void

Draw an image to the current path, img is an instance of Image, x and y are the coordinates of the pdf page in pdf points. The options object accepts either a scaling factor or width and height values. If both are provided the width and height will be used. All values are in PDF points.

opts provides two forms of image sizing properties: scaleX and scaleY or width and height. The latter (width and height) are simply helpers for calculating the scaling factor. To determine the correct scaling factor for a given width and height we only need divide the desired width/height by the images width/height to get the correct scaling factor. Again, this is done for you if you pass width, height in the options object.

results matching ""

    No results matching ""