.NET Interface

The .NET Interface makes it possible for the XSL Formatter V3.4 to function through .NET applications developed using Visual Basic.NET, Visual C#.NET and so on.

The operation of the .NET Interface has been tried and tested in the following .NET environments:

Component Registration

The XSLFormatter .NET component is not registered automatically to the global assembly cache (GAC). It is necessary to resolve the path either by putting the .NET component in the current folder of the application, or by creating an application configuration file.

.NET Component File Name for .NET Framework 1.0 XfoDotNetCtl.dll
for .NET Framework 1.1 XfoDotNetCtl11.dll

The initialization and the termination are necessary to use the DLL. That is, before using the DLL, Initialize method must be called. After using the DLL, Terminate method must be called.

Classes

The following classes are contained in the .NET component.

Name Functions
XfoObj The class of XSL Formatter V3.4 itself. This class implements IDisposable interface. When exiting XfoObj class object, please be sure to call Dispose method in order to release the resource.

Example for C#

XfoDotNetCtl.XfoObj.Initialize();
XfoDotNetCtl.XfoObj obj = new XfoDotNetCtl.XfoObj();
try {
  // some process
} finally {
  obj.Dispose();
  XfoDotNetCtl.XfoObj.Terminate();
}
XfoException XSL Formatter V3.4 exception class. Throws the execute method of XfoObj class.

Properties

XfoException Class includes the following properties.

Name Type R/W Functions
ErrorLevel Int32 R Indicates the error level of the error that occurred during the formatting process.
1. Information
2. Warning
3. Recoverable Error
4. Fatal Error
ErrorCode Int32 R Indicates the error code of the error that occurred during the formatting process. Zero means no error. Non-zero indicates any error occurred.

XfoObj Class includes the following properties.

Name Type R/W Functions
DocumentURI String R/W Specifies the URI of the XML documents you will format.
  • If it is omitted or "@STDIN" is specified, XML documents are loaded from stdin.
The documents loaded from stdin are supposed to be FO files.
StylesheetURI String R/W Specifies the URI of XSL stylesheets for formatting.
  • If the specified XML document is FO, or the XML file contains the processing instruction <?xml-stylesheet ...?> and the XSL stylesheet is specified, this setting is ignored.
  • Otherwise if there is no setting for this property, an error occurs.
OptionFileURI String R/W Specifies the URI of the XML-format Option Setting File which describes XSL Formatter V3.4 options.
OptionFileCount Int32 R Counts the number of Option Setting Files you specified.
PrinterName String R/W Specifies the output format or the printer name to output.
  • When a printer name is specified, the formatted result is outputted to that printer.
  • When "@STDPRN" is specified, the formatted result is outputted to the currently used printer.
  • When "@PDF" is specified, the formatted result is outputted to PDF.
  • When "@SVG" is specified, the formatted result is outputted to SVG.
  • When "@TEXT" is specified, the formatted result is outputted to a text format file.
When omitted, "@PDF" is the default. Please refer to "How to specify the printer name" for details.
Please refer to "PDF Output" for the PDF output information.
Please refer to "SVG Output" for the SVG output information.
Please refer to "Text Output" for the text output information.
@TEXT is not effective with XSL Formatter V3.4 Lite.
PrinterSettingURI String R/W Specifies the URI of the Printer Setting File. Please refer to "How to create a Printer Setting File".
OutputFilePath String R/W Specifies the output file path of the formatted result. When the printer is specified as an output format by PrinterName, a printing result is saved to the specified file by the printer driver. When output format other than a printer is specified, it is saved as the specified file with the specified output format. When omitted, or when "@STDOUT" is specified, it goes to standard output.
OutputFOPath String R/W Specifies the output FO file as the result of XSLT when the input files are an XML document and XSL stylesheet.
  • If the input file is FO, no file is outputted.
  • When "@STDOUT" is specified, it is considered as stdout.
If the setting is omitted, nothing outputs.
ExternalXSLT String R/W Command-line of External XSLT Processor. If this is omitted, default MSXML4 or MSXML3 will be used. For example:
xslt %param -o %3 %1 %2
These meanings are as follows.
  • %1 : XML document
  • %2 : XSL stylesheet
  • %3 : XSLT output file
  • %param : xsl:param
%1 to %3 are used to express only parameter positions. Do not replace them with actual file names. In case you use XSL:param for external XSLT processor, set the parameter in XSLTParamFormat and SetXSLTParam.
XSLTParamFormat String R/W Specifies the parameter format of xsl:param when using External XSLT Processor. For example:
-p %p %v
These meanings are as follows.
  • %p : Parameter Name
  • %v : Parameter Value
BaseURI String R/W Specifies the default base URI.
FormattedPages Int32 R Get the formatted total pages.
MultiVolume Boolean R/W Specifies to output PDF in separate volume. The error occurs when FO doesn't include the axf:output-volume-info extension property. When the value 'false' is specified, the StartVolume/EndVolume parameter is invalid, instead the parameter StartPage/EndPage is effective. When the value 'true' is specified, the parameter StartPage/EndPage is invalid, instead the parameter StartVolume/EndVolumeis effective.
StartVolume
EndVolume
Int32 R/W Effective when MultiVolume=true is specified. Specifies the start and the end of separate volume to output. If the setting of start for separate volume is omitted or the value 'true' is less than 0, the start volume is accounted as the first volume. If the setting of start for separate volume is omitted or the value 'true' is more than actual number of separate volume, the end volume is accounted as the last volume. If the setting is conflicted, an error occurs. (e.g. StartVolume=5 EndVolume=3)
TotalVolumeCount Int32 R Gets the number of all the separate volumes when outputting PDF to multiple separate volumes.
OutputVolumeCount Int32 R Gets the number of the actual separate volumes when outputting PDF to multiple separate volumes.
StartPage
EndPage
Int32 R/W Specifies the start page number or the end page number of document to output. If the start page is omitted or the specified value is 0 or less, the start page is considered from the first page. If the end page is omitted or the specified value exceeds the actual number of pages, the end page is considered as the last page. If the setting is inconsistent, (for example, StartPage=5 EndPage=3) an error occurs.
ExitLevel Int32 R/W Specifies error level to abort the formatting process. XSL Formatter V3.4 will stop formatting when the detected error level is equal to ExitLevel property or higher. The default value is 2 (Warning). Thus if an error occurred and error level is 2 (Warning) or higher, the formatting process will be aborted. Legal values are from 1 to 4. When the value of 5 or higher is specified, it is considered to be the value of 4. If a error-level:4 (fatal error) occurs, the formatting process will be aborted unconditionally. The ExitLevel does not cause an error message to be displayed no matter what value may be specified for this property.
ErrorLevel Int32 R Indicates the error level that occurred during the formatting process.
1. Information
2. Warning
3. Recoverable Error
4. Fatal Error
ErrorCode Int32 R Indicates the error code of the error that occurred during the formatting process. Zero means no error. Non-zero indicates any error occurred.
ErrorMessage String R Indicates the error message of the error that occurred during the formatting process.
ErrorStreamType Int32 R/W Outputs the error message to standard output or to standard error when the error level is less than the specified error level allowed while formatting. The error message is not outputted in default.
0. Not output
1. Standard output
2. Standard error output
XmlDomDocument System.Xml.XmlDocument W Specifies the target XML document by the System.Xml.XmlDocument class object.
XmlDomStylesheet System.Xml.XmlDocument W Specifies the target XSL stylesheet by the System.Xml.XmlDocument class object.

Properties - PDF Settings

Name Type R/W Functions
PdfVersion Int32 R/W Specifies PDF version:
0. PDF version 1.3
1. PDF version 1.4
2. PDF version 1.5
PdfEncryptLevel Int32 R/W Specifies the key length when encrypting the PDF file during outputting. The key length can be specified as follows: (Note: This parameter is effective only when you specify PDF1.4 or later with PDF version (PdfVersion).)
0. 40-bit
1. 128-bit
PdfUserPassword String W Specifies the user password for PDF. The password must be within 32 bytes.
PdfMasterPassword String W Specifies the master password for PDF. The password must be within 32 bytes.
PdfNoPrinting Boolean R/W Prohibits printing the PDF file.
PdfNoChanging Boolean R/W Prohibits making changes to the PDF file.
PdfNoContentCopying Boolean R/W Prohibits copying the content of the PDF file.
PdfNoAddingOrChangingComments Boolean R/W Prohibits adding comments and form fields to the PDF file.
PdfNoFillForm Boolean R/W Prohibits filling in of form fields and signing of the PDF file. This parameter is effective only when you specify PDF1.4 or later for the PDF version (PdfVersion). In order to make this parameter effective, the setting of the other parameter may be required. See also the 'PDF Reference' from Adobe Systems Incorporated for more details.
PdfNoAccessibility Boolean R/W Prohibits text access for screen reader devices of the PDF file. This parameter is effective only when you specify 1.4 or later for the PDF version (PdfVersion).
PdfNoAssembleDoc Boolean R/W Prohibits inserting, deleting and rotating the PDF pages. This parameter is effective only when you specify 1.4 or later for the PDF version (PdfVersion).
PdfEmbedAllFonts Boolean R/W Embeds all embeddable fonts in the PDF.
PdfEmbedAllFontsEx Int32 R/W Specifies whether or not to embed all TrueType fonts and Type1 fonts used in the file of the formatted result into PDF. However, even if all fonts are specified to embed, the font forbidden embedding or the font which is not able to be embedded to PDF cannot be embedded.
0. Specified font
1. All fonts excluding Base14 font
2. All fonts including Base14 font
PdfEmbedFonts String R/W Embeds the specified font in the created PDF. If you want to specify plural fonts, put commas between each fonts.
PdfErrorOnEmbedFault Boolean R/W When true is specified, an error is issued when font embedding fails.
PdfErrorOnMissingGlyph Boolean R/W When true is specified, an error is issued when there is a missing glyph.
PdfPrintingAllowed Int32 R/W Specifies whether and how to permit printing of PDF. This parameter is effective only when you specify 1.4 or later with PDF version (PdfVersion).
0. Not Allowed
1. Low Resolution Printing
2. High Resolution Printing
PdfImageCompression Int32 R/W When a color image format cannot be stored directly in the PDF, the image is stored after being transformed into a bitmap format which is compatible with PDF. Use one of the following values to specify the compression method of the data stored in a PDF file. When Auto is selected, the process is automatically done and creates the image data according to the setting of PdfJPEGQuality and PdfRasterizeResolution. Whichever has the smaller compressed size, JPEG or ZLIB, is selected. These are the settings for color images. Specify PdfGrayscaleImageCompression for grayscale images and PdfMonochromeImageCompression for monochrome images.
0. Auto
1. JPEG compression
2. ZLIB compression
3. JPEG2000 compression (it is effective only when PdfVersion is PDF1.5 or higher)
PdfJPEGQuality Int32 R/W For color image formats that can not be stored directly in the PDF, the image quality can be specified by a numerical value within the range of 1-100 when JPEG compression is specified for the PdfImageCompression. The quality becomes higher in proportion to the increase in the number; however the file size also becomes larger. This is the setting for color images. Specify PdfGrayscaleJPEGQuality for grayscale images.
CAUTION: This is not for changing the quality of a JPEG formatted image.
PdfPutImageColorProfile Boolean R/W Specifies whether to embed in the PDF the color profile of the color image that will be embedded.
PdfImageDownSampling Int32 R/W Specifies either of the following methods to downsample the color image in a PDF. When a value other than None is specified, an image that has a resolution larger than the one specified by PdfImageDownSamplingDPI will be downsampled to the resolution specified by PdfImageDownSamplingTarget. These are the settings for color images. Specify PdfGrayscaleImageDownSampling for grayscale images, and PdfMonochromeImageDownSampling for monochrome images.
0. None
1. Average
2. Bicubic
3. Subsampling
PdfImageDownSamplingTarget Int32 R/W Sets the target resolution when a color image is downsampled.
PdfImageDownSamplingDPI Int32 R/W Sets the resolution for which a color image is to be downsampled.
PdfGrayscaleImageCompression Int32 R/W When a grayscale image format cannot be stored directly in the PDF, the image is stored after being transformed into a bitmap format which is compatible with PDF. Use one of the following values to specify the compression method of the data stored in a PDF file. When Auto is selected, the process is automatically done and creates the image data according to the setting of PdfGrayscaleJPEGQuality and PdfRasterizeResolution. Whichever has the smaller compressed size, JPEG or ZLIB, is selected. These are the settings for grayscale images. Specify PdfImageCompression for color images, and PdfMonochromeImageCompression for monochrome images.
0. Auto
1. JPEG compression
2. ZLIB compression
3. JPEG2000 compression (it is effective only when PdfVersion is PDF1.5 or higher)
PdfGrayscaleJPEGQuality Int32 R/W For grayscale image formats that cannot be stored directly in the PDF, the image quality can be specified by a numerical value within the range of 1-100 when JPEG compression is specified by PdfGrayscaleImageCompression. The quality becomes higher in proportion to the increase in the number; however the file size also becomes larger. Specify PdfJPEGQuality for color images.
CAUTION: This is not for changing the quality of a JPEG formatted image.
PdfGrayscaleImageDownSampling Int32 R/W Specifies either of the following methods to downsample grayscale images in a PDF. When a value other than None is specified, an image that has a resolution larger than the one specified by PdfGrayscaleImageDownSamplingDPI will be downsampled to the resolution specified by PdfGrayscaleImageDownSamplingTarget. These are the settings for grayscale images. Specify PdfImageDownSampling for color images, and PdfMonochromeImageDownSampling for monochrome images.
0. None
1. Average
2. Bicubic
3. Subsampling
PdfGrayscaleImageDownSamplingTarget Int32 R/W Sets the target resolution when a grayscale image is downsampled.
PdfGrayscaleImageDownSamplingDPI Int32 R/W Sets the resolution for which grayscale image is to be downsampled.
PdfMonochromeImageCompression Int32 R/W When monochrome image formats cannot be stored directly in the PDF, the image is stored after being transformed into a bitmap format which is compatible with PDF. Use one of the following values to specify the compression method of the data stored in a PDF file. These are the settings for monochrome images. Specify PdfGrayscaleImageCompression for grayscale images, and PdfImageCompression for color images.
0. None
1. CCITT Group4
2. CCITT Group3
3. Run Length compression
4. ZLIB compression
PdfMonochromeImageDownSampling Int32 R/W Specifies either of the following methods to downsample monochrome images in a PDF. When a value other than None is specified, an image that has a resolution larger than the one specified by PdfMonochromeImageDownSamplingDPI will be downsampled into the resolution specified by PdfMonochromeImageDownSamplingTarget. These are the settings for monochrome images. Specify PdfImageDownSampling for color images, and PdfGrayscaleImageDownSampling for grayscale images.
0. None
1. Average
2. Bicubic
3. Subsampling
PdfMonochromeImageDownSamplingTarget Int32 R/W Sets the target resolution when a monochrome image is downsampled.
PdfMonochromeImageDownSamplingDPI Int32 R/W Sets resolution for which monochrome image is to be downsampled.
PdfLinearize Boolean R/W Specifies whether to output linearized PDF or not. no-LT
PdfCompressContentStream Boolean R/W Specifies whether the text and the line art in PDF are compressed in order to make the size of PDF smaller or not.
PdfUseLaunchForRelativeURI Boolean R/W Specifies whether external links specified by the relative address are transformed into 'Open the file' or into 'World Wide Web link' in the PDF link properties. If the value is true, it is transformed to 'Open the file'. If the value is false, it is transformed to 'World Wide Web link'
PdfRGBConversion Int32 R/W Specifies how to convert the RGB color space (DeviceRGB) to DeviceGray.
0. No Conversion
1. Black to DeviceGray
2. Gray to DeviceGray
3. All RGB to DeviceGray
PdfRasterizeResolution Int32 R/W Specifies the value of the rasterised-resolution of the transformed raster images in the range from 70 to 500(dpi). SVG, EMF and WMF are drawn in PDF as vectors without being transformed to raster images.

Properties - SVG Settings

Name Type R/W Functions
SvgVersion Int32 R/W Specifies SVG version:
0. SVG 1.1
1. SVG Basic
2. SVG Tiny
SvgImageProcessingType Int32 R/W Specifies how to treat images contained in the SVG being created.
0. Embeds all image files.
1. Copies all image files to the destination that is specified by SvgImageCopyPath, and then links.
2. Links images that can be linked and embeds images that have to be embedded. Raster images other than JPEG and PNG are always embedded.
3. Copies images that have been linked to the destination that is specified by SvgImageCopyPath, and links. The embedded image are embedded.
If this parameter is omitted, it is considered as 0 and all images are embedded.
SvgImageCopyPath String R/W Specifies the destination to copy images to as specified in 1 or 3 for SvgImageProcessingType parameter.
SvgGzipCompression Boolean R/W Specifies whether to compress the outputted SVG into gzip format or not.
SvgSingleFile Boolean R/W Specifies whether a formatted result composed of multiple pages is output as a single SVG file or as multiple SVG files. If the value is true, outputs as a single SVG file. If the value is false, outputs as multiple SVG files. When multiple files are output, the files are named by the format specified by SvgFormat. This takes effect only when outputting to a file and is not valid when output is without a file name such as when streaming, etc.
SvgImageRename Boolean R/W When images are copied to the directory specified by SvgImageCopyPath etc., specifies whether to rename all file names to the prefix specified by SvgImagePrefix, or use the original name. When the file name overlaps a sequential number is added. When true is specified, all files are renamed.
SvgImagePrefix String R/W When images are copied to the directory specified by SvgImageCopyPath , specifies the prefix of the file name. The file name will be prefixed followed by a sequential numbers only if the Default is empty.
SvgSinglePageNumber Boolean R/W When SvgSingleFile = false is specified, specifies whether to add sequential number to the output SVG even if it has only one-page. If false it is not added.
SvgFormat String R/W When the original document has multiple pages and false is specified in SvgSingleFile, each page will be output as an SVG files that has a consecutive number at the end of the file name. This parameter specifies the format of those consecutive numbers. For example, when "document.svg" is specified as the name for the output file, by specifying "-01" for SvgFormat the output files will be document-01.svg, document-02.svg and so on. If this parameter is omitted, "1" is considered to have been specified.
SvgEmbedAllFonts Boolean R/W Specifies whether to embed fonts in the outputted SVG.
SvgEmbedFonts String R/W Embeds the specified font in the created SVG. If you want to specify plural fonts, put commas between fonts.
SvgErrorOnEmbedFault Boolean R/W When true is specified, an error is issued when font embedding fails.
SvgImageConversion Int32 R/W Selects how to convert the images embedded in SVG to create from the following.
0. Auto
1. JPEG conversion
2. PNG conversion
SvgJPEGQuality Int32 R/W For the image format which cannot be stored directly in SVG, when JPEG conversion is specified in SvgImageConversion, specifies the quality of the image using the range of 1-100. The quality becomes higher in proportion to the increase in the number; however the file size also becomes larger. The initial value is 80.
SvgRasterizeResolution Int32 R/W Specifies the value of the rasterized-resolution of the raster image which is transformed from vector image in the range from 70 to 500(dpi). SVG, EMF and WMF are drawn in SVG as vectors without being transformed to raster images.

Properties - Printer Settings

Name Type R/W Functions
PrnCopies Int32 R/W Specifies the number of copies. Effective when outputting to a printer. If nothing is specified, the value is considered as 1.
PrnCollate Boolean R/W Indicates collation of multiple copies. Effective when outputting to a printer and the number of copies is plural. If it is not specified or the value 'false' is specified, the same page is multi-copied continuously. If 'true' is specified, the pages specified from start to end are printed repeatedly.
BatchPrint Boolean R/W When the value 'false' is specified, the print dialog box is displayed when printing. If the setting is omitted or the value 'true' is specified, the print dialog is not displayed.

Methods

XfoObj Class provides the following methods.

Name Return Value Arguments Functions
Initialize None None The static method. Initializes DLL within the component which uses the DLL. Be sure to do initialize before using the DLL.
Terminate None None The static method. Terminates DLL within the component which uses the DLL. Be sure to terminate when exiting the DLL.
Dispose None None Releases the resource. Please be sure to call this method when you exit the object.
Execute None None Execute formatting and output to a PDF specified in OutputFilePath or printer specified in PrinterName.
Render None XmlTextReader inputreader
Stream outputstream
Executes formatting XSL-FO document that is specified to inputreader, then outputs PDF to specified outputstream.
Render None Stream inputstream
Stream outputstream
Executes formatting XSL-FO document that is specified to inputstream, then outputs PDF to specified outputstream.
Render None XmlDocument inputdoc
Stream outputstream
Executes formatting XSL-FO document that is specified to inputdoc, then outputs PDF to specified outputstream.
Render None Stream xmlSrc
Stream xslSrc
Stream outputstream
Transforms an XML document specified to xmlSrc using an XSL stylesheet specified to xslSrc, then executes formatting and outputs PDF to the specified outputstream. A standard XSLT processor of .NET Framework is used for the XSLT conversion. The ExternalXSLT property and the setting of XSLT processor in the option setting file is disregarded.
Render None XmlTextReader inputreader
Stream outputstream
String outDevice
Executes formatting XSL-FO document that is specified to inputreader, then outputs the specified device to outputstream.
Render None Stream inputstream
Stream outputstream
String outDevice
Executes formatting XSL-FO document that is specified to inputstream, then outputs the specified device to outputstream.
Render None XmlDocument inputdoc
Stream outputstream
String outDevice
Executes formatting XSL-FO document that is specified to inputdoc, then outputs the specified device to outputstream.
Render None Stream xmlSrc
Stream xslSrc
Stream outputstream
String outDevice
Transforms an XML document specified to xmlSrc using an XSL stylesheet specified to xslSrc, then executes formatting and outputs the specified device to outputstream. A standard XSLT processor of .NET Framework is used for the XSLT conversion. The ExternalXSLT property and the setting of XSLT processor in the option setting file is disregarded.
Clear None None Initializes formatting engine.
SetXSLTParam None String name
String value
Sets parameter name and value for xsl:param.
ClearXSLTParam None None Clears all parameter name and value for xsl:param.
SetFontAlias None String fontname
String aliasname
Sets the substitution of font name. This substitution acts on the font names existing in FO. The font name 'fontName' is replaced to 'aliasName'.
EraseFontAlias None String fontname Erases the substitution of font name 'fontName'.
ClearFontAlias None None Clears all substitutions of font name.
GetFormattingError None Collections.ArrayList errlist Possible to call this method after finishing formatting. Gets the error information with the error level of less than ExitLevel generated while formatting, and stores it in Collections.ArrayList specified as an argument. The error information is stored in ArrayList as an object of XfoErrorInformation class. There are three properties, ErrorLevel, ErrorCode and ErrorMessage in the XfoErrorInformation class as the error information.
GetOptionFileURI String int32 index Gets the URL of Option Setting File from the index you specified
AddOptionFileURI None String fileURI Adds the URL of XML-based Option Setting File that indicates the options for XSL Formatter V3.4.

PDF Output to the Web Browser

It's possible to directly output PDF to the Web Browser, when you use ASP.NET application on a server and output the formatted result in PDF. The following is its sample of program.

public class TestPage : Page
{
    public void OnStreamPDF(Object sender, EventArgs ea)
    {
        XfoDotNetCtl.XfoObj obj = new XfoDotNetCtl.XfoObj();
        obj.ExitLevel = 4;
        FileStream fs = null;
        try
        {
            fs = File.Open("c:\\temp\\sample.fo", FileMode.Open, FileAccess.Read);
            Response.Clear();
            Response.ContentType = "application/pdf";
            obj.Render(fs1, Response.OutputStream);
            Response.End();
        }
        catch(Exception e)
        {
            throw e;
        }
        finally
        {
            if (fs != null)
                fs.Close();
        }
    }
}

Programming Example

The following is a sample C# of program. In addition, [Install directory]/samples/dotnet includes some useful sample files for C# and VisualBasic.NET.

using System;

public class MainApp
{
    static public void Main()
    {
        XfoDotNetCtl.XfoObj.Initialize();
        XfoDotNetCtl.XfoObj obj = new XfoDotNetCtl.XfoObj();
        obj.DocumentURI = "c:\\temp\\test.xml";
        obj.StylesheetURI = "c:\\temp\\test.xsl";
        obj.OutputFilePath = "c:\\temp\\test.pdf";
        obj.ExitLevel = 4;
        try
        {
            obj.Execute();
        }
        catch(XfoException e)
        {
            Console.WriteLine("ErrCode : " + e.ErrorCode + "\n" + e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            obj.Dispose();
            XfoDotNetCtl.XfoObj.Terminate();
        }
    }
}


Copyright © 1999-2005 Antenna House, Inc. All rights reserved.
Antenna House is a trademark of Antenna House, Inc.