ByteScout PDF SDK - VB.NET - Convert XML to PDF - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout PDF SDK – VB.NET – Convert XML to PDF

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – VB.NET – Convert XML to PDF

How to convert XML to PDF in VB.NET with ByteScout PDF SDK

Tutorial on how to convert XML to PDF in VB.NET

Source code documentation samples provide quick and easy way to add a required functionality into your application. ByteScout PDF SDK is the SDK for pdf documents generation, modification and updates. Can also generate and fill PDF forms. Provides support for text (fonts, style, size, font family), layers, pdf form fields, vector and raster drawings. It can be used to convert XML to PDF using VB.NET.

You will save a lot of time on writing and testing code as you may just take the VB.NET code from ByteScout PDF SDK for convert XML to PDF below and use it in your application. Just copy and paste the code into your VB.NET application’s code and follow the instruction. Enjoy writing a code with ready-to-use sample VB.NET codes.

Free trial version of ByteScout PDF SDK is available on our website. Documentation and source code samples are included.

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 SDK Home Page

Explore ByteScout PDF SDK Documentation

Explore Samples

Sign Up for ByteScout PDF SDK 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 SDK Home Page

Explore ByteScout PDF SDK Documentation

Explore Samples

Sign Up for ByteScout PDF SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next