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

Free Support Forum - aspose.com

Coverting xml + xslt to Pdf

I am trying to create pdf file from xml and xslt, but it doesn’t work.

I have tried multiple ways:
Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
pdf1.BindXML(“C:\Sources\web_custom\DDV_O_EDP-82705739-380.xml”, “C:\Sources\web_custom\DDV_O_9.1-display-sl.xslt”)
pdf1.Save(“HelloWorld.pdf”, Generator.SaveType.OpenInAcrobat, Response)

in this scenario i get an error.
I also tried this one:

Dim document As XmlDocument ’ Xml document root
Dim navigator As XPathNavigator ’ navigate document
Dim transformer As XslCompiledTransform ’ transform document
Dim output As StringWriter
document = New XmlDocument()
document.Load(“C:\Sources\web_custom\DDV_O_EDP-82705739-380.xml”)
navigator = document.CreateNavigator
transformer = New XslCompiledTransform()
transformer.Load(“C:\Sources\web_custom\DDV_O_9.1-display-sl.xslt”)
output = New StringWriter()
transformer.Transform(navigator, Nothing, output)
Dim stream As New MemoryStream(System.Text.Encoding.UTF8.GetBytes(output.ToString()))
Dim writer As StreamWriter = New StreamWriter(stream)
writer.Write(output.ToString)
stream.Position = 0
Dim pdf As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
pdf.IsAutoFontAdjusted = True
’ add the section to PDF document sections collection

Dim section As Aspose.Pdf.Generator.Section = pdf.Sections.Add()
section.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.LetterWidth

section.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.LetterHeight

section.PageInfo.Margin.Top = 5

section.PageInfo.Margin.Bottom = 5

section.PageInfo.Margin.Left = 5

section.PageInfo.Margin.Right = 5
’ Read the contents of HTML file into StreamReader object
’ Dim r As StreamReader = File.OpenText(“D:/pdftest/HTML2pdf.html”)
'Create text paragraphs containing HTML text
Dim text2 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(section, output.ToString())
’ enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = True
text2.IsFitToPage = True
text2.IfHtmlTagSupportedOverwrightHtmlFontSizes = True
text2.IfHtmlTagSupportedOverwrightHtmlFontNames = True
text2.IfHtmlTagSupportedCssWinsOnFirstLevelChildren = True
’ Add the text object containing HTML contents to PD Sections
section.Paragraphs.Add(text2)
’ Specify the URL which serves as images database
pdf.HtmlInfo.ImgUrl = “D:/pdftest/MemoryStream/”
pdf.HtmlInfo.PageHeight = 100
pdf.HtmlInfo.PageWidth = 300
pdf.TextInfo.FontSize = 2

'Save the pdf document
pdf.Save(“HelloWorld.pdf”, Generator.SaveType.OpenInAcrobat, Response)
writer.Close()
output.Close()
Response.End()

With this case pdf actualy get made, but it looks twisted. And I can’t get it to fit to 1 page.

lp

Hi there,


Sorry for the inconvenience faced.

After initial investigation, we’ve logged the issue as PDFNEWNET-35355 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue progress via this forum thread.

Best Regards,

Hi Erik,

Thanks for your patience.

We have further investigated the issue PDFNEWNET-35355 reported earlier and it does not seem to be a bug. Please note that BindXML expects that summary XML (that it will get after applying XSLT to that supplied XML), will contain special tags related to PDF document object model. Something similar to following XML after translation.

[XML]

<?xml version="1.0" encoding="utf-8" ?><o:p></o:p>

<Pdf xmlns=“Aspose.Pdf” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“Aspose.Pdf

C:\PROGRA~1\Aspose\ASPOSE~1.NET\Xml\Aspose.Pdf.xsd” DestinationType=“FitPage”>

<Section ID=“section1” PageMarginLeft=“1cm” PageMarginRight=“1cm” PageMarginTop="4.5cm"PageMarginBottom=“3.5cm” PageSize=“A4”>

<PageBorder>
<All BorderStyle=“Normal”></All>

</PageBorder>

<Image ID=“id1” File=“PDFNET-15770-1.gif” Type=“Gif” FixHeight=“5cm” FixWidth=“15cm” Alignment="Center"MarginTop=“1cm”></Image>

<Image ID=“id2” File=“PDFNET-15770-2.gif” Type=“Gif” FixHeight=“10cm” FixWidth=“15cm” Alignment="Center"MarginTop=“1cm”></Image>

<Text MarginLeft=“2cm” MarginRight=“2cm” FontName=“Arial” MarginTop=“1cm”>

<TextBorder>

<All BorderStyle=“Normal”></All>

</TextBorder>
<Segment IsTrueTypeFontBold=“true” FontSize=“12”>Commentaires :#$NL</Segment>

<Segment>
dsfk mkf mskdf skdfm skdf ldkf mslkfd smdfkms dfkmkf;koki mslmkf mkmfk mlkf lkf mkmsfk l kmfksmfmskf ifmks lkfm smkmfk s#$NL

sdfjfhsdfhdsjf lkf fjslkfd ljflskdfpokmlkrt dmlfkger lkvgdhjh fhkjhdhfyez ajd s#$NL
sdfjfhsdfhdsjf lkf fjslkfd ljflskdfpokmlkrt dmlfkger lkvgdhjh fhkjhdhfyez ajd s#$NL

sdfjfhsdfhdsjf lkf fjslkfd ljflskdfpokmlkrt dmlfkger lkvgdhjh fhkjhdhfyez ajd s#$NL

sdfjfhsdfhdsjf lkf fjslkfd ljflskdfpokmlkrt dmlfkger lkvgdhjh fhkjhdhfyez ajd s#$NL

sdfjfhsdfhdsjf lkf fjslkfd ljflskdfpokmlkrt dmlfkger lkvgdhjh fhkjhdhfye#$NL
</Segment>
</Text>

<Image ID=“id3” File=“PDFNET-15770-3.gif” Type=“Gif” FixHeight=“10cm” FixWidth=“15cm” Alignment="Center"MarginTop=“1cm”></Image>
<Image ID=“id4” File=“PDFNET-15770-4.gif” Type=“Gif” FixHeight=“10cm” FixWidth=“15cm” Alignment="Center"MarginTop=“1cm”></Image>
</Section>
</Pdf>

But, as we can see from set of sample files, the XML+XSLT cannot generate XML that make sense for BindXml method. Please ensure that XML which you get after applying XSLT to XML looks like aforementioned XML suitable for BindXml method. In the event of any further query, please feel free to contact.