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

Free Support Forum - aspose.com

XML Schema and For to do Loop

Hi,

I have to create a pdf file by usinge an xml schema that looks like this:
----------------------------------------------------
Notice:

2009.10.09 - Testuser:

This is the first Notice.


2009.10.10 - Testuser2:

This is the second Notice.


2009.10.10 - Testuser1:

This is the third Notice.
-----------------------------------------------------
But by using an xml schema all I get is this:
-----------------------------------------------------
Notice:

2009.10.09 - Testuser:

2009.10.10 - Testuser2:

2009.10.10 - Testuser1:

This is the first Notice.

This is the second Notice.

This is the third Notice.
------------------------------------------------------
What is the proper way to get the rigth result? Used source code below. Thanks, Daniel


schema.xml:

<?xml version="1.0" encoding="UTF-8"?>
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="aspose.pdf.xml">





Private Sub create_notice_folder(ByVal MyExportDaten() As startExport.sExport_Daten, ByVal myindex As Integer, ByRef PagesCountBeforeAddThis As Integer)

Dim mycover As New Pdf
mycover.BindXML("schema.xml", Nothing)
Dim sec1 As Section = mycover.Sections("Content")

Dim t1 As Text = sec1.Paragraphs("NoticeTitle")
Dim t2 As Text = sec1.Paragraphs("NoticeSubTitle")
Dim t3 As Text = sec1.Paragraphs("NoticeValue")

Dim MyText As String = ""

myText = "Notice:" + Environment.NewLine + Environment.NewLine

t1.Segments.Add(MyText)

If MyExportDaten(myindex).Notizen.notizen IsNot Nothing Then

For i = 0 To MyExportDaten(myindex).Notice.Notices.Length - 1
MyText = MyExportDaten(myindex).Notice.Notices(i).Date + " - " + MyExportDaten(myindex).Notice.Notices(i).Creator + ":" + Environment.NewLine + Environment.NewLine

t2.Segments.Add(MyText)

MyText = MyExportDaten(myindex).Notice.Notices(i).Text + Environment.NewLine + Environment.NewLine + Environment.NewLine

t3.Segments.Add(MyText)


Next

Dim id As String = Guid.NewGuid.ToString
Dim myname As String = My.Computer.FileSystem.SpecialDirectories.Temp + "\" + id + ".tmp"
Dim myStream As FileStream = New FileStream(myname, FileMode.Create)
mycover.Save(myStream)

add2ExportObject(myStream, myname)

mycover = Nothing
t1 = Nothing

sec1 = Nothing

End If

End Sub

Hi,

I sent a request yesterday in the public forum and didn´t get an answer yet. May you lok at the feed and give me one.

This message was posted using Aspose.Live 2 Forum

Hello Daniel,

Sorry for replying you late.

Instead of specifying the 3 objects in the XML document, you can define a single object and use it to create your desired document. Please take a look over the following updated XML document and the code snippet. The PDF document that I've generated is in attachment, please take a look.

[XML]

<?xml version="1.0" encoding="UTF-8"?>
<Pdf xmlns="Aspose.Pdf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="aspose.pdf.xml">
<Section ID="Content" TextColor="rgb 0 0 0">
<Text Alignment="Left" FontName="Verdana" FontSize="13" IsTrueTypeFontBold="true" IsUnderline ="true" ID="NoticeTitle" />
</Section>
</Pdf>

[VB.NET]

Dim pdf1 As Pdf = New Pdf()
pdf1.BindXML("d:/pdftest/sampleXMl.xml", Nothing)
'Get the section and then table from the obtained section of the Pdf that
'is built from the XML template

Dim sec1 As Section = pdf1.Sections("Content")
Dim t1 As Text = sec1.Paragraphs("NoticeTitle")
' Dim t2 As Text = sec1.Paragraphs("NoticeSubTitle")
'Dim t3 As Text = sec1.Paragraphs("NoticeValue")

Dim MyText As String = ""
MyText = "Notice:" + Environment.NewLine + Environment.NewLine
t1.Segments.Add(MyText)
Dim i As Integer

For i = 1 To 3
MyText = ""
MyText = "2009.10.09 " + " - " + "Testuser" + i.ToString() + ":" + Environment.NewLine + Environment.NewLine
t1.TextInfo.FontSize = 11
t1.TextInfo.IsTrueTypeFontBold = True
t1.TextInfo.IsUnderline = False
t1.Segments.Add(MyText)

MyText = "This is the " + i.ToString() + "Notice." + Environment.NewLine + Environment.NewLine + Environment.NewLine
t1.TextInfo.FontSize = 11
t1.TextInfo.IsTrueTypeFontBold = False
t1.TextInfo.IsUnderline = False
t1.Segments.Add(MyText)

Next

pdf1.Save("d:/pdftest/ImageInTableIssue.pdf")

In case it does not satisfy your requirements or you've any further query, please feel free to contact.

Thanks for your reply,

But your solution don´t cover all. Our customers like to change the textstyle in the xml file. As you see there is a different in t2 an t3 in "IsTrueTypeFontBold". Is there a way do get that result through different defined "text"- objects in the xml file?

Thanks, Daniel

I noticed also, that the alignment property is set for the whole t1 object. It keeps the last alignment setting. So, if I do it your way I can´t have different alignments in the text for the title (center) an the text (left) for example.

Hello Daniel,

After further looking into this matter, I've concluded that it's an issue in our product that it cannot display the text items in correct order, when converting the XML contents into PDF format. For the sake of correction, I've logged it in our issue tracking system as PDFNET-15057. We will investigate this issue in details and will keep you updated on the status of a correction.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />Regarding your query over setting different Alignment values for the text object, I'm afraid this requirement cannot be accomplished with my earlier proposed solution. Please spare us little time and wait for the solution for PDFNET-15057.

Your patience and comprehension is greatly appreciated in this regard.

We apologize for your inconvenience.

Hello Daniel,

The issues is still under consideration and I am afraid its not yet resolved. Meanwhile, I have contacted the development team to share some ETA regarding its resolution. As soon as I have some updates, I would be pleased to update you with that information.

Please be patient and spare us little time. You patience and comprehension is greatly appreciated in this regard.

Hello Daniel,

There is no possibility to implement your request without any program logic. If You need to separate text settings and XML template You can create configuration file(XML for example), and read the settings. Here is the sample code(I've attached the result with PDF output).

[XML - config.xml]

<?xml version="1.0" encoding="utf-8"?>

<configNotes>

<Text Alignment="Left" FontName="Verdana" FontSize="11" IsTrueTypeFontBold="true" IsUnderline ="false" ID="NoticeSubTitle" />

<Text Alignment="Left" FontName="Verdana" FontSize="11" IsTrueTypeFontBold="false" IsUnderline ="false" ID="NoticeValue" />

</configNotes>

[XML - sample.xml]

<?xml version="1.0" encoding="UTF-8"?>

<Pdf xmlns="Aspose.Pdf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="aspose.pdf.xml">

<Section ID="Content" TextColor="rgb 0 0 0">

<Text Alignment="Left" FontName="Verdana" FontSize="13" IsTrueTypeFontBold="true" IsUnderline ="true" ID="NoticeTitle" />

</Section>

</Pdf>

[VN.NET]

Dim doc As New XmlDocument()
doc.Load("config.xml")
Dim nodeList As XmlNodeList = doc.GetElementsByTagName("Text")
Dim nodeSubTitle As XmlElement = DirectCast(nodeList(0), XmlElement)
Dim nodeValue As XmlElement = DirectCast(nodeList(1), XmlElement)

Dim pdf As New Pdf()
pdf.BindXML("sampleXML.xml", Nothing)

Dim sec As Section = pdf.Sections("Content")
Dim t1 As Text = DirectCast(sec.Paragraphs("NoticeTitle"), Text)

Dim myText As String = String.Format("Notice:{0}{0}", Environment.NewLine)
t1.Segments.Add(myText)

For i As Integer = 1 To 3
myText = String.Format("2009.10.09 - Testuser {0}:{1}{1}", i, Environment.NewLine)
Dim textSubTitle As New Text()
textSubTitle.TextInfo.FontSize = Convert.ToInt32(nodeSubTitle.GetAttribute("FontSize"))
textSubTitle.TextInfo.IsTrueTypeFontBold = Convert.ToBoolean(nodeSubTitle.GetAttribute("IsTrueTypeFontBold"))
textSubTitle.TextInfo.IsUnderline = Convert.ToBoolean(nodeSubTitle.GetAttribute("IsUnderline"))
textSubTitle.Segments.Add(myText)
sec.Paragraphs.Add(textSubTitle)

myText = String.Format("This is the {0} Notice.{1}{1}{1}", i, Environment.NewLine)
Dim textValue As New Text()
textValue.TextInfo.FontSize = Convert.ToInt32(nodeValue.GetAttribute("FontSize"))
textValue.TextInfo.IsTrueTypeFontBold = Convert.ToBoolean(nodeValue.GetAttribute("IsTrueTypeFontBold"))
textValue.TextInfo.IsUnderline = Convert.ToBoolean(nodeValue.GetAttribute("IsUnderline"))
textValue.Segments.Add(myText)
sec.Paragraphs.Add(textValue)
Next

pdf.Save("result.pdf")

The issues you have found earlier (filed as 15057) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.