Skip to main content

Helpcenter

Special Fields

Besides the basic fields there are additional special fields:

  1. Picture fields to insert pictures.

  2. Barcode fields to insert text values displayed as barcodes. DocxFactory supports an extensive list of 1D and 2D barcodes including Code39, Code128, EAN, UPC, ISBN, Databar, Postal Codes, PDF417, Data Matrix, QR Code, Maxi Code and many more.

  3. HTML/RTF fields to insert HTML or RTF values instead of plain text that can be used to add a little formatting like fonts, bolding, colors etc. all the way up to inserting mini documents with numbered or bullet lists, tables etc.

  4. Boolean fields which are a cross between fields and items. Boolean fields have items for yes and no values (which just like regular items can have text, pictures etc.). When setting the field value, the appropriate item for that value is pasted.

Special Fields Exercise
  1. Open special_fields.docx in the DocxFactory/exercises/templates/ directory (see picture below).

    image17.png
  2. To add a picture field, first insert a picture to the template. The picture acts as a place holder that will be replaced with your pictures when creating a new document.

    First click in the box in the top left corner of the document to place the cursor in the box. Then select Picture in the Insert ribbon and choose customer0.png from the DocxFactory/images/ directory (see picture below).

image18.png
  1. Size the picture.

    Right click the picture and select Size from the drop down menu. In the size dialog box make sure the Lock Aspect Ratio is selected, enter 0.94" in the height and press the Close button (see picture below).

image19.png
  1. Enter the picture field name and optional formatting.

    If you are using Microsoft Word 2007 then right click the picture and select Size from the drop down menu. Select the Alt Text tab in the Size dialog box and enter “{CustomerPic UsePlaceHolderSize}” in the Alternative text box (see picture below).

    If you are using Microsoft Word 2010 then right click the picture and select Format Picture from the drop down menu. Select Alt Text from the menu and enter the field name and optional formatting in the Description box.

    image20.png
  1. Add a border around the place holder image.

    Right click the picture and select Format Picture. In the Format Picture dialog box, select the Line Style category, select the third option from the Compound type combo box, enter 5pt Width and close the dialog box (see picture below).

    image21.png
    1. To add a barcode field, enter the field name, the barcode type and any other barcode optional formatting in squiggly brackets just like adding a basic field.

      Replace the Account under Bank Account Activity Report with “{Account UPCA ShowValue}” and increase the font size to 26 (see picture below).

    2. To add an HTML/RTF field, enter the field name and “HTML” or “RTF” in the optional formatting in squiggly brackets just like adding a basic field.

      Replace the Comments at the bottom of the document with “{Comments HTML}” (see picture below).

      image22.png

      The HTML tag styles like fonts, colors etc. are taken from document named styles for similar parts (in the Styles group in the Home ribbon). For example: “<h1>” tag uses the Heading 1 style, “<p>” tag uses the Normal style and “<strong>” tag uses the Strong style. Just like in HTML, tag styles can also be combined. For example: “<p><strong></strong></p>” combines the Normal and Strong styles.

      You can also create your own named style and apply it to an HTML tag by setting the class property to the style name. For example: create a style named MyStyle and insert the HTML “<p class="mystyle"></p>” (note that the HTML class must be in lowercase). Although HTML can also be styled with CSS styles combined in the HTML it is recommended to insert plain HTML in the program and manage the HTML styles using named styles in the template to help keep the data and design separate.

      The inserted HTML/RTF values are like paragraphs which have a line break before and after them and cannot be inserted in the middle of a line.

    3. To add a boolean field, create items for the boolean field values:

  1. <field name>_yes

  • The item name for the field yes value.

  1. <field name>_no

  • The item name for the field no value.

  1. <field name>_notset

  • The item name for the field if the value was not set.

First, select More Symbols from the Symbol drop down menu in the Insert ribbon. Make sure the “Windings 2” font is selected and insert the symbols: “”, “” and “” before the “Active” text and deselect the Italicize (see picture below).

image23.png

Then create the items below (see picture below):

  1. Active_yes

  • That marks the “” symbol.

  1. Active_no

  • That marks the “” symbol.

  1. Active_notset

  • That marks the “” symbol.

image24.png

Note: All the items for the boolean field values are optional. If there is no item for the set field value then no item is pasted.

Note: The field name and value in the boolean field item names are not case sensitive. For example: “MyField_Yes” and “myfield_yes” refer to the same field name and value.

Just like basic fields, special fields also have optional formatting.

Picture Format
  • UseImageFileSize

  • Resizes the inserted picture to the image file width and height and is the default format if no format is entered.

  • UsePlaceHolderSize

  • Keeps the place holder picture width and height.

  • UsePlaceHolderWidth

  • Keeps the place holder picture width and calculates the height according to the image file width/height ratio.

  • UsePlaceHolderHeight

  • Keeps the place holder picture height and calculates the width according to the image file width/height ratio.

Barcode Format
  • <Barcode type>

Code11

  • Code 11

Code25

  • Code 2 of 5 Standard

Code25IATA

  • Code 2 of 5 IATA

Code25Inter

  • Code 2 of 5 Interleaved

Code25Logic

  • Code 2 of 5 Data Logic

Code25Ind

  • Code 2 of 5 Industrial

ITF14

  • ITF-14

Code39

  • Code 3 of 9 (Code 39)

Code39Ext

  • Extended Code 3 of 9 (Code 39+)

Code93

  • Code 93

PZN

  • PZN

LOGMARS

  • LOGMARS

Code32

  • Code 32

Code128

  • Code 128 (automatic subset switching)

Code128B

  • Code 128 (subset B)

EAN128

  • GS1-128 (UCC.EAN-128)

EAN14

  • EAN-14

NVE18

  • NVE-18

UPCA

  • UPC-A

UPCE

  • UPC-E

EAN

  • EAN (2, 5, 8, 13)

ISBN

  • ISBN (EAN-13 with verification stage)

Codabar

  • Codabar

Pharma

  • Pharmacode

Pharma2Track

  • Pharmacode 2 Track

Plessey

  • Plessey Code

MSIPlessey

  • MSI Plessey

Telepen

  • Telepen Alpha

TelepenNum

  • Telepen Numeric

RSS14

  • GS1 Databar-14

RSS14Stack

  • GS1 Databar-14 Stacked

RSS14StackOmni

  • GS1 Databar-14 Stacked Omni Directional

RSSLtd

  • GS1 Databar Limited

RSSExp

  • GS1 Databar Extended

RSSExpStack

  • GS1 Databar Expanded Stacked

Channel

  • Channel Code

FIM

  • FIM

Flat

  • Flattermarken

DAFT

  • DAFT Code

PostNet

  • PostNet

PLANET

  • PLANET

OneCode

  • USPS OneCode

RM4SCC

  • Royal Mail 4 State (RM4SCC)

DPLeit

  • Deutshe Post Leitcode

DPIdent

  • Deutshe Post Identcode

AUSPost

  • Australia Post Standard Customer

AUSReply

  • Australia Post Reply Paid

AUSRoute

  • Australia Post Routing

AUSRedirect

  • Australia Post Redirection

KIX

  • Dutch Post KIX Code

JapanPost

  • Japanese Postal Code

KoreaPost

  • Korea Post

Code16K

  • Code 16K

Code49

  • Code 49

PDF417

  • PDF417

PDF417Trunc

  • PDF417 Truncated

MicroPDF

  • MicroPDF417

DataMatrix

  • Data Matrix

QRCode

  • QR Code

MicroQR

  • Micro QR Code

MaxiCode

  • Maxicode

Aztec

  • Aztec Code

AzRune

  • Aztec Runes

CodeOne

  • Code One

GridMatrix

  • Grid Matrix

HIBCCode39

  • HIBC Code 39

HIBCCode128

  • HIBC Code 128

HIBCPDF417

  • HIBC PDF417

HIBCMicroPDF

  • HIBC MicroPDF417

HIBCDataMatrix

  • HIBC Data Matrix

HIBCQRCode

  • HIBC QR Code

HIBCAztec

  • HIBC Aztec Code

CCEAN

  • Composite Symbol with EAN Linear Component

CCEAN128

  • Composite Symbol with GS1-128 Linear Component

CCUPCA

  • Composite Symbol with UPC-A Linear Component

CCUPCE

  • Composite Symbol with UPC-E Linear Component

CCRSS14

  • Composite Symbol with GS1 Databar-14 Linear Component

CCRSS14Stack

  • Composite Symbol with GS1 Databar-14 Stacked

CCRSS14StackOmni

  • Composite Symbol with GS1 Databar-14 Stacked Omni

CCRSSLtd

  • Composite Symbol with GS1 Databar Limited Component

CCRSSExp

  • Composite Symbol with GS1 Databar Extended Component

CCRSSExpStack

  • Composite Symbol with GS1 Databar Expanded Stacked

  • Scale: <scale>

  • Used to set the barcode print size. The barcode size is multiplied by the scale, where the height of the barcode in scale 1 is equal to the height of a paragraph in font size 30. The default scale, if no scale is entered is calculated according to the font size of the barcode field definition in the template, where font size 30 is equal to scale 1.

  • Height: <height>

  • The height for 1 dimensional barcodes. The default height, if no height is entered is 50.

  • ShowValue

  • Shows the barcode text value.

  • Angle: <angle>

  • Turns the barcode in an angle.

  • Font: <name>

  • The show value font name. The default font, if no font is entered is the font “Calibri”.

  • FontSize: <size>

  • The show value font size. The default font size, if no font size is entered is 11.

  • FGColor: <color>

  • The barcode foreground color (bars and text color). The default foreground color, if no foreground color is entered is the foreground color of the barcode field definition in the template.

  • BGColor: <color>

  • The barcode background color. The default background color, if no background color is entered is the background color (or table cell shade) of the barcode field definition in the template.

  • WhiteSpace: <width>

  • The whitespace width on the barcode sides.

  • Border: <width>

  • The barcode border width.

  • Bind

  • Draws a binding border with bars on the top and bottom of the barcode.

  • Box

  • Draws a box border around the barcode.

Barcode Specific Formats
Code39 and Code39Ext
  • CheckDigit

  • Adds a modulo 10 check digit.

UPCA, UPCE, EAN, ISBN and CCEAN

Note: An EAN2 or EAN5 barcode can be added to the right of the barcode by adding “+<value>” with the EAN value to the barcode value. For example: “1234567890+12345”.

MSIPlessey
  • CheckDigit: <option number>

  • Adds a check digit. Options:

    1. Modulo 10

    2. Modulo 10 & Modulo 10

    3. Modulo 11

    4. Modulo 11 & Modulo 11

RSSExp

Notes: GS1 Application Identifiers (AIs) should be entered using [square brackets] notation. These will be converted to (round brackets) when the value is shown.

RSSExpStack and CCRSSExpStack
  • Cols: <cols>

  • Number of columns from 1 to 9.

Notes: GS1 Application Identifiers (AIs) should be entered using [square brackets] notation. These will be converted to (round brackets) when the value is shown.

Channel
  • Channels: <channels>

  • Number of channels from 3 to 8.

OneCode

Notes: Input data consists of a 20 digit tracking code, followed by a dash (“-“), followed by a delivery point zip-code which can be 0, 5, 9 or 11 digits in length.

Code16K and Code49
  • GS1

  • GS1 input mode.

PDF417, PDF417Trunc and HIBCPDF417
  • Cols: <cols>

  • Number of columns from 1 to 20.

  • Security: <n>

  • Error correction value from 0 to 8. Number of code words equals 2(n + 1).

MicroPDF and HIBCMicroPDF
  • Cols: <cols>

  • Number of columns from 1 to 4.

DataMatrix
  • Size: <option number>

  • Resolution size. Options:

  1. 10 x 10

  2. 12 x 12

  3. 14 x 14

  4. 16 x 16

  5. 18 x 18

  6. 20 x 20

  7. 22 x 22

  8. 24 x 24

  9. 26 x 26

  10. 32 x 32

  11. 36 x 36

  12. 40 x 40

  13. 44 x 44

  14. 48 x 48

  15. 52 x 52

  1. 64 x 64

  2. 72 x 72

  3. 80 x 80

  4. 88 x 88

  5. 96 x 96

  6. 104 x 104

  7. 120 x 120

  8. 132 x 132

  9. 144 x 144

  10. 8 x 18

  11. 8 x 32

  12. 12 x 26

  13. 12 x 36

  14. 16 x 36

  15. 16 x 48

  • Square

  • Adjusts the size using only square sizes.

  • GS1

  • GS1 input mode.

Note: If no size is entered or the data does not fit in the entered size then the size is adjusted automatically.

QRCode
  • Size: <option number>

  • Resolution size. Options:

  1. 21 x 21

  2. 25 x 25

  3. 29 x 29

  4. 33 x 33

  5. 37 x 37

  6. 41 x 41

  7. 45 x 45

  8. 49 x 49

  9. 53 x 53

  10. 57 x 57

  11. 61 x 61

  12. 65 x 65

  13. 69 x 69

  14. 73 x 73

  15. 77 x 77

  16. 81 x 81

  17. 85 x 85

  18. 89 x 89

  19. 93 x 93

  20. 97 x 97

  1. 101 x 101

  2. 105 x 105

  3. 109 x 109

  4. 113 x 113

  5. 117 x 117

  6. 121 x 121

  7. 125 x 125

  8. 129 x 129

  9. 133 x 133

  10. 137 x 137

  11. 141 x 141

  12. 145 x 145

  13. 149 x 149

  14. 153 x 153

  15. 157 x 157

  16. 161 x 161

  17. 165 x 165

  18. 169 x 169

  19. 173 x 173

  20. 177 x 177

  • Security: <option number>

  • Error correction. Options:

  1. Approx. 20% of symbol.

  2. Approx. 37% of symbol.

  3. Approx. 55% of symbol.

  4. Approx. 65% of symbol.

Note: If no size is entered or the data does not fit in the entered size then the size is adjusted automatically.

MicroQR
  • Cols: <cols>

  • Number of columns from 1 to 4.

MaxiCode
  • Mode: <mode>

  • Maxicode mode from 2 to 6. The default mode, if no mode is entered is mode 4.

Note: Modes 2 and 3 require a primary and secondary value. The value is divided into a primary and secondary value by a newline character (“\n”). The primary value required format is 9 digits for mode 2 and 6 alpha numeric characters for mode 3 of post code data (the remaining characters should be filled with spaces), followed by a 3 digit country code (ISO3166), followed by a 3 digit service code depending on your parcel courier.

Aztec
  • Size: <option number>

  • Resolution size. Options:

  1. 15 x 15

  2. 19 x 19

  3. 23 x 23

  4. 27 x 27

  5. 19 x 19

  6. 23 x 23

  7. 27 x 27

  8. 31 x 31

  9. 37 x 37

  10. 41 x 41

  11. 45 x 45

  12. 49 x 49

  13. 53 x 53

  14. 57 x 57

  15. 61 x 61

  16. 67 x 67

  17. 71 x 71

  18. 75 x 75

  1. 79 x 79

  2. 83 x 83

  3. 87 x 87

  4. 91 x 91

  5. 95 x 95

  6. 101 x 101

  7. 105 x 105

  8. 109 x 109

  9. 113 x 113

  10. 117 x 117

  11. 121 x 121

  12. 125 x 125

  13. 131 x 131

  14. 135 x 135

  15. 139 x 139

  16. 143 x 143

  17. 147 x 147

  18. 151 x 151

  • Security: <option number>

  • Error correction. Options:

    1. >10% + 3 code words.

    2. >23% + 3 code words.

    3. >36% + 3 code words.

    4. >50% + 3 code words.

  • GS1

  • GS1 input mode.

Note: If no size is entered or the data does not fit in the entered size then the size is adjusted automatically.

CodeOne
  • Size: <option number>

  • Resolution size. Options:

  1. 16 x 18

  2. 22 x 22

  3. 28 x 32

  4. 40 x 42

  5. 52 x 54

  6. 70 x 76

  7. 104 x 98

  8. 148 x 134

  9. 8X height

  10. 16X height

  • GS1

  • GS1 input mode.

Note: If no size is entered or the data does not fit in the entered size then the size is adjusted automatically.

GridMatrix
  • Size: <option number>

  • Resolution size. Options:

  1. 18 x 18

  2. 30 x 30

  3. 42 x 42

  4. 54 x 54

  5. 66 x 66

  6. 78 x 78

  7. 90 x 90

  8. 102 x 102

  9. 114 x 114

  10. 126 x 126

  11. 138 x 138

  12. 150 x 150

  13. 162 x 162

  • Security: <option number>

  • Error correction. Options:

  1. Approx. 10% of symbol.

  2. Approx. 20% of symbol.

  3. Approx. 30% of symbol.

  4. Approx. 40% of symbol.

  5. Approx. 50% of symbol.

Note: If no size is entered or the data does not fit in the entered size then the size is adjusted automatically.

Composite Barcodes
  • Mode: <option number>

  • The 2D component of the composite symbol. Options:

  1. CC-A

  2. CC-B

  3. CC-C

Note: Composite barcodes require a primary and secondary value for the linear and 2D component respectively. The value is divided into a primary and secondary value by a newline character (“\n”).

HTML/RTF Format
  • HTML

  • For inserting HTML values.

  • RTF

  • For inserting RTF values.

Boolean Format

Booleans fields have no additional optional formatting.

Note: All optional formatting are not case sensitive. For example: “HTML” and “html” refer to the same optional formatting.

  1. Compile the template.

  2. Create the .DOCX file.

    Copy and run the code below.

from docxfactory import WordProcessingMerger

from datetime import datetime

try:

merger = WordProcessingMerger.get_instance()

start_time = datetime.now()

merger.load("/opt/DocxFactory/exercises/templates/special_fields.dfw")

merger.set_clipboard_value("Account", "Account", "12345678901")

merger.set_clipboard_value("Account", "Active", "no")

merger.set_clipboard_value("Account", "CustomerPic",

"/opt/DocxFactory/exercises/images/customer1.png")

merger.set_clipboard_value("Account", "Comments",

"<h3>An unordered list:</h3>" +

"<ul>" +

"<li>List item</li>" +

"<li>List item</li>" +

"<li>List item</li>" +

"</ul>")

merger.paste("Account")

merger.save("/tmp/special_fields.docx")

print("Completed (in",

round((datetime.now() - start_time).total_seconds(), 3),

"seconds).")

exception Exception as e:

print(str(e))

The code sets the value for all the special field types:

  1. Picture fields are set with a string value of the image file path.

Note: Relative paths are resolved relative to the current working directory. For example: “dir/image.jpg” is resolved to “[working directory]/dir/image.png”.

Note: The picture inserted as a place holder is only used to define the picture field in the template. In fact, the picture is removed when compiling the template, leaving the place holder blank. If the picture field is not set when creating a new document then no picture is inserted in the place holder and the picture field remains blank.

Note: DocxFactory does not support images in compatibility mode on purpose because of their many drawbacks, most notably .DOCX files with even a hundred images may take many minutes and even more to open. To find if the .DOCX file is in compatibility mode, check if the title bar displays [Compatibility Mode]. To remove compatibility mode, select Save as from the menu, Word Document and in the Save as dialog-box make sure the Maintain compatibility with Word 97-2003 checkbox is not selected.

Note: In most cases, the image files are saved inside the .DOCX file (also called embedded images) but it is also possible to save only the image files URL instead (also called linked images) to reduce the .DOCX file size but if the .DOCX file is opened on a network with no access to the image files then the images will not be displayed. DocxFactory uses embedded images by default. To use linked images pass an image file “file://<host>/<directory>/<file>” URL instead. It is recommended to use embedded images. Use linked images only when necessary.

  1. Barcode fields are set with a string value to display as a barcode.

  2. HTML/RTF field are set with a string value of the HTML or RTF.

Note: The HTML “<html><body></body></html>” tags (including DTD and other headers) or the RTF “{\rtf1\ansi\deff0}” definitions are optional. If they are missing then DocxFactory will add them automatically.

Note: Similar to picture fields, DocxFactory automatically embeds <img src=“<file>”> tag image files into the document so the document can be sent out and the images can still be displayed. To force DocxFactory to use linked images, enter an “http://<host>/<directory>/<file>” or “file://<host>/<directory>/<file>” URL.

  1. Boolean fields are set with a number value of 0 or string value of “0”, “0.0”, “no”, “false” for no and all other values for yes.

  1. Open the created .DOCX file (see picture below).

    image25.png
Barcodes 1 Exercise

The following exercise creates a document with sample barcodes.

  1. Open barcodes_1.docx in the DocxFactory/exercises/templates/ directory (see picture below).

    image26.png
  2. Compile the template.

  3. Create the .DOCX file.

    Copy and run the code below.

from docxfactory import WordProcessingMerger

from datetime import datetime

try:

merger = WordProcessingMerger.get_instance()

start_time = datetime.now()

merger.load("/opt/DocxFactory/exercises/templates/barcodes_1.dfw")

merger.set_clipboard_value("Main", "MyField1", "12345678901")

merger.set_clipboard_value("Main", "MyField2", "12345678901")

merger.set_clipboard_value("Main", "MyField3", "12345678901")

merger.set_clipboard_value("Main", "MyField4", "12345678901")

merger.set_clipboard_value("Main", "MyField5", "Hello World")

merger.set_clipboard_value("Main", "MyField6", "Hello World")

merger.set_clipboard_value("Main", "MyField7", "Hello World")

merger.set_clipboard_value("Main", "MyField8", "Hello World")

merger.set_clipboard_value("Main", "MyField9", "Hello World")

merger.paste("Main")

merger.save("/tmp/barcodes_1.docx")

print("Completed (in",

round((datetime.now() - start_time).total_seconds(), 3),

"seconds).")

exception Exception as e:

print(str(e))

  1. Open the created .DOCX file (see picture below).

    image27.png
Barcodes 2 Exercise

The following exercise creates a document for printing stickers.

  1. Open barcodes_2.docx in the DocxFactory/exercises/templates/ directory.

    Open the Bookmark dialog box and go through and highlight the bookmarks (see picture below).

    image28.png

    The template has a Row and Cell items like a table and you can paste the Row and Cell items like you would for creating a table. There is also a Main top level item because if the Row item was a top level item then it would start in a new page every time it was pasted and a dummy item which is never pasted and its only purpose is to help differentiate between the Row and Main items.

  2. Draw a rounded rectangle over the first Cell item.

    Place the cursor before “{Desc}” field. Select rounded rectangle from the Shapes drop down menu in the Insert ribbon and draw a rounded rectangle over the first cell item (see picture below).

    image29.png
  3. Position the rounded rectangle.

    Right click the rounded rectangle and select Format AutoShape from the drop down menu. Click the Advanced button in the Layout tab. Set Horizontal Alignment: Left relative to: Left Margin and Vertical Alignment: Top relative to: Top Margin in the Picture Position tab and Select Layout in table cell (see picture below).

    image30.png
  4. Set the rounded rectangle size.

    Select the Size tab in the Format AutoShape dialog box. Set the Height to Absolute: 1.6" and Width to Absolute: 2.05" (see picture below).

    image31.png
  5. Remove the rounded rectangle fill color and keep only the shape outline.

    Select No Fill in the Fill drop down menu in the Format ribbon (see picture below).

    image32.png
  6. Repeat steps 2 to 5 for the second and third Cell items.

  7. Unselect the Allow row to break across pages for the Row item so either the entire row fits in the page or the row is moved to the next page.

    Select the Row bookmark from the Bookmarks dialog box. Right click the highlighted area and select Table Properties from the drop down menu and unselect the Allow row to break across pages in the Row tab (see picture below).

    image33.png
  8. Remove the page bottom margin. Word adds a paragraph after a table. If the table fills the page then the paragraph will overflow adding an empty page. You can remove or shorten the page bottom margin to make space for the paragraph.

    Select the Custom Margins from the Margins drop down menu in the Page Layout ribbon. Set the Bottom Margins: 0" in the Margins tab (see picture below).

    image34.png
    1. Compile the template.

    2. Create the .DOCX file.

      Copy and run the code below.

from docxfactory import WordProcessingMerger

from datetime import datetime

try:

merger = WordProcessingMerger.get_instance()

start_time = datetime.now()

merger.load("/opt/DocxFactory/exercises/templates/barcodes_2.dfw")

merger.paste("Main")

for i in range(20):

j = (i + 1) % 3

if (j == 0) j = 3

if (j == 1)

merger.paste("Row")

merger.set_clipboard_value("", "Desc", "Hello World")

merger.set_clipboard_value("", "PartNum", "12345678901")

merger.paste("Cell" + str(j))

merger.paste("Main")

merger.save("/tmp/barcodes_2.docx")

print("Completed (in",

round((datetime.now() - start_time).total_seconds(), 3),

"seconds).")

exception Exception as e:

print(str(e))

  1. Open the created .DOCX file (see picture below).

    image35.png