[xep-support] Transforming XmlDocument (Containing XSL-FO) to PDF

Hart, Leo Leo.Hart at FMR.COM
Fri Oct 1 13:23:05 PDT 2004


I have a function that accepts an FO document in the form of a
System.Xml.XmlDocument and returns a PDF in the form of a Byte array.

Here's the function:

		Public Shared Function TransformXslFOToPDF(ByRef
pXslFODocument As XmlDocument) As Byte()
			m_log.Debug("Transforming XSL-FO to PDF: " &
vbCrLf & pXslFODocument.OuterXml)

			'Holds the outgoing PDF stream
			Dim lOutStream As New MemoryStream

			'Get Xmldocument into Stream
			Dim lInStream As New MemoryStream
			pXslFODocument.Save(lInStream)
			lInStream.Position = 0

			'Get Stream into XmlReader
			Dim lInReader As New XmlTextReader(lInStream)
			lInReader.MoveToContent()			

			'Configuration settings for Formatter
			Dim lConfigSettings As New Hashtable
			lConfigSettings.Add("ROOT", "C:\Program
Files\RenderX\XEP.NET 3.8")

			'FO Formatter
			Dim lFormatter As New
Renderx.Xep.Formatter(lConfigSettings, Nothing)

			lFormatter.Format("", lInReader, lOutStream,
Formatter.OUTPUT_PDF, lConfigSettings, Nothing)

			Return lOutStream.GetBuffer
		End Function

And here's the FO that exists within pXslFODocument:

		<fo:root
xmlns:rx="http://www.renderx.com/XSL/Extensions"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
			<fo:layout-master-set>
				<fo:simple-page-master
master-name="my-page">
					<fo:region-body margin="1in" />
				</fo:simple-page-master>
			</fo:layout-master-set>
			<fo:page-sequence master-reference="my-page">
				<fo:flow flow-name="xsl-region-body">
					<fo:block>Hello
World!</fo:block>
				</fo:flow>
			</fo:page-sequence>
		</fo:root>

When I run this test case I receive the following error:

		Exception: Renderx.Xep.XepInvalidOperationException
		Message: startDocument: Invalid XSL FO source
'file:/C:/WINDOWS/system32/': 1 error found during validation
		Source: Renderx.Xep.Public
			at Renderx.Xep.Sax.ContentHandler.endDocument()
			at
Renderx.Xep.Sax.Adapter.XmlReaderToSax.WriteEndDocument()
			at
Renderx.Xep.Sax.Adapter.XmlReaderToSax.Parse()
			at Renderx.Xep.Formatter.Format(String
sBasePath, XmlReader reader, Stream outStream, String sOutFormat,
Hashtable htGenProperties, Logger logger)
			at
Sandbox.Library.XML.Transformer.TransformXslFOToPDF(XmlDocument&
pXslFODocument) in C:\Documents and Settings\a122695\My Documents\Visual
Studio Projects\Sandbox\LibrarySandbox\Classes\XML\Transformer.vb:line
60
			at Sandbox.Web.GetPDFFromXSL_FO.Page_Load(Object
sender, EventArgs e) in
C:\Inetpub\WWWRoot\WebSandbox\ASP\XML\GetPDFFromXSL-FO.aspx.vb:line 43

I assume this is related to the fact that the sBasePath parameter in
lFormatter.Format is set to a null string.  I can't figure out what I'm
supposed to use this for.  I've tried various different file and http
paths, but all of them error out.  I just want to convert my
memory-based FO document to a memory-based PDF.

Any suggestions?

Thanks,
Leo Hart

-------------------
(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to majordomo at renderx.com from the address
you are subscribed from.
(*) By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/tos.html



More information about the Xep-support mailing list