Utils#

The following are miscellaneous functions and attributes on a fairly low-level technical detail.

Some functions provide detail access to PDF structures. Others are stripped-down, high performance versions of other functions which provide more information.

Yet others are handy, general-purpose utilities.

Function

Short Description

ConversionHeader()

Return header string for get_text methods

sRGB2rgb()

Convenience function returning a color (red, green, blue) for a given sRGB color integer

ConversionTrailer()

Return trailer string for get_text methods

EMPTY_IRECT()

Return the (standard) empty / invalid rectangle

EMPTY_QUAD()

Return the (standard) empty / invalid quad

EMPTY_RECT()

Return the (standard) empty / invalid rectangle

INFINITE_IRECT()

Return the (only existing) infinite rectangle

INFINITE_QUAD()

Return the (only existing) infinite quad

INFINITE_RECT()

Return the (only existing) infinite rectangle

GetPdfNow()

Return the current timestamp in PDF format

GetPdfString()

Return PDF-compatible string

GetTextLength()

Return string length for a given font & fontsize

GlyphName2Unicode()

Return unicode from a glyph name

GetImageProfile()

Return a dictionary of basic image properties

INFINITE_RECT()

Return the (only existing) infinite rectangle

PaperRect()

Return rectangle for a known paper format

PaperSize()

Return width, height for a known paper format

PaperSizes()

Dictionary of pre-defined paper formats

PlanishLine()

Matrix to map a line to the x-axis

RecoverCharQuad()

Compute the quad of a char (“rawdict”)

RecoverLineQuad()

Compute the quad of a subset of line spans

RecoverQuad()

Compute the quad of a span (“dict”, “rawdict”)

RecoverSpanQuad()

Compute the quad of a subset of span characters

Unicode2GlyphName()

Return glyph name from a unicode

MakeAnnotDA()

Passing color, fontname, fontsize into the annotation

AddAnnotId()

Add a unique /NM key to an annotation or widget

AddOcObject()

Add OC object reference to a dictionary

ColorCount()

Return count of each color

BinFromBuffer()

Turn FzBuffer into a byte[]

BufferFromBytes()

Make FzBuffer from a byte[] object

CalcImageMatrix()

Compute image insertion matrix

CompressBuffer()

Compress FzBuffer into a new buffer

GetPdfString()

Make a PDF-compatible string

ConstructLabel()

Construct a label based on style, prefix and page number

DecodeRawUnicodeEscape()

Decode raw unicode

DoLinks()

Insert links contained in copied page range into destination PDF

EnsureIdentity()

Store ID in PDF trailer

ExpandFontName()

Make /DA string of annotation

GetId()

Count numbers and return unique id on one process

GetAllContents()

All /Contents streams concatenated to one bytes object

GetAnnotByName()

Retrieve annotation by name (/NM key)

GetArea()

Calculate area of rectangle

GetBorderStyle()

Return int meaning PdfObj “border style” from string type

GetColors()

Retrieve the red, green, blue triple of a color name

GetColorHSV()

Retrieve the hue, saturation, value triple of a color name

GetColorInfoList()

Returns Tuples containing color name, red, green, blue color values

GetDestString()

Calculate the PDF action string

GetFieldTypeText()

Returns field type string from int type

GetFontProperties()

Returns properties of the font having xref in PDF

GetGlyphText()

Adobe Glyph List function

GetImageExtension()

Return extension for MuPDF image type

GetLinkText()

Define skeletons for /Annots object texts

GetTextWithLayout()

Retrieves the text content of a page that retains layout.

GetTables()

Return the tables detected from a Page instance

GetWidgetProperties()

Populate a Widget object with the values from a PDF form field

InsertContents()

Insert a buffer as a new separate /Contents object of a page

Integer2Letter()

Return letter sequence string for integer i

Integer2Roman()

Return roman numeral for integer i

MeasureString()

Calculate the width of the text

MergeRange()

Copy a range of pages (spage, epage) from a source PDF to a specified location (apage) of the target PDF

NormalizeRotation()

Return normalized /Rotate value:one of 0, 90, 180, 270

RuleDict()

Make a Label from a PDF page label rule

ReadBarcodes()

Reads bardcodes from a Page instance

WriteBarcode()

Writes a barcode to an image file

GetBarcodePixmap()

Creates a barcode as a Pixmap object.

ReplaceBytes()

Replaces bytes from a source buffer

TESSDATA_PREFIX

A copy of os.environ["TESSDATA_PREFIX"]

PaperSize()#

Convenience function to return width and height of a known paper format code. These values are given in pixels for the standard resolution 72 pixels = 1 inch.

Currently defined formats include ‘A0’ through ‘A10’, ‘B0’ through ‘B10’, ‘C0’ through ‘C10’, ‘Card-4x6’, ‘Card-5x7’, ‘Commercial’, ‘Executive’, ‘Invoice’, ‘Ledger’, ‘Legal’, ‘Legal-13’, ‘Letter’, ‘Monarch’ and ‘Tabloid-Extra’, each in either portrait or landscape format.

A format name must be supplied as a string (case in sensitive), optionally suffixed with “-L” (landscape) or “-P” (portrait). No suffix defaults to portrait.

Parameters:

s – any format name from above in upper or lower case, like “A4” or “letter-l”.

Return type:

Tuple

Returns:

(width, height) of the paper format. For an unknown format (-1, -1) is returned. Examples: PaperSize(“A4”) returns (595, 842) and PaperSize(“letter-l”) delivers (792, 612).


PaperRect()#

Convenience function to return a Rect for a known paper format.

Parameters:

size (string) – any format name supported by PaperSize().

Return type:

Rect

Returns:

Rect(0, 0, width, height) with width, height = Utils.PaperSize(size).


sRGB2Pdf(int srgb)#

Convenience function returning a PDF color triple (red, green, blue) for a given sRGB color integer as it occurs in Page.GetText() dictionaries “dict” and “rawdict”.

Parameters:

srgb (int) – an integer of format RRGGBB, where each color component is an integer in range(255).

Returns:

a tuple (red, green, blue) with float items in interval 0 <= item <= 1 representing the same color. Example sRGB2Pdf(0xff0000) = (1, 0, 0) (red).


sRGB2Rgb(int srgb)#

Convenience function returning a color (red, green, blue) for a given sRGB color integer.

Parameters:

srgb (int) – an integer of format RRGGBB, where each color component is an integer in range(255).

Returns:

a tuple (red, green, blue) with integer items in range(256) representing the same color. Example sRGB2Pdf(0xff0000) = (255, 0, 0) (red).


GlyphName2Unicode(string name)#

Return the unicode number of a glyph name based on the Adobe Glyph List.

Parameters:

name (string) – the name of some glyph. The function is based on the Adobe Glyph List.

Return type:

int

Returns:

the unicode. Invalid name entries return 0xfffd (65533).


Unicode2GlyphName(int ch)#

Return the glyph name of a unicode number, based on the Adobe Glyph List.

Parameters:

ch (int) –

the unicode given by e.g. ord("ß"). The function is based on the Adobe Glyph List.

Return type:

string

Returns:

the glyph name. E.g. Utils.Unicode2GlyphName(Convert.Int32("Ä")) returns 'Adieresis'.


PlanishLine(Point p1, Point p2)#

Return a matrix which maps the line from p1 to p2 to the x-axis such that p1 will become (0,0) and p2 a point with the same distance to (0,0).

Parameters:
  • p1 (Point) – starting point of the line.

  • p2 (Point) – end point of the line.

Return type:

Matrix

Returns:

a matrix which combines a rotation and a translation

glossary/images/img-planish.png


PaperSizes#

A dictionary of pre-defines paper formats. Used as basis for PaperSize().


TESSDATA_PREFIX#

Copy of os.environ["TESSDATA_PREFIX"] for convenient checking whether there is integrated Tesseract OCR support.

If this attribute is None, Tesseract-OCR is either not installed, or the environment variable is not set to point to Tesseract’s language support folder.

Note

This variable is now checked before OCR functions are tried. This prevents verbose messages from MuPDF.


GetPdfNow()#

Convenience function to return the current local timestamp in PDF compatible format, e.g. D:20170501121525-04’00’ for local datetime May 1, 2017, 12:15:25 in a timezone 4 hours westward of the UTC meridian.

Return type:

string

Returns:

current local PDF timestamp.


GetTextLength(string text, string fontName: "helv", float fontSize: 11, int encoding: 0)#

Calculate the length of text on output with a given built in font, fontSize and encoding.

Parameters:
  • text (string) – the text string.

  • fontName (string) – the fontName. Must be one of either the Base-14-Fonts or the CJK fonts, identified by their “reserved” fontnames (see table in Page.InsertFont()).

  • fontSize (float) – the fontSize.

  • encoding (int) – the encoding to use. Besides 0 = Latin, 1 = Greek and 2 = Cyrillic (Russian) are available. Relevant for Base-14 fonts “Helvetica”, “Courier” and “Times” and their variants only. Make sure to use the same value as in the corresponding text insertion.

Return type:

float

Returns:

the length in points the string will have (e.g. when used in Page.InsertText()).

Note

This function will only do the calculation – it won’t insert font nor text.

Note

The Font class offers a similar method, Font.text_length(), which supports Base-14 fonts and any font with a character map (CMap, Type 0 fonts).

Warning

If you use this function to determine the required rectangle width for the (Page or Shape) InsertTextbox methods, be aware that they calculate on a by-character level.


GetPdfString(string text)#

Make a PDF-compatible string: if the text contains code points Convert.ToInt32(c) > 255, then it will be converted to UTF-16BE with BOM as a hexadecimal character string enclosed in “<>” brackets like <feff…>. Otherwise, it will return the string enclosed in (round) brackets, replacing any characters outside the ASCII range with some special code. Also, every “(”, “)” or backslash is escaped with a backslash.

Parameters:

text (string) – the object to convert

Return type:

string

Returns:

PDF-compatible string enclosed in either () or <>.


GetImageProfile(byte[] stream)#

Show important properties of an image provided as a memory area. Its main purpose is to avoid using other libraries just to determine them.

Parameters:

stream (byte[]) – either an image in memory or an opened file. An image in memory may be any of the formats bytes.

Return type:

ImageInfo

Returns:

No exception is ever raised. In case of an error, None is returned. Otherwise, there are the following items:

There is the following relation to Exif information encoded in orientation, and correspondingly in the transform matrix-like (quoted from MuPDF documentation, ccw = counter-clockwise):

  1. Undefined

  2. 0 degree ccw rotation. (Exif = 1)

  3. 90 degree ccw rotation. (Exif = 8)

  4. 180 degree ccw rotation. (Exif = 3)

  5. 270 degree ccw rotation. (Exif = 6)

  6. Flip on X. (Exif = 2)

  7. Flip on X, then rotate ccw by 90 degrees. (Exif = 5)

  8. Flip on X, then rotate ccw by 180 degrees. (Exif = 4)

  9. Flip on X, then rotate ccw by 270 degrees. (Exif = 7)

Note

  • For some “exotic” images (FAX encodings, RAW formats and the like), this method will not work. You can however still work with such images in MupDF.NET, e.g. by using Document.ExtractImage() or create pixmaps via Pixmap(doc, xref). These methods will automatically convert exotic images to the PNG format before returning results.

  • You can also get the properties of images embedded in a PDF, via their xref. In this case make sure to extract the raw stream: Utils.GetImageProfile(doc.GetXrefStreamRaw(xref)).

  • Images as returned by the image blocks of Page.GetText() using “dict” or “rawdict” options are also supported.


ConversionHeader(string i: "text", string filename: "UNKNOWN")#

Return the header string required to make a valid document out of page text outputs.

Parameters:
  • i (string) – type of document. Use the same as the output parameter of GetText().

  • filename (string) – optional arbitrary name to use in output types “json” and “xml”.

Return type:

string


ConversionTrailer(string i)#

Return the trailer string required to make a valid document out of page text outputs. See Page.GetText() for an example.

Parameters:

i (string) – type of document. Use the same as the output parameter of GetText().

Return type:

string


RecoverQuad((float, float) lineDir, Span span)#

Compute the quadrilateral of a text span extracted via options “dict” or “rawdict” of Page.GetText().

Parameters:
  • lineDir ((float, float)) – line["dir"] of the owning line. Use None for a span from Page.GetTextTrace().

  • span (Span) – the span.

Returns:

the Quad of the span, usable for text marker annotations (‘Highlight’, etc.).


RecoverCharQuad((float, float) lineDir, Span span, Char char)#

Compute the quadrilateral of a text character extracted via option “rawdict” of Page.GetText().

Parameters:
  • lineDir ((float, float)) – line["dir"] of the owning line. Use None for a span from Page.GetTextTrace().

  • span (Span) – the span.

  • char (Char) – the character.

Returns:

the Quad of the character, usable for text marker annotations (‘Highlight’, etc.).


RecoverSpanQuad((float, float) lineDir, Span span, Char[] chars: None)#

Compute the quadrilateral of a subset of characters of a span extracted via option “rawdict” of Page.GetText().

Parameters:
  • lineDir ((float, float)) – line["dir"] of the owning line. Use None for a span from Page.GetTextTrace().

  • span (Span) – the span.

  • chars (Char[]) – the characters to consider. If given, the selected extraction option must be “rawdict”.

Returns:

the Quad of the selected characters, usable for text marker annotations (‘Highlight’, etc.).


RecoverLineQuad(Line line, List<Span> spans: None)#

Compute the quadrilateral of a subset of spans of a text line extracted via options “dict” or “rawdict” of Page.GetText().

Parameters:
  • line (Line) – the line.

  • spans (Span[]) – a sub-list of line.Spans. If omitted, the full line quad will be returned.

Returns:

the Quad of the selected line spans, usable for text marker annotations (‘Highlight’, etc.).



INFINITE_QUAD()#
INFINITE_RECT()#
INFINITE_IRECT()#

Return the (unique) infinite rectangle Rect(-2147483648.0, -2147483648.0, 2147483520.0, 2147483520.0), resp. the IRect and Quad counterparts. It is the largest possible rectangle: all valid rectangles are contained in it.


EMPTY_QUAD()#
EMPTY_RECT()#
EMPTY_IRECT()#

Return the “standard” empty and invalid rectangle Rect(2147483520.0, 2147483520.0, -2147483648.0, -2147483648.0) resp. quad. Its top-left and bottom-right point values are reversed compared to the infinite rectangle. It will e.g. be used to indicate empty bboxes in page.get_text("dict") dictionaries. There are however infinitely many empty or invalid rectangles.


CalcImageMatrix(int width, int height, Rect tr, float rotate, bool keep)#

Compute image insertion matrix

Parameters:
  • width (int) – image width

  • height (int) – image height

  • tr (Rect) – rect of target image

  • rotate (float) – rotate to be set for target image

  • keep (bool) – calc size of target image keeping origin image’s ratio

Returns:

Matrix


ColorCount(FzPixmap pm, dynamic clip)#

Return count of each color.

Parameters:
  • pm (FzPixmap) – source pixmap

  • clip (Rect) – count colors in clip area of source pixmaps.

Returns:

return count of each color.


ConstructLabel(string style, string prefix, int pno)#

Construct a label based on style, prefix and page number.

Parameters:
  • style (string) – type of style for label. That includes D, r, R, a, A.

  • prefix (string) – added prefix to label

  • pno (int) – translate pno to letter according to the style

Return type:

string

Returns:

styled label


DecodeRawUnicodeEscape(FzBuffer s)#
DecodeRawUnicodeEscape(string s)#

Decode raw unicode


Insert links contained in copied page range into destination PDF.


EnsureIdentity(Document pdf)#

Store ID in PDF trailer


ExpandFontName(string fontname)#

Make /DA string of annotation

Returns:

expand font name. For example, if fontname starts with co or Co, returns Cour


GetId()#

Count numbers and return unique id on one process

Return type:

int

Returns:

unique number


GetAllContents(Page page)#

All /Contents streams concatenated to one bytes object.

Parameters:

page (Page) – Page object to get all streams

Return type:

byte[]


GetAnnotByName(Page page, string name)#

Retrieve annotation by name (/NM key)

Parameters:
  • page (Page) – Page object containing annotations.

  • name (string) – annotation name. Looping annotations in page, that find the annotation which has name as ID.

Return type:

PdfAnnot

Returns:

PdfAnnot object that has the name.


GetArea(Rect rect, string unit: "px")#

Calculate area of rectangle. Parameter is one of ‘px’ (default), ‘in’, ‘cm’, or ‘mm’.

Parameters:
  • rect (Rect) – rectangle calculated area

  • unit (string) – unit used in rect. default is px, there are other units like cm, mm.

Return type:

float

Returns:

area of rectangle


GetBorderStyle(string style)#

Return int meaning PdfObj “border style” from string type.

Parameters:

style (string) – border type in format of style. style can be one of ‘B’, ‘D’, ‘I’, ‘U’, ‘S’ or lowercases.

Returns:

return int from border pdfobj.


GetColors(string name)#

Retrieve the red, green, blue triple of a color name.

Parameters:

name (string) – color name

Return type:

float[]

Returns:

return float array equal to color name. If invalid color name, return (1, 1, 1) - white.


GetColorHSV(string name)#

Retrieve the hue, saturation, value triple of a color name.

Returns:

a triple (degree, percent, percent). If not found (-1, -1, -1) is returned.


GetColorInfoList()#

Return Tuples containing of color name, red, green, blue color values.


GetDestString(int xref, int dDict)#
GetDestString(int xref, float dDict)#
GetDestString(int xref, LinkInfo dDict)#

Calculate the PDF action string.

Parameters:
  • xref (int) – the xref of the link pdfobj.

  • dDict (LinkInfo) – one parameter of coordinate positioned in PDF

  • dDict – one parameter of coordinate positioned in PDF

  • dDict – link info contains ‘Kind’, ‘From’, ‘To’, ‘Page’, ‘Xref’, …

Returns:

string of PDF action


GetFieldTypeText(int wtype)#

Return field type string from int type.


GetFontProperties(Document doc, int xref)#

Return properties of the font having xref in PDF. Properties are ‘Name’, ‘Extension’, ‘Type’, ‘Asc’, ‘Desc’.

Parameters:
  • xref (int) – the xref of the font

  • doc (Document) – source PDF that has the font.

Return type:

Tuple(string, string, string, float, float)

Returns:

properties of the font.


GetGlyphText()#

Adobe Glyph List function


GetImageExtension(int type)#

Return extension for MuPDF image type.


GetLinkText(Page page, LinkInfo link)#

Define skeletons for /Annots object texts

Returns:

annot string.


GetTextWithLayout(Page page, Rect clip: null, int flags: 0, int tolerance: 5)#

Retrieves the text content of a page that retains layout. Positioning of text is adjusted by spaces.

Parameters:
  • page (Page) – The page instance.

  • clip (Rect) – Specify a region to consider within the page rectangle and ignore the rest. Default null is the full page.

  • flags (int) – Indicator bits to control whether to include images or how text should be handled with respect to white spaces and ligatures.

  • tolerance (int) – Neighborhood threshold.

Return type:

string

Returns:

a string containing the text with layout applied.


GetTables(Page page, Rect clip: null, string strategy: null, string vertical_strategy: "lines", string horizontal_strategy: "lines", List<Line> add_lines: null, List<Edge> vertical_lines: null, List<Edge> horizontal_lines: null, float snap_tolerance: TableFlags.TABLE_DEFAULT_SNAP_TOLERANCE, float snap_x_tolerance: 0.0f, float snap_y_tolerance: 0.0f, float join_tolerance: TableFlags.TABLE_DEFAULT_JOIN_TOLERANCE, float join_x_tolerance: 0.0f, float join_y_tolerance: 0.0f, float edge_min_length: 3.0f, float min_words_vertical: TableFlags.TABLE_DEFAULT_MIN_WORDS_VERTICAL, float min_words_horizontal: TableFlags.TABLE_DEFAULT_MIN_WORDS_HORIZONTAL, float intersection_tolerance: 3.0f, float intersection_x_tolerance: 0.0f, float intersection_y_tolerance: 0.0f, float text_tolerance: 3.0f, float text_x_tolerance: 3.0f, float text_y_tolerance: 3.0f)#

Find tables on the page and return a list with related information. Typically, the default values of the many parameters will be sufficient. Adjustments should ever only be needed in corner case situations.

Parameters:
  • page (Page) – The page instance to use for table detection.

  • clip (Rect) – specify a region to consider within the page rectangle and ignore the rest. Default null is the full page.

  • strategy (str) –

    Request a table detection strategy. Valid values are “lines”, “lines_strict” and “text”.

    Default is “lines” which uses all vector graphics on the page to detect grid lines.

    Strategy “lines_strict” ignores borderless rectangle vector graphics. Sometimes single text pieces have background colors which may lead to false columns or lines. This strategy ignores them and can thus increase detection precision.

    If “text” is specified, text positions are used to generate “virtual” column and / or row boundaries. Use min_words_* to request the number of words for considering their coordinates.

    Use parameters vertical_strategy and horizontal_strategy instead for a more fine-grained treatment of the dimensions.

  • add_lines (List<Line>) – Specify a list of “lines” (i.e. pairs of Line objects) as additional, “virtual” vector graphics. These lines may help with table and / or cell detection and will not otherwise influence the detection strategy. Especially, in contrast to parameters horizontal_lines and vertical_lines, they will not prevent detecting rows or columns in other ways. These lines will be treated exactly like “real” vector graphics in terms of joining, snapping, intersectiing, minimum length and containment in the clip rectangle. Similarly, lines not parallel to any of the coordinate axes will be ignored.

  • snap_tolerance (float) – Any two horizontal lines whose y-values differ by no more than this value will be snapped into one. Accordingly for vertical lines. Default is 3. Separate values can be specified instead for the dimensions, using snap_x_tolerance and snap_y_tolerance.

  • join_tolerance (float) – Any two lines will be joined to one if the end and the start points differ by no more than this value (in points). Default is 3. Instead of this value, separate values can be specified for the dimensions using join_x_tolerance and join_y_tolerance.

  • edge_min_length (float) – Ignore a line if its length does not exceed this value (points). Default is 3.

  • min_words_vertical (int) – relevant for vertical strategy option “text”: at least this many words must coincide to establish a virtual column boundary.

  • min_words_horizontal (int) – relevant for horizontal strategy option “text”: at least this many words must coincide to establish a virtual row boundary.

  • intersection_tolerance (float) – When combining lines into cell borders, orthogonal lines must be within this value (points) to be considered intersecting. Default is 3. Instead of this value, separate values can be specified for the dimensions using intersection_x_tolerance and intersection_y_tolerance.

  • text_tolerance (float) – Characters will be combined into words only if their distance is no larger than this value (points). Default is 3. Instead of this value, separate values can be specified for the dimensions using text_x_tolerance and text_y_tolerance.

Return type:

List

Returns:

a list of Table


GetWidgetProperties(Annot annot, Widget widget)#

Populate a Widget object with the values from a PDF form field.

Returns:

Widget object.


InsertContents(Page page, byte[] newCont, int overlay: 1)#

Insert a buffer as a new separate /Contents object of a page.

  1. Create a new stream object from buffer ‘newcont’

  2. If /Contents already is an array, then just prepend or append this object

  3. Else, create new array and put old content obj and this object into it. If the page had no /Contents before, just create a 1-item array.

Returns:

xref of the content.


Integer2Letter(int i)#

Return letter sequence string for integer i.


Integer2Roman(int i)#

Return roman numeral for integer i.


MeasureString(string text, string fontFile, string fontName, float fontSize: 11.0f, int encoding: 0)#

Calculate the width of the text.

Parameters:
  • text (string) – target text.

  • fontFile (string) – must pass font file to calculate the width. MuPDF.NET doesn’t support inner font resource, so must specify external font path.

  • fontName (string) – must specify with font file together.

  • fontSize (float) – font size. default is 11.0f.

  • encoding (int) – encoding type.


MergeRange(Document docDes, Document docSrc, int spage, int epage, int apage, int rotate, bool links, bool annots, int showProgress, GraftMap graftmap)#

Copy a range of pages (spage, epage) from a source PDF to a specified location (apage) of the target PDF. If spage > epage, the sequence of source pages is reversed.


NormalizeRotation(int rotate)#

Return normalized /Rotate value:one of 0, 90, 180, 270.


RuleDict((int, string) item)#

Make a Label from a PDF page label rule.

Parameters:

item (Tuple(int, string)) – a tuple (pno, rule) with the start page number and the rule string like <</S/D…>>.

Returns:

a label struct Label


ReadBarcodes(Page page, Rect clip = null, bool decodeEmbeddedOnly = false, BarcodeFormat type = BarcodeFormat.ALL, bool tryHarder = true, bool tryInverted = false, bool pureBarcode = false, bool multi = true, bool autoRotate = true)#

Read barcodes from page.

Parameters:
  • page (Page) – The page to read barcodes from.

  • clip (Rect) – The area to read from on the page. If null read the whole page.

  • decodeEmbeddedOnly (bool) – Decode barcodes only from embedded images in the PDF resources.

  • type (BarcodeFormat) – Barcode type to decode. Default is ALL.

  • tryHarder (bool) – Spend more time to try to find a barcode; optimize for accuracy, not speed.

  • tryInverted (bool) – Try to decode as inverted image.

  • pureBarcode (bool) – Image is a pure monochrome image of a barcode.

  • multi (bool) – Try to read multi barcodes on page.

  • autoRotate (bool) – Indicate whether the image should be automatically rotated. Rotation is supported for 90, 180 and 270 degrees.

Return type:

List

Returns:

a list of Barcode objects.


ReadBarcodes(string imageFile, Rect clip = null, BarcodeFormat type = BarcodeFormat.ALL, bool tryHarder = true, bool tryInverted = false, bool pureBarcode = false, bool multi = true, bool autoRotate = true)#

Read barcodes from an image file.

Parameters:
  • page (Page) – The page to read barcodes from.

  • clip (Rect) – The area to read from on the page. If null read the whole image.

  • decodeEmbeddedOnly (bool) – Decode barcodes only from embedded images in the PDF resources.

  • type (BarcodeFormat) – Barcode type to decode. Default is ALL.

  • tryHarder (bool) – Spend more time to try to find a barcode; optimize for accuracy, not speed.

  • tryInverted (bool) – Try to decode as inverted image.

  • pureBarcode (bool) – Image is a pure monochrome image of a barcode.

  • multi (bool) – Try to read multi barcodes on page.

  • autoRotate (bool) – Indicate whether the image should be automatically rotated. Rotation is supported for 90, 180 and 270 degrees.

Return type:

List

Returns:

a list of Barcode objects.


WriteBarcode(Page page, Rect clip, string text, BarcodeFormat type, string characterSet = null, bool disableEci = false, bool forceFitToRect = false, bool pureBarcode = false, int marginLeft = 0, int marginTop = 0, int marginRight = 0, int marginBottom = 0, int narrowBarWidth = 0)#

Write a barcode to a PDF page.

Creates a barcode at the supplied rectangle clip on the supplied Page.

Parameters:
  • page (Page) – The page to save the barcode image to.

  • clip (Rect) – The area to create the barcode on the page.

  • text (string) – Contents to write.

  • type (BarcodeFormat) – Format to encode; See: BarcodeFormat.

  • characterSet (string) – Use a specific character set for binary encoding (if supported by the selected barcode format).

  • disableEci (bool) – Don’t generate ECI segment if non-default character set is used.

  • forceFitToRect (bool) – Resize output barcode image width/height into clip region.

  • pureBarcode (bool) – Don’t put the content string into the output image.

  • marginLeft (int) – Specifies margin left in pixels.

  • marginTop (int) – Specifies margin top in pixels.

  • marginRight (int) – Specifies margin right in pixels.

  • marginBottom (int) – Specifies margin bottom in pixels.

  • narrowBarWidth (int) – The width of the narrow bar in pixels.


WriteBarcode(string imageFile, string text, BarcodeFormat type, int width = 300, int height = 300, string characterSet = null, bool disableEci = false, bool forceFitToRect = false, bool pureBarcode = false, int marginLeft = 0, int marginTop = 0, int marginRight = 0, int marginBottom = 0, int narrowBarWidth = 0)#

Write a barcode to an image file.

Parameters:
  • imageFile (string) – The image file to save the barcode image to.

  • text (string) – Contents to write.

  • type (BarcodeFormat) – Format to encode; See: BarcodeFormat.

  • width (int) – Width of image file.

  • height (int) – Height of image file.

  • characterSet (string) – Use a specific character set for binary encoding (if supported by the selected barcode format).

  • disableEci (bool) – Don’t generate ECI segment if non-default character set is used.

  • forceFitToRect (bool) – Resize output barcode image using width/height params.

  • pureBarcode (bool) – Don’t put the content string into the output image.

  • marginLeft (int) – Specifies margin left in pixels.

  • marginTop (int) – Specifies margin top in pixels.

  • marginRight (int) – Specifies margin right in pixels.

  • marginBottom (int) – Specifies margin bottom in pixels.

  • narrowBarWidth (int) – The width of the narrow bar in pixels.


GetBarcodePixmap(string text, BarcodeFormat type, int width = 0, string characterSet = null, bool disableEci = false, bool pureBarcode = false, int marginLeft = 0, int marginTop = 0, int marginRight = 0, int marginBottom = 0, int narrowBarWidth = 0)#

Creates a barcode image as a Pixmap.

Note, image height is automatically calculated by maintaining aspect ratio set by the width parameter. A width of 0 returns the a full scale representation.

Parameters:
  • text (string) – Contents to write.

  • type (BarcodeFormat) – Format to encode; See: BarcodeFormat.

  • width (int) – Width of image file.

  • characterSet (string) – Use a specific character set for binary encoding (if supported by the selected barcode format).

  • disableEci (bool) – Don’t generate ECI segment if non-default character set is used.

  • pureBarcode (bool) – Don’t put the content string into the output image.

  • marginLeft (int) – Specifies margin left in pixels.

  • marginTop (int) – Specifies margin top in pixels.

  • marginRight (int) – Specifies margin right in pixels.

  • marginBottom (int) – Specifies margin bottom in pixels.

  • narrowBarWidth (int) – The width of the narrow bar in pixels.

Returns:

Pixmap


ReplaceBytes(byte[] src, byte[] search, byte[] replace, int limit=1)#

Replaces bytes in a source buffer against the supplied search and the replacement parameters.

Parameters:
  • src (byte[]) – The source bytes buffer.

  • search (byte[]) – The bytes buffer to search against.

  • replace (byte[]) – The bytes buffer to replace with.

  • limit (int) – The number of matches to make, defaults to 1.