The example given below provides complete demonstration of the almost all possible ways to convert XSL-FO files in any form to PDF document. The example also describes that how can developers set meta information of the PDF documents. In the early lines of code, it is also practiced about how to set license for Aspose.Pdf . These lines are commented for the developers using evaluation versions of Aspose.Pdf . If you have bought a license of Aspose.Pdf then you should un-comment those lines.
Code Snippet
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports Aspose.Pdf
Public Class HelloWorld
Shared Sub Main()
'Set up your product license.
'If you just want to evaluate Aspose.Pdf.Fo, you can annotate these two lines.
'License license = new License();
'license.SetLicense("Aspose.Pdf.lic");
'Create a Convertor object.
Dim app As Pdf
Dim pdf As System.IO.Stream
Dim name As String = "HelloWorld"
Dim fo As String = name + ".fo"
Dim xml As String = name + ".xml"
Dim xsl As String = name + ".xsl"
' Create the XmlDocument.
Dim doc_fo As XmlDocument = New XmlDocument
doc_fo.Load(New StreamReader(fo))
Dim doc_xml As XPathDocument = New XPathDocument(xml)
'1. fo:string2string
app = New Pdf
app.BindFO(fo)
app.Save(name + "_fo_sring2string.pdf")
'2. fo:string2stream
app = New Pdf
app.BindFO(fo)
pdf = New System.IO.FileStream(name + "_fo_string2stream.pdf",
System.IO.FileMode.Create)
app.Save(pdf)
'3. fo:stream2string
app = New Pdf
app.BindFO(New System.IO.FileStream(fo, System.IO.FileMode.Open,
System.IO.FileAccess.Read))
app.Save(name + "_fo_stream2string.pdf")
'4. fo:stream2stream
app = New Pdf
app.BindFO(New System.IO.FileStream(fo, System.IO.FileMode.Open,
System.IO.FileAccess.Read))
pdf = New System.IO.FileStream(name + "_fo_stream2stream.pdf",
System.IO.FileMode.Create)
app.Save(pdf)
'5. fo:doc2string
app = New Pdf
app.BindFO(doc_fo)
app.Save(name + "_fo_doc2string.pdf")
'6. fo:doc2stream
app = New Pdf
app.BindFO(doc_fo)
pdf = New System.IO.FileStream(name + "_fo_doc2stream.pdf",
System.IO.FileMode.Create)
app.Save(pdf)
'7. xml:string2string
app = New Pdf
app.BindFO(xml, xsl)
app.Save(name + "_xml_string2string.pdf")
'8. xml:string2stream
app = New Pdf
app.BindFO(xml, xsl)
pdf = New System.IO.FileStream(name + "_xml_string2stream.pdf",
System.IO.FileMode.Create)
app.Save(pdf)
'9. xml:doc2string
app = New Pdf
app.BindFO(doc_xml, xsl)
app.Save(name + "_xml_doc2string.pdf")
'10. xml:doc2stream
app = New Pdf
app.BindFO(doc_xml, xsl)
pdf = New System.IO.FileStream(name + "_xml_doc2stream.pdf",
System.IO.FileMode.Create)
app.Save(pdf)
'0. An example of how to set the metadata of your generated pdf document
'If you do not want to set these tedious metadata of pdf, you can set the
'second parameter of Save method to be "null" simply, as shown in above.
'At first create a IDictionary to contain your metadata.
Dim metadata As System.Collections.IDictionary = New
System.Collections.Hashtable
'Then set the various items.
'If you don't set them, Aspose.Pdf.Fo will set default value.
'a. title of your pdf doc:
metadata.Add("Title", "New Title")
'b. author of your pdf doc:
metadata.Add("Author", "New Author")
'c. subject of your pdf doc:
metadata.Add("Subject", "New Subject")
'd. keywords of your pdf doc:
metadata.Add("Keywords", "New Key Words")
'e. creator of your pdf doc:
metadata.Add("Creator", "New Creator")
'f. producer of your pdf doc:
metadata.Add("Producer", "New Producer")
'Make this IDictionary be the parameter of Save method and
'start converting.
app = New Pdf
app.FoMetaData = metadata
app.BindFO(fo)
app.Save("HelloWorld.pdf")
End Sub
End Class