Altsoft Xml2PDF Server Library

Altsoft.Publisher Namespace

The Altsoft.Publisher namespace contains the set of classes for converting various page description documents from one format to another.

The following source formats are supported:

Word2003Xml Microsoft Word 2003 xml format.
Word2007Xml Microsoft Word 2007 xml format.
Word2007DocX Microsoft Word 2007 format.
FO XSL formatting objects (XSL-FO) format.
SVG Scaleable Vector Graphics format.
XHTML Extensible Hypertext Markup Language format.

Generally, you first create the APSource object that represents your source document. It can be done using one of Create factory methods in APSource class that accepts any stream (memory, zip archive, etc) or URI (local file, web reference, etc) as an input parameter:

    APSource src1 = APSource.Create("1.fo");
    APSource src2 = APSource.Create("http://www.w3c.org");
    
    System.IO.Stream stream = new System.IO.MemoryStream();
    APSource src3 = APSource.Create(stream, APSourceFormat.FO);

Optionally, you can apply an XSL transformation to any source XML document. In this case you first create a new APSource with final (after applying XSL transformation) source format, than create a separate APSource for your XSL transformation and apply this XSLT to the source document using ApplyXSLT. Note that XSLT documents are also represented as APSource objects, but an XSLT source can be used only as an input parameter for APSource.ApplyXSLT method:

    APSource source = APSource.CreateFO("1.xml");
    APSource xslt = APSource.CreateXSLT("1.xsl");
    source.ApplyXSLT(xslt);

As destination object you can use:

PDF Portable Document Graphics.
XPS Microsoft Xml Paper Specification.
PS PostScript.
TIFF Tiff image (multipage image).
GDI+ GDI+ output for printing and preview documents.

You can create required APDestination object using one of the factory Create methods in APDestination class. The destination document can be created either in memory, or as a local file. You can configure Altsoft formatting engine with APConfig object specified as one of the Create method parameters.

Additionally, you can specify security options (at the moment only PDF encryption) using properties UserPassword, OwnerPassword and Permissions:

    APDestionation pdf = APDestination.CreatePDF("1.pdf");
    pdf.OwnerPassword = "password";
    pdf.Permissions.CanPrint = false;

To format the source document and append it to the destination object you simply use Append method of APEngine class and save the destination object:

    using(APDestination pdf = APDestination.CreatePDF("result.pdf"))
    {
        using(APSource src1 = APSource.CreateFO("1.fo"))
            APEngine.Append(src1, pdf);
        pdf.Save();
    }

This method can be called an arbitrary number of times merging the formatting results of different source documents into one destination object:

    System.IO.MemoryStream pdfStream = new System.IO.MemoryStream();
    
    using(APDestination pdf = APDestination.CreatePDF(pdfStream))
    {
        using(APSource src1 = APSource.CreateFO("1.fo"))
            APEngine.Append(src1, pdf);

        using(APSource src2 = APSource.CreateFO("2.fo"))
            APEngine.Append(src2, pdf);

        pdf.Save();
    }

Alternatively, any source document can be used as a backgound via AddBackground method:

    using(APDestination xps = APDestination.CreateXPS("result.xps"))
    {
        using(APSource src = APSource.CreateDocX("source.docx"))
            APEngine.Append(src, xps);

        using(APSource background = APSource.CreateSVG("background.svg"))
            APEngine.AddBackground(src, xps, 0, xps.PageCount-1, true);

        xps.Save();
    }

GDIPlus destination object represents a special output object that can be used for direct print or preview of the formatting results. To print source document, append it to the GDIPlus object using APEngine.Append call and send it directly to a print device (represented by the standard System.Drawing.Printing.PrintDocument object) using GDIPlusPrint call:

    using(APDestination gdiPlus = APDestination.CreateGDIPlus())
    {
        using(APSource src1 = APSource.CreateFO("1.fo"))
            APEngine.Append(src1, gdiPlus);
        
        System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
        
        // ... configure printDoc
        APEngine.GDIPlusPrint(gdiPlus, printDoc);
        printDoc.Print();
    }  

Namespace hierarchy

Classes

ClassDescription
APConfig Altsoft formatting engine configuration.
APDestination Output document destination
APDestinationPermissions Set of APDestination permissions.
APEngine Facade class for Altsoft Xml2PDF functionality.
APLog Operation log.
APSource Input document source.

Structures

StructureDescription
APWarning Operation warning message.

Delegates

DelegateDescription
BeginStageHandler Base delegate for OnBeginStage event handlers.
EndStageHandler Base delegate for OnEndStage event handlers.
ProgressHandler Base delegate for OnProgress event handlers.
WarningHandler Base delegate for OnWarning event handlers.

Enumerations

EnumerationDescription
APDestinationFormat Available destination formats
APSourceFormat Available source formats.