2X faster development
The ultimate WPF UI toolkit to boost your development speed.
You can generate PDF report starting from Word document by using Essential DocIO and Essential PDF. Below steps need to be followed,
For more information about the required assemblies, please refer our UG documentation page. Step 1: Create a Word document from scratchCreate template Word document with merge fields using Essential DocIO. The following code example shows how to create a Word document template with merge fields. C# // Creates a new instance of Word document WordDocument document = new WordDocument(); // Adds one section and one paragraph to the document document.EnsureMinimal(); // Sets page margins to the last section of the document document.LastSection.PageSetup.Margins.All = 72; // Appends text to the last paragraph document.LastParagraph.AppendText("Emp_Id: "); // Appends merge field to the last paragraph document.LastParagraph.AppendField("Emp_Id", FieldType.FieldMergeField); document.LastParagraph.AppendText("\nName: "); document.LastParagraph.AppendField("Name", FieldType.FieldMergeField); document.LastParagraph.AppendText("\nPhone: "); document.LastParagraph.AppendField("Phone", FieldType.FieldMergeField); document.LastParagraph.AppendText("\nCity: "); document.LastParagraph.AppendField("City", FieldType.FieldMergeField); // Saves and closes the WordDocument instance. document.Save("Template.docx"); document.Close();
VB ' Creates an instance of a WordDocument Dim document As New WordDocument() ' Adds one section and one paragraph to the document document.EnsureMinimal() ' Sets page margins to the last section of the document document.LastSection.PageSetup.Margins.All = 72 ' Appends text to the last paragraph. document.LastParagraph.AppendText("Emp_Id: ") ' Appends merge field to the last paragraph document.LastParagraph.AppendField("Emp_Id", FieldType.FieldMergeField) document.LastParagraph.AppendText(vbLf & "Name: ") document.LastParagraph.AppendField("Name", FieldType.FieldMergeField) document.LastParagraph.AppendText(vbLf & "Phone: ") document.LastParagraph.AppendField("Phone", FieldType.FieldMergeField) document.LastParagraph.AppendText(vbLf & "City: ") document.LastParagraph.AppendField("City", FieldType.FieldMergeField) ' Saves and closes the WordDocument instance. document.Save("Template.docx") document.Close()
The generated template document looks as follows. Step 2: Perform Mail mergeThe Mail merge operation replaces the matching merge fields with the respective data. The following code example shows how to perform a simple Mail merge in the generated template document with string array as data source. C# // Opens the template document WordDocument document = new WordDocument("Template.docx"); // Gets the data for Mail merge string[] fieldNames = new string[] { "Emp_Id", "Name", "Phone", "City" }; string[] fieldValues = new string[] { "1001", "Peter", "+122-2222222", "London" }; // Performs the Mail merge document.MailMerge.Execute(fieldNames, fieldValues); // Saves and closes the WordDocument instance. document.Save("WordReport.docx"); document.Close();
VB ' Opens the template document Dim document As New WordDocument("Template.docx") ' Gets the data for Mail merge Dim fieldNames As String() = New String() {"Emp_Id", "Name", "Phone", "City"} Dim fieldValues As String() = New String() {"1001", "Peter", "+122-2222222", "London"} ' Performs the Mail merge document.MailMerge.Execute(fieldNames, fieldValues) ' Saves and closes the WordDocument instance. document.Save("WordReport.docx") document.Close()
The resultant document looks as follows. Step 3: Convert the Word document to PDFThe following code example illustrates how to convert a Word document into PDF document. C# // Opens the template document WordDocument document = new WordDocument("WordReport.docx"); // Creates an instance of the DocToPDFConverter DocToPDFConverter converter = new DocToPDFConverter(); // Converts Word document to PDF document PdfDocument pdfDocument = converter.ConvertToPDF(document); // Saves the report as PDF document pdfDocument.Save("PDFReport.pdf"); // Closes the instance of PDF document object pdfDocument.Close(true); // Closes the instance of Word document object document.Close();
VB ' Opens the template document Dim document As New WordDocument("WordReport.docx") ' Creates an instance of the DocToPDFConverter Dim converter As New DocToPDFConverter() ' Converts Word document into PDF document Dim pdfDocument As PdfDocument = converter.ConvertToPDF(document) ' Saves the report as PDF document pdfDocument.Save("PDFReport.pdf") ' Closes the instance of PDF document object pdfDocument.Close(True) ' Closes the instance of Word document object document.Close()
The generated PDF report looks as follows. The following simple sample with complete code snippets demonstrates on how to generate PDF report starting from Word document using Essential DocIO and PDF. |
2X faster development
The ultimate WPF UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
I will suggest to using ZetPDF to Create, Edit, Convert, Protect or Print PDF documents, without requiring Adobe Acrobat. It's the fastest pdf SKD for .NET applications.
this is very helpful! for beginners and want to save time, I found zetpdf.com i heard a lot of this from my co workers. i tried using it nad it's really convenient and easy to use!
thanks for the information! i recommend using zetpdf.com if you're looking for a very fast and helpful pdf sdk.