CIB pdf toolbox 2 technical documentation

4. Usecases

4.4. Content Modify (Adding text / shapes / Barcodes / Images)

You can add text to the document, modify text, add shapes as images and more:

Property

Meaning

Type

TextOverlay

TextOverlay is a JSON-Array of JSON-Objects of new text strings added to the PDF

The keys in the JSON-Object can be:

  • Degree: degree from 0 - 360 degrees
  • FontColor: Which color it should have in HEX
  • FontName: name of the font. Please set also property FontWorkSpace, if you want to set a directory, where to lookup the font.
  • FontSize: font size
  • FontStyle: which style of the font should be used, normal, bold, italic or bolditalic
  • Opacity: 0 is transparent, 100 is full visible
  • PageSelection: A page selection on which the text should
    be added. By default it is added on all pages.

  • Position: where it should be added. You can specify this by an absolute position or by a predefined location. When you specifiy an absolute position, then you need to supply a position in X and Y from top left corner by e.g. Position: “10;20”. This is a absolute position in PDF-points (which can be positioned relative, see PageWidth and PageHeight). If you want to use mm, then you need to set e.g. Position: “10mm;20mm”. 

    If you specify a negative Y-coordinate, the Position anchor will be the bottom line, instead of the top line. If you specify a negative X-coordinate, the position will be anchored from the right page border.

    You can also specify predefined locations, which are:

    • TopLeft
    • TopCenter
    • TopRight
    • MiddleLeft
    • MiddleCenter
    • MiddleRight
    • BottomLeft
    • BottomCenter
    • BottomRight

  • PageWidth: You can define a page width, on which the
    coordinates of an absolute positioned rectangle refer to. If
    not specified, the page width in points is used.

  • PageHeight: You can define a page height, on which the
    coordinates of an absolute positioned rectangle refer to. If
    not specified, the page height in points is used.

  • Text: what text should be added, it can contain newlines, which will be interpreted as new text lines.

    The Text can contain magic keywords for which the text content will be replaced. This can be:
  • “<NumPages>”: The amount of pages in the document

  • “<Page>”: The current page number

  • “<DateTime:format>”: A datetime string, defined by a format string:

o yyyy: Year, (e.g. 2015)

o yy: Year, as 2 number (e.g. 15)

o MMMM: Full month name (e.g. December)

o MMM: Abbreviated Month Name (e.g. Dec)

o MM: Month number with leading zero(eg.04)

o dddd: Represents the full name of the day (Monday, Tuesday, etc).

o ddd: Represents the abbreviated name of the day (Mon, Tues, Wed, etc).

o dd: Represents the day of the month as a number from 01 through 31.

o HH: 24-hour clock hour, with a leading 0 (e.g. 22)

o mm: Minutes with a leading zero

o ss: Seconds with leading zero

  • Type: Type of shape, e.g. Rectangle

  • ZLevel: which zlevel it should be added. -1 means in the background, 1 in the foreground

Example:

TextOverlay= [{"FontColor": "#FF0000", "FontName": "Arial", "Degree": -45, “Text": "Demo", "FontSize": 100, "ZLevel": 1, "Opacity": 30, "Position": "MiddleCenter", "FontStyle": "Normal"}]

Creates a new Text with content “Demo” above existing pdf content with font color red, font Arial, font size 100 and normal font style. The position would be in the middle of the page and the text will be rotated by -45 degrees.

Set

TextReplace

By this you can replace existing text in a PDF. For the new text the existing font attributes are used. If the new text contains glyphs, which the old font doesn’t provide, a new font is  embedded.

Either you can specify a region (<SpecifiedRegion>), where text should be  replaced or give text-strings(<TextSearch>), which should be replaced.

The value is a JSON-array of either a <SpecifiedRegion> or a <TextSearch>.

A <SpecifiedRegion> is a JSON-object with keys:

  • PageWidth (optional): You can define a page width as JSON-number, on  which the coordinates of an absolute positioned rectangle refer to. If not specified, the page width in points is used.

  • PageHeight (optional): You can define a page height as JSON-number, on which the coordinates of an absolute positioned rectangle refer to. If not specified, the page height in points is used.

  • PageIndex: A JSON-number for the page index. Default is 0.

  • Replace: A JSON-array of specified regions as JSON-objects, where text should be replaced on this page.

  • For Defining, in which region the text should be replaced, you need either to specify a region, by X,Y, Width, Height or a dynamic region, found by specifying SearchText.

  • Each of those JSON-objects have:
    • Text: The new text

    • SearchText: A text, which is searched for and which will be  replaced.

    • SearchHitIndexes: Define, which hits of a Search, defined by  SearchText, should be replace. Please specify a ;-separated list of indexes. Default is all hits.

    • X: X coordinate from top left as JSON-string in pt, mm, or cm.

    • Y: Y coordinate from top left as JSON-string in pt, mm, or cm.

    • Width: Width as JSON-string in pt, mm, or cm.

    • Height: Height as JSON-string in pt, mm, or cm.

    • Fixed: A JSON-Boolean, which defines, if the text right to the replaced text should be moved to fit new text width or not. Default: true

A <TextSearch> is a JSON-object with keys:

  • Text: New text

  • SearchText: old text

  • PageSelection: A page selection, default all

  • Fixed: A JSON-Boolean, which defines, if the text right to the replaced text should be moved to fit new text width or not. Default: true

Set

DrawShape

DrawSpape is a JSON-Array of JSON-Objects of new shapes added to the PDF. The keys in the JSON-object can be:

  • PageSelection: on which pages this shape should be added

  • Color: Which color it should have in HEX

  • Filename: Source of an image

  • Format: Format of a Barcode, supported are DataMatrix,
    QR, Aztec, PDF417, Code39, Code93, Code128, ITF,
    Codabar

  • Position: positon of top left corner, in mm or pt. In case of
    a type Line an array of Positions, separated by semicolon,
    e.g.: "Position": "19mm;27mm;11mm;30mm"

  • Width: width of the space in mm or pt

  • Height: heigth of the space in mm or pt

  • LineCap: Setting line cap style (0-2)

  • LineJoin: Setting line join style (0-2)

  • BorderThickness: thickness of the border if the shape has border

  • Rotation: Rotation of a Image/Barcode. Supported values
    are 90, 180, 270.

  • Text: Content of a Barcode in UTF-8. ITF and Codabar use
    only the allowed text for their types.

  • Type: Type of shape, e.g. Rectangle, Line, Image, Barcode

Example:

DrawShape = [{"PageSelection": "1", "Color": "#DDFF0000", "Position": "19mm;27mm", "Width": "26mm", "Height": "6mm", "Type": "Rectangle", "BorderThickness": "3pt"}]

Create a new rectangle shape with a border with of 3 pt and color red and transparency #DD on page 1 and position 19 mm, 27 mm (from top left) and with 26 mm and height 6 mm.

DrawShape=[{'PageSelection': '1', 'Type': 'Barcode', 'Format':
'DataMatrix', 'Text': 'Example Barcode', 'Position':
'10mm;30mm','Width': '20mm', 'Height': '20mm'}]

Creates a new Barcode of Type DataMatrix on Page 1.

Set

AnnotationAdd

AnnotationAdd is a JSON-Array of JSON-Objects of new Rich Media annotations added to the PDF. The keys in the JSONobject can be:

- PageIndex: on which pages this Rich Media annotation should be                    added

- Filename: Path of the video file to be embedded.

- ThumbnailPath: Thumbnail of the Rich Media annotation.

- Position: position of top left corner, in mm or pt. Separated by                       semicolon.

- Width: width of the annotation in points or mm.

- Height: height of the annotation in points or mm.

- ActivationCondition*: PV or XA

- DeactivationCondition*: PI or XD


*According to PDF specifications.

Example:

[ {"PageIndex":5, "Filename":"D:\\\\media1.mp4",
"ThumbnailPath":"D:\\\\image46.png",
"Position":"508.4622pt;32.85032pt", "Width":"198.0682pt",
"Height":"356.5226pt", "ActivationCondition":"PV",
"DeactivationCondition":"PI"}]

Set