Using NFOP with ASP.NET Example

Here's some example ASP.NET VB.NET code that will allow you to use NFOP to push the generated PDF out to a browser.

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="ApacheFop" %>
 
<script LANGUAGE="VB" runat="server">
 
Public Class CVPDFMaker
 
Public Shared Sub MakePdf(xml as string, xsl as string, pdf as string)
  Try
    Dim objFOStream As New StringWriter()
    Dim objDoc As New XmlDocument()
    objDoc.Load(xml)
    Dim objTransform As New XslTransform()
    objTransform.Load(xsl)
    objTransform.Transform(objDoc, Nothing, objFOStream)  
    Dim eng As New Engine() '' using NFop
    Dim spdf As SByte()
    spdf = eng.Run(objFOStream.ToString())
    Dim intLength As Integer = spdf.Length
    Dim fs As New FileStream(pdf, FileMode.Create, FileAccess.Write)
    Dim binWriter As New BinaryWriter(fs)
    For intLength = 0 To (intLength - 1)
        binWriter.Write(spdf(intLength))
    Next
    fs.Close()   
    binWriter.Close()  
  Catch objException As Exception
   '' something's gone wrong
  End Try
End Sub
 
End Class
</script>