Classes
Constants
- BLOCK_END
Matches HTML that ends with a closed block element, which ends its line.
- BLOCK_START
Matches HTML that opens with a block element, which starts a new line.
- LINE_BREAK_END
Matches the line break that ends a word at a required break.
- PAGE_CONTEXT_STATE
Recipe page content-stream lifecycle states.
Functions
- loadPrototypes() ⇒
void Install every method exported by lib/recipe/*.js on the Recipe prototype.
- resolve(recipe, object) ⇒
object Resolve an object through an indirect reference.
- lookup(recipe, dictionary, key) ⇒
object|null Look up a dictionary entry and resolve it.
- readContentStream(recipe, objectId) ⇒
string Read and decode one content stream as a Latin-1 string.
- resolveFontSize([options], [fallback]) ⇒
number Resolves a text font size from
size, itsfontSizealias, or a fallback, rejecting a size that is not a finite number greater than zero. Zero, negative, and infinite sizes have no usable meaning: they draw nothing readable and measure to nonsensical font metrics, so they are reported as invalid input naming the option and the value. Omitting both options, or passingnullorundefined, selects the fallback.
Recipe
Kind: global class
- Recipe
- new Recipe(src, [output], [options])
.Word.Word.Line.Column.position⇒Object.read([inSrc])⇒Object.endPDF([callback])⇒*.register(key, [callback])⇒Recipe.comment([text], x, y, [options])⇒Recipe.link(url, x, y, width, height)⇒Recipe.annot(x, y, subtype, [options])⇒Recipe.appendPage(pdfSrc, [pages])⇒Recipe.chroma(name, value, [colorspace])⇒Recipe.permission([flags])⇒number.encrypt([options])⇒Recipe.registerFont([fontName], [fontSrcPath], [type])⇒Recipe.rotateContent(degrees, [x], [y])⇒Recipe.htmlToTextObjects(htmlCodes, [options])⇒Array.<Object>.image(imgSrc, x, y, [options])⇒Recipe.info([options])⇒Object|Recipe.custom(key, value)⇒Recipe.structure(output)⇒Recipe.insertPage(afterPageNumber, pdfSrc, srcPageNumber)⇒Recipe.overlay(pdfSrc, [x], [y], [options])⇒Recipe.createPage([pageWidth], [pageHeight], [margins])⇒Recipe.rotate(rotation)⇒Recipe.setPageBox(box, left, bottom, right, top)⇒Recipe.endPage()⇒Recipe.editPage(pageNumber)⇒Recipe.deletePage(pageNumbers, [options])⇒Recipe.pageInfo(pageNumber)⇒RecipePageInfo.getCurrentPageInfo()⇒RecipePageInfo|null.pauseContext()⇒Recipe.resumeContext()⇒Recipe.getPageInfo()⇒Object.margins([left], [right], [top], [bottom])⇒object.replaceText(text, replacement, pageNumber)⇒Recipe.removeText(pageNumber, [options])⇒Recipe.n_gon(cx, cy, radius, [sides], [options])⇒Recipe.star(cx, cy, radius, [points], [options])⇒Recipe.triangle(x, y, traits, [options])⇒Recipe.arrow(x, y, [options])⇒Recipe.split([outputDir], [prefix])⇒Recipe.table(x, y, contents, [options])⇒Recipe.textDimensions(text, [options])⇒Object.text([text], [x], [y], [options])⇒Recipe.movedown([lines], [returnCoords])⇒Object|Array.<number>.layout(id, [x], [y], [width], [height], [options])⇒Recipe.moveTo(x, y)⇒Recipe.lineTo(x, y, [options])⇒Recipe.line(coordinates, [options])⇒Recipe.polygon(coordinates, [options])⇒Recipe.circle(x, y, radius, [options])⇒Recipe.rectangle(x, y, width, height, [options])⇒Recipe.ellipse(cx, cy, rx, ry, [options])⇒Recipe.arc(x, y, radius, [startAngle], [endAngle], [options])⇒Recipe.pie(x, y, radius, [startAngle], [endAngle], [options])⇒Recipe.lineStyle([options])⇒Recipe.lineWidth(width)⇒Recipe.opacity(value)⇒Recipe.fill()⇒Recipe.stroke()⇒Recipe.fillAndStroke()⇒Recipe
new Recipe(src, [output], [options])
Create a new PDF, or open an existing one for editing.
Throws:
ErrorIf an existing source PDF cannot be read or opened for editing.
Params
- src
string|Buffer-Recipe.Source.NEW("new", orBuffer.from("new")) for a new PDF, otherwise the path or Buffer of the PDF to edit. - [output]
string- The output path. For a path source it defaults to the source path; for a Buffer source the result is only returned byendPDF()unless an output path is given. - [options]
Object- The options for pdfDoc - [.version]
number- The PDF version of a new PDF: 1.0 through 1.7 or 2.0. Other values fall back to 1.7. - [.author]
string- The author - [.title]
string- The title - [.subject]
string- The subject - [.keywords]
Array.<string>- The array of keywords - [.colorspace]
Recipe.Colorspace- The default colorspace, one of theRecipe.Colorspacevalues. - [.password]
string- Owner password; also opens a protected source. - [.userPassword]
string- The 'view' password; also enables encryption. - [.ownerPassword]
string- The 'edit' password. - [.userProtectionFlag]
number- Encryption permission flags, seepermission(). - [.fontSrcPath]
string|Array.<string>- Directory location(s) of additional fonts.
recipe.Word
Kind: instance class of Recipe
new Word(word, pathOptions)
A word used by Recipe text layout.
Params
- word
string- The word, a single space measured as "o". - pathOptions
Object- The resolved text options: font, size and charSpace.
new Word(word, pathOptions)
A word used by Recipe text layout.
Params
- word
string- The word value. - pathOptions
Object- The resolved text options.
recipe.Word
Kind: instance class of Recipe
new Word(word, pathOptions)
A word used by Recipe text layout.
Params
- word
string- The word, a single space measured as "o". - pathOptions
Object- The resolved text options: font, size and charSpace.
new Word(word, pathOptions)
A word used by Recipe text layout.
Params
- word
string- The word value. - pathOptions
Object- The resolved text options.
recipe.Line
Kind: instance class of Recipe
new Line(width, height, size, pathOptions)
A line used by Recipe text layout.
Params
- width
number- The line width. - height
number- The line height. - size
number- The font size. - pathOptions
Object- The resolved text options.
recipe.Column
Kind: instance class of Recipe
new Column(x, y, width, height, [text], [field], [options])
A column used by Recipe text layouts.
Params
- x
number- The x coordinate. - y
number- The y coordinate. - width
number- The column width. - height
number- The column height. - [text]
string= "''"- The column heading. - [field]
string= "''"- The associated data field. - [options]
Object- The column options.
recipe.position ⇒ Object
The current drawing position in Recipe coordinates, where y grows downward from the top edge of the page.
Kind: instance property of Recipe
Returns: Object - The current position.
recipe.read([inSrc]) ⇒ Object
Read PDF metadata: the page count and, keyed by one-based page number, each page's media box, rotation, layout and size.
Kind: instance method of Recipe
Returns: Object - The PDF metadata.
Throws:
ErrorIf the PDF cannot be read or has no pages.
Params
- [inSrc]
string|Buffer- A PDF path or Buffer to read instead of the recipe source. Reading another PDF does not change the recipe state.
recipe.endPDF([callback]) ⇒ *
End the pdfDoc. Finalization happens once; later calls do not rewrite the PDF and invoke the callback with the completed output when applicable. An active page is finished first, so a forgotten endPage() does not cost that page. A failed finalization retires the Recipe and later calls rethrow the original error.
Kind: instance method of Recipe
Returns: * - The callback result, or undefined without a callback.
Throws:
ErrorIf pages are being deleted while a page is still open.ErrorIf finalization fails; later calls rethrow the same error.
Params
- [callback]
function- Called when the PDF is finished: with the output Buffer for a Buffer source without an output path, with the output path for a Buffer source with one, and without an argument for a path source.
recipe.register(key, [callback]) ⇒ Recipe
Register a callback procedure with MuhammaraJS.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
stringIf the callback function is unnamed when no key is provided.stringIf the key conflicts with an existing Recipe prototype member.stringIf the callback is not a function.
Params
- key
string|function- Name assigned to the callback. When a named function is registered, and its given name is what is to be used to access it, the key is unnecessary. - [callback]
function- Callback procedure that can be accessed through MuhammaraJS. It is added to the shared Recipe prototype, so every Recipe instance gets it.
recipe.comment([text], x, y, [options]) ⇒ Recipe
Create a comment annotation: a Text annotation with the Comment icon. It is written when the PDF ends.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIfoptions.coloris not a known color, or a position, size, opacity, border, orquadPointsvalue is invalid.
Params
- [text]
string= "''"- The text content - x
number|"center"- The coordinate x - y
number|"center"- The top coordinate y; (x, y) is the top-left corner, as forannot(). - [options]
Object- The options - [.title]
string- The title. - [.date]
string- The date. - [.open]
boolean= false- Open the annotation by default? - [.richText]
boolean- Display with rich text format, text will be transformed automatically, or you may pass in your own rich text starts with "<?xml..." - [.replies]
Array- Array of annotation replies, each with text and optional title, date, subject, richText, and flag. - [.flag]
Recipe.AnnotFlag- The flag property, one of theRecipe.AnnotFlagvalues. - [.color]
string|Array.<number>- The annotation color, as forannot(). - [.width]
number- The rectangle width, as forannot(). - [.height]
number- The rectangle height; as forannot(), (x, y) is the top-left corner and the rectangle extends down from it. The otherannot()options, such asborder,opacity, andquadPoints, apply too;contentsis used whentextis empty.
recipe.link(url, x, y, width, height) ⇒ Recipe
Add a clickable URL link to the current page.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active,urlis not a string, or the rectangle is not finite.
Params
- url
string- The URL to open. - x
number|"center"- The top-left x coordinate. - y
number|"center"- The top-left y coordinate. - width
number- The link width. - height
number- The link height.
recipe.annot(x, y, subtype, [options]) ⇒ Recipe
Create an annotation. It is written when the PDF ends.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIfoptions.coloris not a known color, or a position, size, opacity, border, orquadPointsvalue is invalid.
Todo
- [ ] support for rich text RC
Params
- x
number|"center"- The left edge of the annotation rectangle. - y
number|"center"- The top edge of the annotation rectangle. Likerectangle()andlink(), (x, y) is the rectangle's top-left corner, and the rectangle extendsoptions.heightdown from it. - subtype
Recipe.AnnotSubtype- The annotation subtype, one of theRecipe.AnnotSubtypevalues. - [options]
Object- The options - [.text]
string= "''"- The annotation content. - [.contents]
string- The content whentextis empty. - [.title]
string- The title. - [.open]
boolean= false- Open the annotation. Annotation will be closed by default. Specific to text annotations; subtype='Text' - [.richText]
boolean- Rich text - [.flag]
Recipe.AnnotFlag- The flag property, one of theRecipe.AnnotFlagvalues. - [.icon]
Recipe.AnnotIcon- The icon of a Text annotation, one of theRecipe.AnnotIconvalues. Viewers show 'Note' when it is omitted. - [.name]
string- The/Nameicon wheniconis omitted. - [.flags]
number- Flag bits whenflagis omitted. - [.width]
number- Width; a finite number of at least zero. - [.height]
number- Height; a finite number of at least zero. - [.date]
string- Date of annotation - [.subject]
string- The subject. - [.replies]
Array- Array of annotation replies. A reply keeps its ownopen,icon,name, andopacity, and otherwise inherits the metadata of the annotation it answers. - [.border]
number|Object- The border width, or an object with itswidthanddashpattern. A negative width writes no border; text markup annotations default to 0. - [.borderWidth]
number- The border width; overridesborder.width. - [.borderDash]
Array.<number>- The border dash pattern; overridesborder.dash. - [.quadPoints]
Array.<number>- Quad points, eight numbers per quadrilateral, written as given instead of covering the rectangle. - [.color]
string|Array.<number>- The annotation color: a#rrggbbHexColor, a%r,g,bPercentColor, a DecimalColor array, a color registered withchroma(), or a CSS color name in any case. - [.opacity]
number= 1- Annotation opacity from 0 (transparent) to 1 (opaque). - [.followOriginalPageRotation]
boolean= false- Preserve the original page rotation when positioning the annotation.
recipe.appendPage(pdfSrc, [pages]) ⇒ Recipe
Append pages from the other pdf to the current pdf. An active page is finished first, so appended pages follow it in the output.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
RangeErrorIf a selection is not a positive integer or a two-value range in ascending order.ErrorIf pages were deleted with deletePage() on this Recipe.ErrorIf the source PDF cannot be read.
Params
- pdfSrc
string- The path for the other pdf. - [pages]
number|Array.<(number|Array.<number>)>= []- A one-based page number or array of page numbers and inclusive ranges. Omitting it appends all pages; endpoints beyond the source are clamped to its final page.
recipe.chroma(name, value, [colorspace]) ⇒ Recipe
Associate color values to names
The colorspace parameter is optional. When it is missing, the colorspace is automatically determined by the given color value. Note that the special PDF color space called 'separation' may also be used. The color value is then treated as the alternative color when the named 'separation' color is unavailable.
If the 'name' parameter is Recipe.ChromaCommand.LOAD ('!load'), the second parameter is the name of a JSON
formatted file containing a formatted list of defined colors associated with the
color spaces rgb, cmyk, gray, or separation (think PANTONE color definitions).
This file will be merged with existing set of known colors. The color values
must be specified as hex values.
For example, { 'rgb': {'purple':'ff00ff', 'red':'#ff0000'}, 'cmyk': {'cyan':'ff000000', 'magenta':'%0,100,0,0'}, 'gray': {'grey':'#33'} }
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf the file to load cannot be read or is not valid JSON.ErrorIf a loaded color definition has an unrecognized colorspace.ErrorIf a color value has an invalid size.TypeErrorIf the colorspace is unknown.
Params
- name
string- the name to be associated to given color value, orRecipe.ChromaCommand.LOAD - value
string|Array.<number>- the color value (HexColor, DecimalColor, or PercentColor), or the path of the JSON file to load - [colorspace]
Recipe.Colorspace|""= ''- One of theRecipe.Colorspacevalues; empty picks gray, rgb or cmyk from the value length.
recipe.permission([flags]) ⇒ number
Encryption user access permissions
This function supplies the numeric value for the encrypt function's 'userProtectionFlag' option. When no argument is given, the default 'print' value is used.
Kind: instance method of Recipe
Returns: number - The numeric user protection flag.
Throws:
ErrorIf a name is not aRecipe.Permissionvalue.
Params
- [flags]
string= "'print'"- One or moreRecipe.Permissionvalues (print, modify, copy, edit, fillform, extract, assemble, printbest), separated by commas, for example[Permission.PRINT, Permission.COPY].join().
recipe.encrypt([options]) ⇒ Recipe
Encrypt the pdf
Kind: instance method of Recipe
Returns: Recipe - The recipe instance. The output is encrypted by endPDF():
the output file for a path source, and the Buffer passed to the callback
(or written to the output path) for a Buffer source.
Params
- [options]
Object- The options - [.password]
string- The permission password. - [.ownerPassword]
string- The password for editing. - [.userPassword]
string- The password for viewing & encryption. - [.userProtectionFlag]
number- The flag for the security level, seepermission().
recipe.registerFont([fontName], [fontSrcPath], [type]) ⇒ Recipe
Register a custom font
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Params
- [fontName]
string= "''"- The font name used in text, matched case-insensitively. - [fontSrcPath]
string= "''"- The path to the font file. - [type]
Recipe.FontStyle= 'regular'- The style this file provides, one of theRecipe.FontStylevalues or its short form r, b, i or bi. Any other value registers the regular style.
recipe.rotateContent(degrees, [x], [y]) ⇒ Recipe
Rotate subsequent content around a point in Recipe coordinates.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- degrees
number- Counter-clockwise rotation in degrees. Therotationoption of shapes, text, and images turns clockwise instead. - [x]
number|"center"= 0- Rotation origin x coordinate. - [y]
number|"center"= 0- Rotation origin y coordinate.
recipe.htmlToTextObjects(htmlCodes, [options]) ⇒ Array.<Object>
Convert HTML into Recipe text layout objects.
Kind: instance method of Recipe
Returns: Array.<Object> - The parsed text layout objects: one per child node,
each with its value, tag, style flags, link, font size ratio and childs.
Params
- htmlCodes
string- The HTML source. Tag names are matched case-insensitively. - [options]
Object- Text options used to initialize the objects. - [.font]
string- The font of every object. - [.size]
number- The base font size of every object.
recipe.image(imgSrc, x, y, [options]) ⇒ Recipe
Place images to pdf
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.RangeErrorIfpageis not an integer from 1 to 4294967296, a size is not a finite number, ormiterLimitis not a number of at least 1.TypeErrorIfrotationis not a finite number.ErrorIf the image, or the PDF pagepageselects, cannot be read.
Params
- imgSrc
string- The path for the image. [JPEG, PNG, TIFF, PDF] - x
number|"center"- The coordinate x of the top-left corner - y
number|"center"- The coordinate y of the top-left corner - [options]
Object- The options - [.page]
number= 1- The one-based page of a PDF source, or the image of a multi-image TIFF, as inoverlay(). - [.width]
number- The new width. The frame's line width isoptions.lineWidth. - [.height]
number- The new height - [.scale]
number- Scale the image from the original width and height. - [.keepAspectRatio]
boolean= true- Keep the aspect ratio. - [.opacity]
number- The opacity of the image and its frame. - [.align]
string- ARecipe.HorizontalAlignvalue, optionally followed by a space and aRecipe.VerticalAlignvalue, for example "center center". Horizontal center moves the image left by half its width and right moves it right by half; vertical center moves it up by half its height and bottom moves it down by half from its top-left placement. - [.rotation]
number- Clockwise rotation of the image, in degrees. - [.rotationOrigin]
Array.<number>- [x, y] of the rotation origin; the bottom-left corner of the drawn image when omitted. - [.skewX]
number- Skew angle off the x axis, in degrees. - [.skewY]
number- Skew angle off the y axis, in degrees. - [.fill]
string|Array.<number>- Paint the image box beneath the image in this color. - [.stroke]
string|Array.<number>- Outline the image box above the image in this color. - [.color]
string|Array.<number>- Outline color whenstrokeis not given. - [.colorspace]
Recipe.Colorspace- The frame colorspace. - [.colorName]
string- The Separation ink name of a"separation"frame color. - [.lineWidth]
number- The outline width. The outline lies inside the image box, as arectangle()stroke does. - [.dash]
Array.<number>- The outline dash pattern. - [.dashPhase]
number- The outline dash phase. - [.lineCap]
Recipe.LineCap- The outline dash cap. - [.lineJoin]
Recipe.LineJoin- The outline corner join. - [.miterLimit]
number- The outline miter limit. - [.debug]
boolean|number- Outline the image box in green and mark the placement point in red. - [.link]
string- Make the image open this URL.
recipe.info([options]) ⇒ Object | Recipe
Add standard and custom PDF information, or retrieve existing PDF information. Custom keys retain their spelling when written; array values are joined with a comma and space.
Kind: instance method of Recipe
Returns: Object | Recipe - The existing information dictionary when options are omitted, otherwise the recipe instance.
A new PDF has no existing information, so the call without options returns undefined.
Throws:
ErrorIf the source information cannot be read.
Params
- [options]
Object- The options (when missing obtains existing PDF information) - [.author]
string- The author - [.title]
string- The title - [.subject]
string- The subject - [.keywords]
Array.<string>- The array of keywords
recipe.custom(key, value) ⇒ Recipe
Add custom information to pdf
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf the key or value is null or undefined.
Params
- key
string- The key - value
string- The value; other values are converted with toString().
recipe.structure(output) ⇒ Recipe
Write the PDF object structure to a file.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf the source reader was released by endPDF(), or the output file cannot be written.
Params
- output
string- The output file path.
recipe.insertPage(afterPageNumber, pdfSrc, srcPageNumber) ⇒ Recipe
Insert a page from the other pdf
Kind: instance method of Recipe
Returns: Recipe - The recipe instance. Pages are inserted by endPDF();
Buffer sources do not support insertion.
Throws:
ErrorIf pages were deleted with deletePage() on this Recipe.ErrorIf afterPageNumber is not a number.TypeErrorIf pdfSrc or srcPageNumber is missing.
Params
- afterPageNumber
number- The one-based page number to insert after; 0 inserts before the first page. - pdfSrc
string- The path for the other pdf - srcPageNumber
number- The one-based page number to be inserted from the other pdf.
recipe.overlay(pdfSrc, [x], [y], [options]) ⇒ Recipe
Overlay a pdf to the current pdf
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.ErrorIf the overlay PDF cannot be read.
Params
- pdfSrc
string- The path for the overlay pdf - [x]
number|Object= 0- The PDF x offset from the left edge, or options when using the two-argument form. - [y]
number= 0- The offset from the top edge. - [options]
Object- The options. - [.scale]
number- Scale the overlay pdf, default is 1 - [.page]
number- Page of the overlay pdf, default is 1 - [.keepAspectRatio]
boolean- To keep the aspect ratio when scaling, default is true - [.fitWidth]
boolean- To set the width to 100% (use with keepAspectRatio=true) - [.fitHeight]
boolean- To set the height to 100% (use with keepAspectRatio=true)
recipe.createPage([pageWidth], [pageHeight], [margins]) ⇒ Recipe
Create a new page, specifying either actual width and height, or the name of a supported page size (eg. 'letter', 'letter-size') '-size' will be removed from string but is discouraged to use.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf pages were deleted with deletePage() on this Recipe.ErrorIf another page is still active; call endPage() first.
Params
- [pageWidth]
number|Recipe.PageSize- The page width, or aRecipe.PageSizename. Known named medium sizes: executive, folio, legal, letter, ledger, tabloid, a0-a10, b0-b10, c0-c10, ra0-ra4, sra0-sra4. Unknown names use the default letter size. - [pageHeight]
number- The page height, or rotation (90) when page size name given. - [margins]
object- page margin definitions. - [.left]
number- Left margin. - [.right]
number- Right margin. - [.top]
number- Top margin. - [.bottom]
number- Bottom margin.
recipe.rotate(rotation) ⇒ Recipe
Set the rotation of the current page.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active orrotationis not a number.RangeErrorIfrotationis not a multiple of 90.ErrorIf the active page was opened witheditPage().
Params
- rotation
number- The page rotation in degrees, a multiple of 90.
recipe.setPageBox(box, left, bottom, right, top) ⇒ Recipe
Set a page box on the active new page.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
RangeErrorIf the page box constant is unknown.TypeErrorIf no page is active.
Params
- box
number|string- AnePDFPageBox*constant or aPageBoxname. - left
number- The PDF left coordinate. - bottom
number- The PDF bottom coordinate. - right
number- The PDF right coordinate. - top
number- The PDF top coordinate.
recipe.endPage() ⇒ Recipe
Finish a page. Without an active page this does nothing.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf the page cannot be written.
recipe.editPage(pageNumber) ⇒ Recipe
Start editing a page
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf the Recipe was not constructed from an existing PDF.ErrorIf the page does not exist in the source PDF.ErrorIf another page is still active; call endPage() first.
Params
- pageNumber
number- The one-based page number to be edited.
recipe.deletePage(pageNumbers, [options]) ⇒ Recipe
Delete one or more pages from an existing PDF. Page numbers are one-based and refer to the original source document.
By default a page that retained structures still reference - outline
items, link annotations and named destinations, form widgets, tagged-PDF
structure elements or the open action - cannot be deleted. With
pruneReferences, those references are removed instead: a destination
that targets a deleted page becomes null (so outline items keep their
title and children, and links do nothing), and every other direct
reference to a deleted page is dropped. Pruning applies to every queued
deletion once any deletePage() call enables it.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf options is not an object or pruneReferences is not a boolean.RangeErrorIf a page number does not identify an original page.ErrorIf the Recipe has no existing source, has ended, would delete every page, combines deletion with page composition, or the page tree, page labels or retained references cannot be rewritten. A failed call leaves the queued deletions unchanged.
Params
- pageNumbers
number|Array.<number>- Page number or page numbers to delete. - [options]
Object- Deletion options. - [.pruneReferences]
boolean= false- Remove references to the deleted pages from retained structures instead of refusing the deletion.
recipe.pageInfo(pageNumber) ⇒ RecipePageInfo
Get page information
Kind: instance method of Recipe
Returns: RecipePageInfo - The page information.
Throws:
TypeErrorIf the page is unknown.
Params
- pageNumber
number- The one-based page number.
recipe.getCurrentPageInfo() ⇒ RecipePageInfo | null
Get information about the current page.
Kind: instance method of Recipe
Returns: RecipePageInfo | null - The current page information, or null when no page has been created or edited.
recipe.pauseContext() ⇒ Recipe
Pause the current page content context.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf there is no active page content context.
recipe.resumeContext() ⇒ Recipe
Resume the current page content context after it has been paused.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf there is no paused page content context.
recipe.getPageInfo() ⇒ Object
Get the document information dictionary.
Kind: instance method of Recipe
Returns: Object - The document information dictionary.
recipe.margins([left], [right], [top], [bottom]) ⇒ object
Set/Get current page margins.
Kind: instance method of Recipe
Returns: object - When parameters are given, the value returned is the recipe handle. When no
parameters given, the return value is the current page margin object.
Params
- [left]
number|object- Left margin width or an object holding margin properties to be set. Valid margin property names are: left, right, top, bottom. - [right]
number- Right margin width. - [top]
number- Top margin height. - [bottom]
number- Bottom margin height.
recipe.replaceText(text, replacement, pageNumber) ⇒ Recipe
Replace text shown with Tj in a page's single content stream. Each operand
is decoded through the font selected by Tf (its /ToUnicode CMap, then
its /Encoding and /Differences), and a match is compared with text.
The replacement is encoded through the same font and written back as a
literal or hex string, like the original operand. Only whole Tj operands
match; TJ, ', and " operands and text split across operators are left
unchanged.
The replacement can only use glyphs the font already has. Embedded subset fonts usually carry just the glyphs of their original text.
Kind: instance method of Recipe
Returns: Recipe - The Recipe instance.
Throws:
TypeErrorIf text or replacement is not a string, or if the page number is not a positive integer.RangeErrorIf the source document has no such page.ErrorIf the page does not have one indirect content stream, or the matched font cannot be read, has a malformed/Widthsarray, or has no glyph for a replacement character.
Params
- text
string- Text to replace. - replacement
string- Replacement text. - pageNumber
number- One-based page number.
recipe.removeText(pageNumber, [options]) ⇒ Recipe
Remove all shown text from a page, for example before placing a fresh OCR
text layer. Text-showing operators (Tj, TJ, ', ") are dropped;
graphics, images, and text state are kept. Annotation appearances are not
changed.
The page's source content streams are rewritten in place, so a stream shared
with another page loses its text there too. Content added with editPage()
in the same Recipe is kept.
Kind: instance method of Recipe
Returns: Recipe - The Recipe instance.
Throws:
TypeErrorIf the page number is not a positive integer, or the options are not an object.RangeErrorIf the source document has no such page.ErrorIf the page'sContentsholds a direct stream.
Params
- pageNumber
number- One-based page number. - [options]
RemoveTextOptions- Removal options. - [.forms]
boolean= false- Also remove text from the Form XObjects the page paints, including nested forms. Other pages that paint the same form lose that text too.
recipe.n_gon(cx, cy, radius, [sides], [options]) ⇒ Recipe
Draw an N-sided regular polygon
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.RangeErrorIfsidesis not a finite number or exceeds 100000.
Params
- cx
number- x-coordinate of center point of regular polygon - cy
number- y-coordinate of center point of regular polygon - radius
number- The radius, distance from the center of the polygon to a vertice. - [sides]
number|Object= 3- the number of sides of the regular polygon, at least 3; or the options when the side count is omitted. - [options]
Object- The options - [.color]
string|Array.<number>- HexColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor or DecimalColor - [.fill]
string|Array.<number>- HexColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash style [number, number] - [.rotation]
number= 0- Clockwise rotation in degrees, +/- 0 through 360. - [.rotationOrigin]
Array.<number>= [cx,cy]- [originX, originY] - [.rotationVertice]
number- the number of the vertice to be used as rotation origin - [.skewX]
number- the angle skew off the x-axis - [.skewY]
number- the angle skew off the y-axis. - [.link]
string- Make the polygon's bounding square open this URL. - [.debug]
boolean- Also draw the circumscribed circle and center.
recipe.star(cx, cy, radius, [points], [options]) ⇒ Recipe
Draw an N pointed star
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.RangeErrorIfpointsis not a finite number or exceeds 100000.
Params
- cx
number- x-coordinate of center point of regular polygon - cy
number- y-coordinate of center point of regular polygon - radius
number- The radius, distance from the center to a star point. - [points]
number|Object= 5- number of points on star, at least 5; or the options when the point count is omitted. - [options]
Object- The options - [.color]
string|Array.<number>- HexColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor or DecimalColor - [.fill]
string|Array.<number>- HexColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash style [number, number] - [.rotation]
number- Clockwise rotation in degrees, +/- 0 through 360. Default: 0 - [.rotationOrigin]
Array.<number>- [originX, originY] Default: x, y - [.skewX]
number- the angle skew off the x-axis - [.skewY]
number- the angle skew off the y-axis. - [.link]
string- Make the star's bounding square open this URL. - [.debug]
boolean- Also draw the circumscribed circle and center.
recipe.triangle(x, y, traits, [options]) ⇒ Recipe
Draw a triangle, by specifying three side lengths, two side lengths and one inclusive angle, one side length and two adjacent angles, or with a set of vertices.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
ErrorIf traits does not contain three values or does not define a valid triangle.TypeErrorIf no page is active.
Params
- x
number- x-coordinate used to position triangle, by default associated with left vertex of triangle base. - y
number- y-coordinate used to position triangle, by default associated with left vertex of triangle base. - traits
Array.<number>- the data defining the triangle. Angles are specified as degrees, sides in units of points (1/72 in.). - [options]
Object- The options - [.traitID]
Recipe.TriangleTrait= 'sss'- indicates what type of data is being passed in the traits parameter, one of theRecipe.TriangleTraitvalues: ('sss'- three side lengths, 'sas' - side-angle-side (sideA, <C, sideB), 'asa' - angle-side-angle (<B, sideC, <A), or 'vtx' - three vertex points [x,y]) - [.position]
Recipe.TrianglePosition= 'b'- the position of the triangle to be set at the given x,y coordinates, one of theRecipe.TrianglePositionvalues. The values can be one of: 'A' - the A vertex (right vertex of triangle base), 'B' - the B vertex (left vertex of triangle base), 'C' - the C vertex (apex of triangle), 'centroid', 'circumcenter', or 'incenter' of the triangle. - [.flipX]
Boolean= false- flip triangle up to down through rotation point. - [.flipY]
Boolean= false- flip triangle right to left through rotation point. - [.color]
string|Array.<number>- HexColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor or DecimalColor - [.fill]
string|Array.<number>- HexColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash style [number, number] - [.rotation]
number- Clockwise rotation in degrees, +/- 0 through 360. Default: 0 - [.rotationOrigin]
Array.<number>- [originX, originY] Default: x, y - [.skewX]
number- the angle skew off the x-axis - [.skewY]
number- the angle skew off the y-axis. - [.link]
string- Make the triangle's bounding box open this URL. - [.debug]
boolean- Also draw the reference points and labels.
recipe.arrow(x, y, [options]) ⇒ Recipe
Draw an arrow
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- x
number- x-coordinate position - y
number- y-coordinate position - [options]
Object- arrow and polygon options - [.type]
Recipe.ArrowType|number= 0- indicates the type of arrow head to produce, aRecipe.ArrowTypevalue or its number (0-'triangle', 1-'dart', 2-'kite'). Note, that the value of base offset in head option overrides this value. - [.head]
number|Array.<number>= [10,20,0]- defines the length, width and base offset of arrow head. A single number can be used to assign both the length and width of arrow, giving the base offset value as zero. - [.shaft]
number|Array.<number>= [10,10]- defines the length and width of the arrow shaft. - [.double]
Boolean= false- indicate double headed arrow production. - [.at]
Recipe.ArrowAt- position and/or rotate at theRecipe.ArrowAthead or tail of arrow instead of at center. - [.debug]
number|boolean- Draw the drop point; 2 also labels the reference points.
recipe.split([outputDir], [prefix]) ⇒ Recipe
Split the pdf
Kind: instance method of Recipe
Returns: Recipe - The recipe instance. Each page is written to
<outputDir>/<prefix>-<pageNumber>.pdf.
Throws:
ErrorIf the source reader was released by endPDF(), or an output file cannot be written.
Params
- [outputDir]
string= "''"- The path for the output PDFs. - [prefix]
string- The output filename prefix. Defaults to the source filename; pass one for a Buffer source, which has no filename.
recipe.table(x, y, contents, [options]) ⇒ Recipe
Display text data in tabular form Rows and headers use their rendered text-box heights, including padding, minimum heights, fixed heights, and HTML layout. Empty contents or no selected columns leave the Recipe unchanged. Array-form order preserves exact keys. Header text styles are independent of body styles: column header options (or defaults) are overridden by table header options, then alignToData and column hcell box overrides are applied.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.RangeErrorIf the overflow callback continues into an area too small for the pending row and its repeated header. Return true to stop, or provide enough space; rows are not split and the callback is called once per overflow.ErrorIf the overflow callback continues after ending the page without starting another one.
Params
- x
number- The coordinate x used to position table on page - y
number- The coordinate y used to position table on page - contents
Array.<object>- the data to be placed into the table - [options]
object- The options - [.height]
number- The height designation of the table - [.order]
string|Array.<string>- Defines the order of the named columns in the table. It can also be used to choose a subset of the actual data found in the given contents. - [.columns]
Array.<object>- Holds the defining options for columns in the table.- [.name]
string- The name of the content data field to be associated with the column. This field is mandatory when supplying column options. - [.text]
string- The title to be applied to the column header. When missing, the data field name is used. - [.width]
number= 100- The width of table column. - [.cell]
object- Holds the options to be applied to a column table cell. All textBox options from the 'text' interface can be used here. - [.color]
string|Array.<number>- Text color (HexColor, PercentColor or DecimalColor) - [.opacity]
number= 1- opacity - [.font]
string= "Helvetica"- The font. 'Arial', 'Helvetica'... - [.size]
number= 14- The font size - [.renderer]
function- function to be called which can be used to modify the text options for a particular table cell. The function is called with(text, data, field, row), wheretextis the text to be written in the cell,dataholds the text elements in the table row,fieldis the column field, androwis the one-based row number. The function returns an object with the text attributes that are to be modified for the table cell.
- [.name]
- [.header]
object|boolean= false- When true, the column name associated with a column will appear at the top of the column. When presented as an object it is the set of unique options to be applied to column headers. All 'text' interface options can be used.- [.cell]
object- All textBox options from the 'text' interface can be used here.
- [.cell]
- [.border]
object|boolean- Used to define table and cell border characteristics- [.width]
number= .5- Thickness of lines used in the border. - [.stroke]
string|Array.<number>- line color (HexColor, PercentColor or DecimalColor)
- [.width]
- [.overflow]
function- Called when the next table entry is going to expand the table beyond the given height or page boundary. Its parameters are (self, row) where 'self' is the recipe handle so that other recipe interfaces can be called, and the row number of the data which caused the data overflow. The callback'sthisis also the Recipe instance. The return value can be 'true' which indicates that data processing should stop, or 'false' which indicates that the data should continue being processed with the original [x,y] coordinates, or it can be an object containing a 'position' property indicating the [x,y] coordinates where the next table for the remaining data should start. - [.row]
object- text properties to be applied to all cells in a table row.- [.cell]
object- All textBox options from the 'text' interface can be used here. - [.nth]
Recipe.TableRowNth- ARecipe.TableRowNthvalue, indicating that the properties should be applied only to 'even' or 'odd' rows.
- [.cell]
recipe.textDimensions(text, [options]) ⇒ Object
Get text dimensions
Kind: instance method of Recipe
Returns: Object - measurement components of given text: width, height, xMin, xMax, yMin, yMax
Throws:
ErrorIf the font file cannot be loaded.
Params
- text
string- text to be measured - [options]
Object- The options - [.font]
string= "'helvetica'"- name of font from which measurements are to be taken - [.size]
number= 14- size of font to be used in taking measurements - [.charSpace]
number= 0- character spacing being applied to the given text. - [.bold]
boolean- Measure with the bold style of the font. - [.italic]
boolean- Measure with the italic style of the font.
recipe.text([text], [x], [y], [options]) ⇒ Recipe
Write text elements
Kind: instance method of Recipe
Returns: Recipe - The recipe instance. Without an active page nothing is drawn.
Throws:
TypeErrorIfoptions.charSpaceoroptions.rotationis not a finite number; nothing is drawn.RangeErrorIfoptions.sizeis not greater than zero oroptions.miterLimitis below 1; nothing is drawn.ErrorIf an overflow callback names an undefined layout, or a font cannot be loaded.
Todo
- [ ] support break words
Params
- [text]
string= "''"- The text content - [x]
number|"center"|Object- The coordinate x, or the options to continue at the current position - [y]
number|"center"- The coordinate y - [options]
Object- The options - [.color]
string|Array.<number>- Text color (HexColor, PercentColor or DecimalColor) - [.opacity]
number= 1- opacity - [.rotation]
number= 0- Clockwise rotation in degrees, +/- 0 through 360. - [.rotationOrigin]
Array.<number>= [x,y]- [originX, originY] - [.font]
string= "Helvetica"- The font. 'Arial', 'Helvetica'... - [.size]
number= 14- The font size - [.charSpace]
number= 0- space to be added between characters, units in points. - [.align]
string= "'left top'"- This is the alignment of the text in relationship to its position coordinates, specified as 'horizontal vertical': aRecipe.HorizontalAlignvalue, optionally followed by a space and aRecipe.VerticalAlignvalue. - [.highlight]
Object|Boolean- Text markup annotation. - [.underline]
Object|Boolean- Text markup annotation. - [.strikeOut]
Object|Boolean- Text markup annotation. - [.html]
Boolean- Interpret text as html - [.flow]
Boolean- Used to activate/deactivate text flow which is the ability to use multiple calls to 'text' to create an overall text box. Defaults totruefor a call without coordinates andfalsefor a call with them. - [.layout]
number|string- An identifier of the layout to be associated with given text. - [.overflow]
function- Called when the text is going to exceed the area of the given text object. Intended for column layouts. Its parameter is (self) where 'self' is the recipe handle so that other recipe interfaces can be called. The return value can be 'true' which indicates that text processing should stop, or 'false' which indicates that the text should continue being processed with the original [x,y] coordinates, or it can be an object containing a 'column' property indicating either a layout column index or a set of [x,y] coordinates where the next set of layout columns should be positioned for the remaining text. - [.hilite]
Boolean|Object= false- Used to hilite given text.- [.color]
string|Array.<number>= "yellow"- text hilite color (HexColor, PercentColor or DecimalColor) - [.opacity]
number= .5- text hilite color opacity
- [.color]
- [.textBox]
Object- Text Box to fit in.- [.width]
number= 100- Text Box width - [.height]
number- Text Box fixed height - [.minHeight]
number= 0- Text Box minimum height - [.padding]
number|Array.<number>= 0- Text Box padding, [top, right, bottom, left] - [.lineHeight]
number= 0- Text Box line height - [.wrap]
Recipe.TextWrap|Boolean= 'auto'- Text wrapping mechanism, may be true, false, or aRecipe.TextWrapvalue: 'auto', 'clip', 'trim', 'ellipsis'. All the option values that are not equivalent to 'auto' dictate how the text which does not fit on a line is to be truncated. True is equivalent to 'auto'. False is equivalent to 'ellipsis'. - [.textAlign]
string= "'left top'"- Alignment inside text box, specified as 'horizontal vertical', where horizontal is aRecipe.TextAlignvalue and vertical aRecipe.VerticalAlignvalue. - [.clipIfExceedsBox]
boolean= false- Render only complete lines that fit within the text box height. - [.onClip]
function- Called as onClip(recipe, result) when clipping leaves text unrendered. Do not call endPage() or endPDF() in this callback because the text operation is still active. - [.style]
Object- Text Box styles - [.lineWidth]
number= 2- Text Box border width - [.stroke]
string|Array.<number>- Text Box border color (HexColor, PercentColor or DecimalColor) - [.dash]
Array.<number>= []- Text Box border border dash style [number, number] - [.fill]
string|Array.<number>- Text Box border background color (HexColor, PercentColor or DecimalColor) - [.opacity]
number= 1- Text Box border background opacity - [.borderRadius]
boolean|number|Array.<number>= 0- Border radius to apply to get rounded corners.
- [.width]
- [.title]
string- Title of annotation - [.open]
boolean= false- Open the annotation. Annotation will be closed by default. Specific to text annotations; subtype='Text' - [.richText]
boolean- Rich text in annotation - [.flag]
Recipe.AnnotFlag- The annotation flag, aRecipe.AnnotFlagvalue. - [.icon]
Recipe.AnnotIcon= 'Note'- The icon of annotation, aRecipe.AnnotIconvalue. Specific to text annotations. - [.date]
string- Date of text to show up on annotation - [.subject]
string- Subject of annotation. - [.link]
string- Make the text open this URL.
recipe.movedown([lines], [returnCoords]) ⇒ Object | Array.<number>
Move text positioning down N lines in text box
Kind: instance method of Recipe
Returns: Object | Array.<number> - - when returnCoord false, the recipe object, when true, the new [x,y] coordinates.
Params
- [lines]
number= 1- the number of lines to reposition x and y coordinates - [returnCoords]
Boolean= false- indicate whether or not to return [x,y] coordinates
recipe.layout(id, [x], [y], [width], [height], [options]) ⇒ Recipe
Define text column layout
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf width or height is omitted while no page is active.
Params
- id
number|string- The identifier to be associated with the layout. (See 'text' layout option) - [x]
number- The coordinate x used to position text columns on page. When zero or omitted, left margin used. - [y]
number- The coordinate y used to position text columns on page. When zero or omitted, top margin used. - [width]
number- The width of a text column. When zero or omitted, space between left and right margin used. - [height]
number- The height of a text column. When zero or omitted, space between top and bottom margin used. - [options]
object- The options. - [.columns]
number- Represents the number of columns in which to divide the given width. - [.gap]
number= 18- Defines the separation between layout columns, units in points. - [.reset]
boolean- True indicates that the a new layout should be produced for the given layout id, so any previous layout associated with the given id will be lost.
recipe.moveTo(x, y) ⇒ Recipe
move the current position to target position
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- x
number|"center"- The coordinate x - y
number|"center"- The coordinate y
recipe.lineTo(x, y, [options]) ⇒ Recipe
Draw a line from current position
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- x
number|"center"- The coordinate x - y
number|"center"- The coordinate y - [options]
Object- The options - [.color]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- how transparent should line be, from 0: invisible to 1: opaque - [.dash]
Array.<number>- The dash pattern [dashSize, gapSize] or [dashAndGapSize] - [.dashPhase]
number- distance into dash pattern at which to start dash (default: 0, immediately) - [.lineCap]
Recipe.LineCap- open line end style, aRecipe.LineCapvalue (default: 'round') - [.lineJoin]
Recipe.LineJoin- joined line end style, aRecipe.LineJoinvalue (default: 'round') - [.miterLimit]
number- limit at which 'miter' joins are forced to 'bevel' (default: 1.414)
recipe.line(coordinates, [options]) ⇒ Recipe
Draw a line through coordinate pairs, or from (startX, startY) to
(endX, endY) when called as line(startX, startY, endX, endY, options?).
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- coordinates
Array.<Array.<number>>|number- The array of coordinate [[x,y], [m,n]], or the start x - [options]
Object- The options, or the start y in the four-number form - [.color]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- how transparent should line be, from 0: invisible to 1: opaque - [.dash]
Array.<number>- The dash pattern [dashSize, gapSize] or [dashAndGapSize] - [.dashPhase]
number- distance into dash pattern at which to start dash (default: 0, immediately) - [.lineCap]
Recipe.LineCap- open line end style, aRecipe.LineCapvalue (default: 'round') - [.lineJoin]
Recipe.LineJoin- joined line end style, aRecipe.LineJoinvalue (default: 'round') - [.miterLimit]
number- limit at which 'miter' joins are forced to 'bevel' (default: 1.414)
recipe.polygon(coordinates, [options]) ⇒ Recipe
Draw a polygon
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active or there are no coordinates.
Params
- coordinates
Array.<number>- The array of coordinate [[x,y], ... [m,n]] - [options]
Object- The options - [.color]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.fill]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash pattern [dashSize, gapSize] or [dashAndGapSize] - [.dashPhase]
number- distance into dash pattern at which to start dash (default: 0, immediately) - [.rotation]
number- Clockwise rotation in degrees, +/- 0 through 360. Default: 0 - [.rotationOrigin]
Array.<number>- [originX, originY] Default: x, y - [.lineCap]
Recipe.LineCap- open line end style, aRecipe.LineCapvalue (default: 'round') - [.lineJoin]
Recipe.LineJoin- joined line end style, aRecipe.LineJoinvalue (default: 'round') - [.miterLimit]
number- limit at which 'miter' joins are forced to 'bevel' (default: 1.414) - [.link]
string- Make the polygon's bounding box open this URL.
recipe.circle(x, y, radius, [options]) ⇒ Recipe
Draw a circle
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- x
number|"center"- The coordinate x of the center - y
number|"center"- The coordinate y of the center - radius
number- The radius - [options]
Object- The options - [.color]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.fill]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash style [number, number] - [.link]
string- Make the circle's bounding square open this URL.
recipe.rectangle(x, y, width, height, [options]) ⇒ Recipe
Draw a rectangle
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- x
number|"center"- The coordinate x of the top-left corner - y
number|"center"- The coordinate y of the top-left corner - width
number- The width - height
number- The height - [options]
Object- The options - [.color]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.fill]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash style [number, number] - [.rotation]
number- Clockwise rotation in degrees, +/- 0 through 360. Default: 0 - [.rotationOrigin]
Array.<number>- [originX, originY] Default: x, y - [.borderRadius]
number|Array.<number>- Radius size for rounded corners. When a one to four number array can be used to give specific sizees to each corner. The numbering starts from the top, left corner, and goes clockwise around the text box. Missing values in the array are filled in by opposite corner values. - [.link]
string- Make the rectangle open this URL. - [.useGivenCoords]
boolean- Take x and y as PDF coordinates of the bottom-left corner.
recipe.ellipse(cx, cy, rx, ry, [options]) ⇒ Recipe
Draw an ellipse
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- cx
number|"center"- x-coordinate of center point of ellipse - cy
number|"center"- y-coordinate of center point of ellipse - rx
number- radius length from the center point along x-axis - ry
number- radius length from the center point along y-axis - [options]
Object - [.color]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.fill]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash style [number, number] - [.rotation]
number- Clockwise rotation in degrees, +/- 0 through 360. Default: 0 - [.rotationOrigin]
Array.<number>- [originX, originY] Default: x, y
recipe.arc(x, y, radius, [startAngle], [endAngle], [options]) ⇒ Recipe
Draw an arc of a circle.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- x
number|"center"- the x coordinate of the arc center point - y
number|"center"- the y coordinate of the arc center point - radius
number- the distance from the given x,y coordinates from which to produce the arc - [startAngle]
number= 0- the start of the arc in degree units +/- 0 through 360. Positive values go clockwise, Negative values, counterclockwise. - [endAngle]
number= 360- the end of the arc in degree units +/- 0 through 360. Positive values go clockwise, Negative values, counterclockwise. - [options]
Object - [.color]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.stroke]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.fill]
string|Array.<number>- HexColor, PercentColor or DecimalColor - [.lineWidth]
number- The line width - [.opacity]
number- The opacity - [.dash]
Array.<number>- The dash style [number, number] - [.rotation]
number= 0- Clockwise rotation in degrees, +/- 0 through 360. - [.rotationOrigin]
Array.<number>- [originX, originY] Default: x, y
recipe.pie(x, y, radius, [startAngle], [endAngle], [options]) ⇒ Recipe
Draw a closed sector of a circle.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- x
number|"center"- the x coordinate of the pie center point - y
number|"center"- the y coordinate of the pie center point - radius
number- the distance from the center point to the arc - [startAngle]
number= 0- the start of the arc in degree units - [endAngle]
number= 360- the end of the arc in degree units - [options]
Object- The path options.
recipe.lineStyle([options]) ⇒ Recipe
Set the line style for the current page content context.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.RangeErrorIfmiterLimitis not a number of at least 1.
Params
- [options]
Recipe.LineStyleOptions- The line style options. - [.width]
number- The line width. - [.lineWidth]
number- Alias for width. - [.cap]
number- The PDF line cap style, aLineCapStylevalue. - [.join]
number- The PDF line join style: 0 miter, 1 round, 2 bevel. - [.miterLimit]
number- The miter limit, at least 1. - [.dash]
Array.<number>- The dash pattern. - [.dashPhase]
number- The dash pattern phase.
recipe.lineWidth(width) ⇒ Recipe
Set the line width.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
TypeErrorIf no page is active.
Params
- width
number- The line width.
recipe.opacity(value) ⇒ Recipe
Set fill and stroke opacity.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
Throws:
RangeErrorIf the value is not a finite number from 0 to 1.
Params
- value
number- The requested opacity from 0 (transparent) to 1 (opaque).
recipe.fill() ⇒ Recipe
Fill the current path.
This compatibility method currently has no effect.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
recipe.stroke() ⇒ Recipe
Stroke the current path.
This compatibility method currently has no effect.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
recipe.fillAndStroke() ⇒ Recipe
Fill and stroke the current path.
This compatibility method currently has no effect.
Kind: instance method of Recipe
Returns: Recipe - The recipe instance.
BLOCK_END
Matches HTML that ends with a closed block element, which ends its line.
Kind: global constant
BLOCK_START
Matches HTML that opens with a block element, which starts a new line.
Kind: global constant
LINE_BREAK_END
Matches the line break that ends a word at a required break.
Kind: global constant
PAGE_CONTEXT_STATE
Recipe page content-stream lifecycle states.
Kind: global constant
loadPrototypes() ⇒ void
Install every method exported by lib/recipe/*.js on the Recipe prototype.
Kind: global function Throws:
stringIf two recipe modules export the same member.
resolve(recipe, object) ⇒ object
Resolve an object through an indirect reference.
Kind: global function
Returns: object - Resolved PDF object.
Params
- recipe
Recipe- Recipe with an open source reader. - object
object- PDF object or indirect reference.
lookup(recipe, dictionary, key) ⇒ object | null
Look up a dictionary entry and resolve it.
Kind: global function
Returns: object | null - Resolved PDF object, or null when missing.
Params
- recipe
Recipe- Recipe with an open source reader. - dictionary
object- PDF dictionary. - key
string- Entry name.
readContentStream(recipe, objectId) ⇒ string
Read and decode one content stream as a Latin-1 string.
Kind: global function
Returns: string - Decoded stream bytes, one character per byte.
Params
- recipe
Recipe- Recipe with an open source reader. - objectId
number- Stream object ID.
resolveFontSize([options], [fallback]) ⇒ number
Resolves a text font size from size, its fontSize alias, or a fallback,
rejecting a size that is not a finite number greater than zero. Zero,
negative, and infinite sizes have
no usable meaning: they draw nothing readable and measure to nonsensical font
metrics, so they are reported as invalid input naming the option and the
value. Omitting both options, or passing null or undefined, selects the
fallback.
Kind: global function
Returns: number - The resolved font size in PDF points.
Throws:
RangeErrorIf the given size is not a finite number greater than zero.
Params
- [options]
Object- Options holdingsizeorfontSize. - [fallback]
number- Size used when neither option is given.