Command Line to Convert CSV To a PDF or XPS File (Examples)

If you have trouble running these examples see Using the Command Line and Helpful Hints For Creating a Command Line.

Although the discussion below refers to PDF, everything is similarly applicable to the XPS file type.

There is a great amount of flexibility when converting files to PDF. You can specify:

The items above are handled with the /N{sheets^range} and /U switches. Further PDF specific options are available:

The items above are specified using the /E"{^^^^PDFOptimization^PDFFromPage^PDFToPage^PDFIgnorePrintAreas^PDFIncludeDocProperties}" switch.

The first example shows how to convert a whole csv file. Next we'll show how to convert specific ranges. Finally we'll show how to specify PDF attributes.

The examples that follow are shown using csv files for the input file. To convert to XPS instead of PDF in the examples below change the /C-1 to /C-2.

Each switch shown in blue is described in detail below the examples. It is highly recommended you review each switches description before implementing the example, thereby giving you the full power of 'Convert XLS'.

Example 1 (Whole CSV File Conversion)

Below we show how to convert the whole workbook (all sheets, and all used ranges) to a single PDF file:

ConvertXLS /S"C:\in\Y.CSV" /T"C:\out\Y.PDF" /C-1 /V

To do a whole folder is quite simple:

ConvertXLS /S"C:\in\*.CSV" /T"C:\out\*.PDF" /C-1 /V

 

Example 2 (Range Specific Conversions)

Specifying ranges can be very powerful. For example if you want to only extract the 2nd column you can use "B:B" for the range. To specify a specific range, say A1 to B5 change the /N switch slightly to:

ConvertXLS /S"C:\in\Y.CSV" /F-4143 /N"^A1:B5" /T"C:\out\Y.PDF" /C-1 /V

Example 3 (Specify Specific PDF Attributes)

Here we use the /E switch to specify PDF attributes (Optimization, From Page, To Page, Ignore Print Areas, and Include Document Properties). The syntax for the /E switch is shown below:

/E"^^^^PDFOptimization^PDFFromPage^PDFToPage^PDFIgnorePrintAreas^PDFIncludeDocProperties}"

This is a caret "^" separated string. The first few items in this string are omitted above for clarity, as they are not useful in the case of converting to PDF. Omitting the /E switch from the command line will set the PDF Optimization off (not minimized file size), from and to pages will be from the beginning and to the end of the document, Print Areas will be ignored and Document Properties will not be included.

To convert a whole csv file, yet specify to optimize the PDF for web use (minimize file size), only convert pages 2-5, ignore print areas and include document properties the syntax would be:

ConvertXLS /S"C:\in\Y.CSV" /T"C:\out\Y.PDF" /C-1 /V /E"^^^^1^1^5^TRUE^TRUE"

 

Sheet: Only used when an Excel file is the input file. Use "*" or "" for all sheets. You can use names of sheets, or the numeric index. If using numeric indices, you can specify ranges of sheets (i.e. "1,4,10-20" and "4-10,9" etc.). Range and DelimChar are optional.

Range: You could optionally specify a range, say if you only wanted to convert a portion of the input file. Use the same syntax as an Excel range (e.g. A1:B10).

DelimChar: Not useful in these examples. It is for specifying the ASCII value of the delimitation character used in a CSV file. 44 for comma, 124 for Bar "|", 9 for the tab etc.

FixedWidth: Not useful in these examples. Here you can specify how to import/export a fixed width text file. Not used in this example.

UseDoubleQuotes: 0=Never, 1=Sometimes, 2=Always

UseCustomXML: TRUE to enforce custom XML attributes for the Row and Root nodes, else use FALSE

RootNode: Name of the root node. Used if bUseCustomXML is TRUE

RowNode: Name of the row node. Used if bUseCustomXML is TRUE

PDFOptimization: 0 standard, 1 = Minimize for web usage.

PDFFromPage: Page number to start the PDF or XPS output file. Leave blank or set to 0 to start at the beginning.

PDFToPage: Page to end the PDF or XPS output file. Leave blank or set to 0 to go to the end.

IgnorePrintAreas: TRUE to ignore print areas, else FALSE

PDFIncludeDocProperties: TRUE to include document properties, else FALSE

A typical string might look like the following:

/ E "0^TRUE^MyRoot^myRow^0^0^FALSE^FALSE^"

Omitting the /E switch will set the PDF Optimization off (not minimized file size), from and to pages will be from the beginning and to the end, Print Areas will be ignored and Document Properties will not be included.

Note: It is highly encouraged that you use the Verbose (/V) switch initially to see what the status of your conversion is and to help you perfect your command line. When in verbose mode the program will tell you what went wrong or right with your command line using message boxes.