ByteScout PDF Suite - VB.NET - Convert xml to pdf with pdf sdk - ByteScout

ByteScout PDF Suite – VB.NET – Convert xml to pdf with pdf sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Suite – VB.NET – Convert xml to pdf with pdf sdk

How to convert xml to pdf with pdf sdk in VB.NET with ByteScout PDF Suite

This code in VB.NET shows how to convert xml to pdf with pdf sdk with this how to tutorial

These source code samples are assembled by their programming language and functions they apply. What is ByteScout PDF Suite? It is the set that includes 6 SDK products to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript. It can help you to convert xml to pdf with pdf sdk in your VB.NET application.

These VB.NET code samples for VB.NET guide developers to speed up coding of the application when using ByteScout PDF Suite. Simply copy and paste in your VB.NET project or application you and then run your app! Enjoy writing a code with ready-to-use sample codes in VB.NET.

You can download free trial version of ByteScout PDF Suite from our website with this and other source code samples for VB.NET.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Program.vb
      
Imports System.Xml Imports Bytescout.PDF ''' <summary> ''' This example demonstrates how to create table from some XML data. ''' Since your XML file has different structure the example just shows technique of XML data reading ''' and PDF table creation. ''' </summary> Class Program Shared Sub Main() ' Load XML document Dim xmlDocument = New XmlDocument() xmlDocument.Load("sample.xml") ' Read columns information from XML data Dim columns = New List(Of String)() Dim columnNodeList = xmlDocument.SelectNodes("/Report/Columns/Column") For Each node As XmlNode In columnNodeList columns.Add(node.Attributes("Name").Value) Next ' Read row nodes from XML data Dim rowNodeList = xmlDocument.SelectNodes("/Report/ReportData") ' Create new PDF document Dim pdfDocument = New Document() pdfDocument.RegistrationName = "demo" pdfDocument.RegistrationKey = "demo" ' Add page Dim page = New Page(PaperFormat.A4) pdfDocument.Pages.Add(page) Dim lightGrayColor = New ColorGray(200) Dim whiteColor = New ColorGray(255) ' Create PDF table Dim table = New Table() table.BackgroundColor = lightGrayColor ' Add columns For c = 0 To columns.Count - 1 Dim column = New TableColumn(columns(c), columns(c)) ' Set column width column.Width = If(c = 0, 100, 60) table.Columns.Add(column) Next ' Add rows For Each rowNode As XmlNode In rowNodeList ' Create new row and set its background color Dim row = table.NewRow() row.BackgroundColor = whiteColor ' Get cell values from XML data For Each childNode As XmlNode In rowNode.ChildNodes ' Get cell info from XML data Dim columnName = childNode.Name Dim columnIndex = columns.IndexOf(childNode.Name) Dim cellValue = childNode.InnerText ' Set cell text row(columnName).Text = cellValue ' Set cell text alignment row(columnName).TextFormat.HorizontalAlign = If(columnIndex = 0, HorizontalAlign.Left, HorizontalAlign.Right) Next ' Add the row to the table table.Rows.Add(row) Next ' Draw the table on canvas page.Canvas.DrawTable(table, 20, 20) ' Save document to file pdfDocument.Save("result.pdf") ' Cleanup pdfDocument.Dispose() ' Open document in default PDF viewer application Process.Start("result.pdf") End Sub End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next