We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Error when using PDF.Generator


I am trying to generate a PDF from xml + xsl stylesheet. I copied an example from your website. I am receving the following error:

Execution of the 'document()' function was prohibited. Use the XsltSettings.EnableDocumentFunction property to enable it. An error occurred at (1,2414)

Attached are the source document DCJS_msg_extract.xml and the stylesheet merged-nysrap.xsl(I was required to zip it by your system).

Below is the code:

Dim pdf As New Aspose.Pdf.Generator.Pdf

'Create XMLDcoument object for XML file

Dim SourceXML As System.Xml.XmlDocument = New System.Xml.XmlDocument()

Dim fs As FileStream = New FileStream("c:\DCJS_msg_extract.xml", FileMode.Open)

'load the contents of FileStream object into SrourceXML object


'Create XMLDcoument object for XSL file

Dim SourceXSL As System.Xml.XmlDocument = New System.Xml.XmlDocument()

'read the contents of XSL file into FileStream object

Dim XSL_FileStream As FileStream = New FileStream("C:\styleRepository\styleRepository\RapGen\merged-nysrap.xsl", FileMode.Open)

'load the contents of FileStream object into SrourceXSL object


'call the BindFO method with two arguments (XML,XSL)

pdf.BindFO(SourceXML, SourceXSL)

'Write PDF File


Hi Edward,

Thanks for contacting support.

I have tested the scenario and I am able to reproduce the issue that XML and XSL files are not properly being converted into PDF format. For the sake of correction, I have logged this problem as PDFNEWNET-34509 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Do you have any updates regarding this issue? It is critcal that I have this working by next Monday.

Hi Edward,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Well, our development team needs some time to further analyze your issue. I have requested them to share an ETA regarding the resolution of your issue once they are done with their analysis. However, it will not be possible to provide a fix for your issue by coming Monday. I will update you via this forum thread once I get the ETA information.

Sorry for the inconvenience,

Hi Edward,

Thanks for your patience.

The development team has further investigated the issue PDFNEWNET-34509 reported earlier and as per our observations, following exception is being thrown.

Execution of the ‘document()’ function was prohibited. Use the XsltSettings.EnableDocumentFunction property to enable it. An error occurred at (1,2414).

It’s because the supplied XML+XSLT documents are complex enough and use advanced features of transformation. Please note that problem (at least now) is in XML+XSLT transformation itself, not in conversion results of PDF.

In such cases, it is always useful to do transformation in outer code (not inside Aspose.Pdf),
investigate result when necessary and supply final result XML for usage in BindXML method.
For testing purposes, we tried using following code snippet but we encountered an exception which states that during XSLT transformation, some file is required which was not provided earlier.

An error occurred while loading document ‘file:///c:/styleRepository/styleRepository/RapGen/RapGen_resources/rapgen_preferences.xml’. See InnerException for a complete description of the error.


FileStream inXmlStream = new FileStream(@“F:\ExternalTestsData\34509.xml”, FileMode.Open);<o:p></o:p>

FileStream inXslStream = new FileStream(@"F:\ExternalTestsData\34509.xslt", FileMode.Open);

string result = DoTransformation(inXmlStream, inXslStream);

byte[] outAsBytes = System.Text.Encoding.UTF8.GetBytes(result);

string preparedXmlFile = @"F:\ExternalTestsData\34509_prepared.xml";

File.WriteAllBytes(preparedXmlFile, outAsBytes);

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

pdf.BindXML(preparedXmlFile, null);


internal static string DoTransformation(Stream inputStream, Stream xslStream)



// load source document


System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();


XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

xmlReaderSettings.ProhibitDtd = false;

XmlReader xmlReader = XmlReader.Create(new StringReader(xmlDoc.OuterXml), xmlReaderSettings);


// load xslt-transform


System.Xml.XmlDocument xsltDoc = new System.Xml.XmlDocument();


System.Xml.Xsl.XslCompiledTransform processor = new System.Xml.Xsl.XslCompiledTransform();

XmlReader xsltReader = XmlReader.Create(new StringReader(xsltDoc.OuterXml));

System.Xml.Xsl.XsltSettings xsltSettings = new System.Xml.Xsl.XsltSettings();

xsltSettings.EnableDocumentFunction = true;

processor.Load(xsltReader, xsltSettings, null);


// do transformation


System.Text.StringBuilder documentBuilder = new System.Text.StringBuilder();

XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

xmlWriterSettings.ConformanceLevel = ConformanceLevel.Auto;

XmlWriter xmlWriter = XmlWriter.Create(documentBuilder, xmlWriterSettings);

processor.Transform(xmlReader, xmlWriter);

return documentBuilder.ToString();


Please share the required file so that we can further proceed with the investigation/resolution of this problem.

The issues you have found earlier (filed as PDFNEWNET-34509) have been fixed in Aspose.Pdf for .NET 9.9.0.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.