# txt2pdf – Convert Text Files to PDF

Version: 2.0.0

Part of DaVince Tools

Last Modified: December 13, 2001

Command Syntax

Description

New Features / Changes

Additional Information

About DaVince Tools

## Command Syntax:

(Please note that the square brackets "[" and "]" specify optional parameters; do not enter the brackets as part of the command)

txt2pdf [-1] [-c commandfile] [-f] [-i key:value [-i key:value]] [-o outputfile] [-p profile] [-r] [-s] [-?] [file1 file2 ...]

Arguments:

-1: (numeric "one") Create a PDF file for each text file specified on the command line (one to one relationship). For each TIFF file specified, a PDF file is created in the same directory with the same name except with a ".PDF" extension. A PDF file is not created if one already exists and is newer than the corresponding text file. To force a PDF file to be created, use the "-f" option. The default is to take all specified files and combine them into a single PDF file (many to one relationship). The behavior of the "-o" option changes when using the "-1" option, as described below.

-c: Process commands in the specified command file. When using this argument, files and directories can be specified via a file instead of on the command line. Click here for more info on command files.

-f: When used with the "-1" option, force overwriting an existing PDF file. By default, a PDF file may not be created with the "-1" option if the TIFF file is unchanged since the last time the PDF file was created.

-i: Specify Info dictionary attribute values like title and author of document. The following attributes are available for use:

Attribute | Description
Author | The name of the person who created the document.
Keywords | Key words associated with the document.
Subject | The subject of the document.
Title | The title of the document.

Note that the attribute names are case sensitive (first character in uppercase). This option can be specified multiple times when setting multiple dictionary attribute values. To specify an attribute along with its data, separate the two with a colon ":". You will need to enclose the string in quotes if there are spaces in the data. For example, to set the title of a document to "The Declaration of Independence", use the following parameter:

-i "Title:The Declaration of Independence"

In addition to these tags, custom tags can be used with this option; however, Acrobat Reader will not recognize them. The "CreationDate" and "Creator" attributes are automatically filled in by the program and cannot be overridden with this option.

-o: Specify the name of the PDF file to create. The ".pdf" extension should be included in the filename. If this option is not specified, the filename "text.pdf" in the current directory is assumed.

-p: Specify a profile to use in the creation of the PDF file. Profiles contain conversion information such as margin and font settings and reside in the "txt2pdf.ini" file located in either the directory where the executable file resides or the windows base directory (typically "C:\WINDOWS" for Windows 9x, "C:\WINDIR" for Windows NT). If the file is present in both directories, the file located in the windows base directory takes precedence. The default profile "default" is used when this option is not specified.

-r: When a directory is specified, search subdirectories (recursive search).

-s: Sort the filenames specified on the command line in alphanumeric order before processing them. Note that when a directory is specified on the command line, files in that directory are always sorted.

-?: A brief summary of arguments is displayed.

[file1 file2 …]: Specify one or more text files to convert. Wild card characters such as "*" and "?" may be used.

## Description:

"txt2pdf" is a command line program that converts ASCII text files to PDF (Portable Document Format) files. The key features of this program are:

- Choice of any of the base 14 fonts
- Support for 3 standard font encoding types for use with international characters
- Text re-flow support with left or full justification
- Support for legacy carriage control used in FORTRAN and COBOL generated reports
- Automatic detection of DOS, Unix and Mac text files
- PDF file compression support
- Multiple column support
- Article thread option
- Optional "green bar" background
- Automatic bookmark creation option
- Customizable headers and footers
- Header, footer and column line option
- Convert many text files to one PDF or create a PDF file for each specified text file
- Individual filenames with wildcard support and/or an entire directory may be specified for conversion
- Specify files or directories to convert either via the command line or a command file
- Large file support (1,000+ pages)
- Creates a version 1.2 PDF file with a unique file ID in trailer

The application reads text files independent of the end of line character sequence. This allows DOS, Unix and Mac text files to be read by the application. The screen output can be redirected to a file adding the DOS syntax ">filename" to the end of the command line. This can be used to redirect output to a log file. The program returns an error code of 1 when a fatal error occurs, used in batch programs to test the success of the program.

Special characters provide additional functionality during conversion. They are listed below:

Character | Behavior in Application
Horizontal Tab (HT) | Replace tab character with 1 space character
Form Feed (FF) | Skip to next page
Vertical Tab (VT) | Skip to next column. If at the last column in the page, or the page contains only 1 column, skip to next page

Other characters in column position 1 provide additional carriage control features when "legacy" mode is enabled (see below for additional information).
The program options are specified either on the command line or in a profile stored in the initialization file. Command line options are typically file related directives, whereas the profile settings are conversion related directives. Profile settings are stored in the initialization file "txt2pdf.ini located in either the executable file's directory or the Windows’ root directory (typically "C:\WINDOWS" for Windows 9x and "C:\WINNT" for Windows NT/2000). If both files are present, the file in the Windows' root directory takes precedence. The file is divided into profiles, which can be specified by name on the command line. A profile begins with the name of the profile surrounded by square brackets. An example file is shown below:

`

[book]

`
`topmargin=36`
`bottommargin=36`
`leftmargin=1`
`rightmargin=36`
`font=Times-Roman Default`
`fontsize=12`
`leading=6lpi`
`orientation=portrait`
`…`

Multiple profiles can exist in the file. The "-p" command line option determines which profile the program will use. Profile names are case sensitive. . Default profile options can be overwritten by defining them in the "_common" profile.

In addition to the default profile, the following sample profiles are defined in the txt2pdf.ini file that ships with the program:

Profile Name | Description
fixed-80x60 | Fixed font, 80 characters per line, 60 lines per page, portrait mode, line wrap at margin. Useful for printing standard text files in a fixed font that assumes 80 characters per line.
fixedbar-80x60 | Same as "fixed-80x60" with a green bar background.
legacy-80x60 | Fixed font, 80 characters per line, 60 lines per page, portrait mode, line wrap at margin. Same as "fixed-80x60", except it uses the legacy carriage control characters in column 1 (i.e "1" is form feed, "0" is double space).
legacybar-80x60 | Same as "legacy-80x60" with a green bar background.
fixed-132x60 | Fixed font, 132 characters per line, 60 lines per page, landscape mode, line wrap at margin. Useful for printing standard text files in a fixed font that assumes 132 characters per line.
fixedbar-132x60 | Same as "Fixed-132x60" with a green bar background.
legacy-132x60 | Fixed font, 132 characters per line, 60 lines per page, landscape mode, line wrap at margin. Same as "Fixed-132x60", except it uses the legacy carriage control characters in column 1 (i.e "1" is form feed, "0" is double space).
legacybar-132x60 | Same as "Legacy-132x60" with a green bar background
book-1col | Proportional font, 12 point font, word wrap with text reflow, 1 column, page numbers
book-2col | Proportional font, 12 point font, word wrap with text reflow, 2 columns, page numbers

Several option statements can appear after the profile line. These option statements have the following syntax:

option=value

Where option is the name of valid option (see below) and "value" is the value for the option. Depending on the option, "value" can be a number, a string or a Boolean value. The following values are all valid for a Boolean value:

Valid True Values | Valid False Values
True, T, On, Enable, Yes, Y | False, F, Off, Disable, No, N

These values are case insensitive (i.e. both "true" and "TRUE" are valid).

### Common Profile Settings

The following table describes options allowed in the txt2pdf.ini file that are common to all "DaVince Tools" converters (options are case insensitive):

Option | Data Type | Description
Bookmark | Bool | When true, create a bookmark for each file converted
BookmarkFilenameExtension | Bool | When true, include filename extension (usually ".tif" or ".tiff") in the bookmark name. Otherwise, ignore it. The default is false.
Compression | Bool | When true, compress the page description (image data is always compressed). The default value is false.
Description* | Description of Profile (string) | Description of profile. This description is displayed in the Windows version of "DaVince Tools"
FileMatch | String | This parameter allows setting a default file match pattern when specifying a directory to convert. This is a comma delimited list of file matching patterns. The default setting is "*.txt,*.bat,*.ini"
OpenAction | Fit, FitH, FitV, None | This parameter describes how to view the first page of the newly created PDF file when opened. Choices are "Fit" to fit entire page, "FitH" to fit the horizontal width of the page, "FitV" to fit the vertical width of the page, or "None", which defaults to the setting defined in the PDF viewer. The default setting is "None".

### Converter Specific Settings

These tables describe txt2pdf.ini settings that are unique to this converter. They are divided into the following categories:

Margin and Layout INI Options
Font INI Options
Header and Footer INI Options
Misc. INI Options

### Margin and Layout INI Options

Option | Data Type | Description
Leftmargin | Number (in points) | The left margin. The default is 36 points (.5 inches)
Rightmargin | Number (in points) | The right margin. The default is 36 points (.5 inches)
Topmargin | Number (in points) | The top margin. The default is 36 points (.5 inches)
Bottommargin | Number (in points) | The bottom margin. The default is 36 points (.5 inches)
Columnmargin | Number (in points) | The margin between columns if number of columns is greater than 1. The default is 14.4 points (.2 inches)
Columns | Number | Number of columns per page (default is 1)
Paper | Letter | legal | executive | ledger | a0 | a1 | a2 | a3 | a4 | a5 | a6 | a7 | a8 | a9 | a10 | custom w h | The paper size. The default is letter. For a custom paper size, w and h are the width and height of the custom paper size, respectively.
Orientation | Portrait | landscape | The paper orientation. The default is portrait.

### Font INI Options

Option | Data Type | Description
Leading | Number + "" | "x" | "lpi" | Leading is the vertical spacing between lines. It can be specified 3 ways. A number by itself specifies the leading as a point size. Specifying a leading value less than your font size can result in overlapping text. A number with "x" specifies the factor to apply against the font size to determine the leading value. For example, "1x" refers to a leading value equal to the font size value. A value of "2x" refers to a leading value equal to twice the font size value (double space). A number with "lpi" specifies the leading as a "lines per inch" value. Default is 1x.
Font | Fonts: Courier | Courier-Bold | Courier-BoldOblique | Courier-Oblique | Helvetica | Helvetica-Bold | Helvetica-BoldOblique | Helvetica-Oblique | Times-Roman | Times-Bold | Times-Italic | Times-BoldItalic | ZapfDingbats Encodings: Default | WinAnsiEncoding | MacRomanEncoding | PdfDocEncoding | The name of the font and optional encoding. The font name can be the name of any of the 14 base fonts for Adobe reader. The font name is case sensitive (default font is Courier). An optional encoding can be specified. The encoding name is also case sensitive (default encoding is Default).
Fontsize | Number (in points) | The size of the font, in points (there are 72 points in 1 inch). The default value is 12 points.
Wrapmode ** | truncate | margin | legacy | word | Method of wrapping lines (lines longer than the column width). Choices are: Truncate – do not show anything past margin Margin (default) – wrap line at margin to next line Legacy - use column 1 for carriage control in the following manner (used in COBOL and FORTRAN formatted output): '1' - form feed blank - single space '0' - double space '-' - triple space Word – wrap line at word to next line
Justification | Left | full | When wrap mode is set to "word" and justification is set to "full", perform full justification, which removes the ragged text edge on the right margin (default is left).

### Header and Footer INI Options

(more information is also in the "Headers and Footers" section below)

Option | Data Type | Description
Header | Bool | Display header on each page. Default is false.
Headerfont | Fonts: Courier | Courier-Bold | Courier-BoldOblique | Courier-Oblique | Helvetica | Helvetica-Bold | Helvetica-BoldOblique | Helvetica-Oblique | Times-Roman | Times-Bold | Times-Italic | Times-BoldItalic | ZapfDingbats Encodings: Default | WinAnsiEncoding | MacRomanEncoding | PdfDocEncoding | The name of the font used in the header. The font name can be the name of any of the 14 base fonts for Adobe reader. The font name is case sensitive (default font is Courier). An optional encoding can be specified. The encoding name is also case sensitive (default encoding is Default).
Headerfontsize | Number (in points) | The size of the font used in the header, in points (there are 72 points in 1 inch). The default is 12 points.
Headerstring | String | Customized header string (see below for syntax). Default is "|- &p -"
Footer | Bool | Display footer on each page. Default is false.
Footerfont | Fonts: Courier | Courier-Bold | Courier-BoldOblique | Courier-Oblique | Helvetica | Helvetica-Bold | Helvetica-BoldOblique | Helvetica-Oblique | Times-Roman | Times-Bold | Times-Italic | Times-BoldItalic | ZapfDingbats Encodings: Default | WinAnsiEncoding | MacRomanEncoding | PdfDocEncoding | The name of the font used in the footer. The font name can be the name of any of the 14 base fonts for Adobe reader. The font name is case sensitive (default font is Courier). An optional encoding can be specified. The encoding name is also case sensitive (default encoding is Default).
Footerfontsize | Number (in points) | The size of the font used in the footer, in points (there are 72 points in 1 inch). The default is 12 points.
Headerlinewidth | Number (in points) | Draws a horizontal line of the specified width between the header and the top of the text on a page. This value should be set to less than the value of the Fontsize tag. Set to zero when no line is desired (default value is zero).
Footerlinewidth | Number (in points) | Draws a horizontal line of the specified width between the footer and the bottom of the text on a page. This value should be set to less than the value of the Fontsize tag. Set to zero when no line is desired (default value is zero).
Columnlinewidth | Number (in points) | If Columns is set to 2 or more, this option draws a vertical line at the specified width between the columns. This value should be set to less than the value of the Columnmargin tag. Set to zero when no line is desired (default value is zero).
Footerstring | String | Customized footer string (see below for syntax). Default is "|- &p -"

### Misc. INI Settings

OptionDescription |  |
PageTrim | Front | back | both | none | Remove blank pages from either the front or back of the resulting PDF file, or both. Blank pages result when extra form feed characters appear at the beginning or end of the text stream. The default is none.
Articles | Bool | Create article threads for document. When combining multiple text files into 1 PDF file, an article thread is created for each file. The default is false.
BarWizard* | Bool | When true, create "green bars" on the page to give it a legacy report look. The default is false.
BarWizardOptions* | Multiple options | Define various options for the bar wizard
ParagraphWizard | Bool | When used with "wrapmode=word", this wizard removes linefeeds at the end of a line if the next lines does not contain a space or blank line. The effect of this is that the resulting PDF file will have a better text flow at the margin. The default is false.
ResetPageNumber | Bool | If combining multiple text files into a single PDF file, reset the page number to "1" between each file. This is useful if you are printing the page number in the header or footer. The default is false.

* - new in version 2.0

** - updated in version 2.0

All margin, leading, line and font size parameters are specified in "points". A point is a unit of measurement equal to 1/72 of an inch. A 1/2 inch margin would be specified as 36 points. A 12 point font with 1x leading specified would print at 72/12 or 6 lines per inch.

### Headers and Footers

Headers and footers are customizable. The single line of text can be left, centered and right justified using the vertical pipe character "|" as a tab character. Text is initially left justified. After the first "|" character, the following text is centered. Another "|" character will right justify text following the second tab. Variables can be specified to be a part of the text in the header or footer. A variable starts with the ampersand character "&", followed by a single character. Variables are case sensitive. The following variables are available for use in a header or footer:

&& | Literal ampersand character "&"
&a | Author name as specified on the command line
&A | Alias of file being processed (via command file), or name of file if no alias specified
&d | Date of file
&D | Current system date
&f | Name of file being processed
&p | Current page number
&s | Subject name as specified on the command line
&t | Time of file
&T | Current system time
&w | Title or file name if title not present on command line

The default header and footer string is "|- &p -". This places a page number in the center of the page.

Copying text to the

To copy text to the clipboard from a multi-column PDF file, use the text selection tool and press the CTRL key while dragging a rectangle around the area. You can only copy 1 column of text at a time using this method.

### Determining Characters per Line and Lines Per Page

There is no direct way of specifying the number of characters per line when using a fixed font. The number of characters per line is dependent on the width of the page, the number of columns, the margins and the size of the font. The following formula can be used to set the text font point size when a specific number of characters per line is required:

(text font size) = ((page width)- (left margin) - (right margin) - ((# of columns) -1) * (column margin)) / (chars per line) / 0.6

(text font size, page width, and margins must be specified in points)

For example:

Page Width | 612 points (8.5 inches)
Left Margin | 72 points (1 inch)
Right Margin | 72 points (1 inch)
# of chars per line | 80
# of columns | 1

(text font size) = ((612 - 72 - 72 - 0)/ 80 / .6 = 9.75

Therefore, a font size of 9.75 points is required to print 80 characters per line.

Similarly, the number of lines per page cannot be specified directly. However, a value for leading can be calculated to get the desired lines per page. The following formula can be used to determine the leading based on a desired number of lines per page (note that for calculation purposes, the header and footer lines each count as one line):

(total lines per page) = (lines per page)

if (header line width) > 0 then (total lines per page) = (total lines per page) + 1

if (footer line width) > 0 then (total lines per page) = (total lines per page) + 1

(absolute leading) = ((page height)- (top margin) - (bottom margin) - (header height) - (footer height)) / (total lines per page)

(font size, page height, and margins must be specified in points)

Note that overlapping text can occur if the leading value is less the font size. The header and footer heights are zero if they are disabled, otherwise, they are calculated as follows:

(header height) = (header font size)

(footer height) = (footer font size)

For example:

Page Height | 792 points (11.0 inches)
Top Margin | 36 points (0.5 inch)
Bottom Margin | 36 points (0.5 inch)
Desired # of lines per page | 60
Text Font Size | 12
Header Font Size | 14
Header Line Width | 2
Footer Font Size | disabled
Footer Line Width | 0

First calculate the header height:

(header height) = (14)

(total lines per page) = 60 + 1 = 61

Footer height is zero, now calculate leading value:

(absolute leading) = ((792)- (36) - (36) - (14) - (0)) / (61) = 11.574 points

### Bar Wizard Options

When the bar wizard is enabled, it creates a "green bar" background to the page. This "green bar" background is used to help ease the horizontal reading of a legacy report. This eliminates the need to purchase green bar paper since the green bars are a part of the PDF file.

The option "BarWizard" is used to enable or disable the green bar background. The option "BarWizardOptions" allows one to customize the layout of the green bar background. The following parameters can be used with this option:

BarHeight | The height of the green bar, in points. The default is 36 points (.5 inches)
Color | The color of the green bar (it does not have to be green). Must be set to either "green", "blue" or "gray". The default is "green"
LineNumbers | Boolean value. If set to true, display line numbers on the left and right sides of the bars. The default is true
LineSkip | The number of lines to skip before printing the first green bar at the top of the report. This allows for white space at the top of a report to allow for a heading. The default value is "0" (no line skip)

These parameters are listed in a comma separated list in the format of

`

param:value

`

The following statement specifies the default values for all parameters

`

BarWizardOptions=barheight:36,color:green,lineskip:0,linenumbers:true

`

The wizard utilizes the page size and its margins in determining the geometry of the bars itself.

## New Features / Changes

A list of new features and changes, along with a version history, can be found in the release notes.

## Additional Information:

Any tool that creates a PDF must create an intermediate file prior to writing the PDF file. The filename of this intermediate file begins with "tmps" and appears in the directory pointed to by the environment variable "TMP". If this environment does not exist, then the temporary file is written in the current directory. The intermediate file exists only during the execution of the program.

## About DaVince Tools:

Visit the DaVince Tools web site at http://www.davince.com for the latest version of this software and the latest documentation. DaVince Tools is shareware and software registration is urged if you find these programs useful. You can register the software on-line at http://www.davince.com.

DaVince Tools

was written in C++ using the DaVince Class Library, written by the same author as this program. The DaVince Class Library is a C++ library for developing PDF and TIFF applications. Contact the author at info@davince.com for more information on the availability of the class library.