How to draw grid in PDF with conformance?
Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can draw grid in conformance PDF or PDF/A-1b using C# and VB.NET.
Steps to draw grid in PDF with the conformance
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework applications from NuGet.org.
- Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; using System.Data; using System.Drawing;
VB.NET
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Graphics Imports Syncfusion.Pdf.Grid Imports System.Data Imports System.Drawing
- Use the following code snippet to draw grid or table in PDF/A-1b document.
C#
//Create a new PDF document PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A1B); //Add a page PdfPage page = doc.Pages.Add(); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); pdfGrid.Style.Font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 14), true); //Create a DataTable DataTable dataTable = new DataTable(); //Add columns to the DataTable dataTable.Columns.Add("ID"); dataTable.Columns.Add("Name"); //Add rows to the DataTable dataTable.Rows.Add(new object[] { "E01", "Mark" }); dataTable.Rows.Add(new object[] { "E02", "Chad" }); //Assign data source pdfGrid.DataSource = dataTable; //Draw grid to a page of the PDF document pdfGrid.Draw(page, new PointF(10, 10)); //Save the document doc.Save("Output.pdf"); //Close the document doc.Close(true);
VB.NET
'Create a new PDF document Dim doc As New PdfDocument(PdfConformanceLevel.Pdf_A1B) 'Add a page Dim page As PdfPage = doc.Pages.Add() 'Create a PdfGrid Dim pdfGrid As New PdfGrid() pdfGrid.Style.Font = New PdfTrueTypeFont(New Font("Arial Unicode MS", 14), True) 'Create a DataTable Dim dataTable As New DataTable() 'Add columns to the DataTable dataTable.Columns.Add("ID") dataTable.Columns.Add("Name") 'Add rows to the DataTable dataTable.Rows.Add(New Object() {"E01", "Mark"}) dataTable.Rows.Add(New Object() {"E02", "Chad"}) 'Assign data source pdfGrid.DataSource = dataTable 'Draw grid to a page of the PDF document pdfGrid.Draw(page, New PointF(10, 10)) 'Save the document doc.Save("Output.pdf") 'Close the document doc.Close(True)
You can download the work sample from PdfGridConformanceSample.Zip
By executing the program, you will get the PDF document as follows.
Take a moment to peruse the documentation, where you will find other options like drawing right-to-left text and multi-column text, consuming TrueType fonts, Standards fonts, CJK fonts. Also, the features like PDF form filling, extract text or images from PDF, protect PDF documents with code examples.
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
Conclusion
I hope you enjoyed learning about how to draw grid in PDF with conformance.
You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!