Take the following steps to start a project and to add some code that uses SVG to convert a Microsoft Word DOCX file to PDF:
In the Solution Explorer window, right-click on the References folder, and select "Add Reference..." from the context menu. In the "Add Reference" dialog box, select the ".NET" tab, browse to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" folder, and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
Add the following lines at the beginning of the file:
using System.IO;using System.Diagnostics;using Leadtools;using Leadtools.Codecs;using Leadtools.Forms.DocumentWriters;
Imports System.IOImports System.DiagnosticsImports LeadtoolsImports Leadtools.CodecsImports Leadtools.Forms.DocumentWriters
Add the following code snippet to the Main method:
var inFileName = @"C:\users\Public\Documents\LEADTOOLS Images\Leadtools.docx";var format = DocumentFormat.Pdf;// Create the output file namevar dir = Path.GetDirectoryName(inFileName);var outFileName = Path.Combine(dir, "DocumentWriterTutorial." + DocumentWriter.GetFormatFileExtension(format));var codecs = new RasterCodecs();// Set 300 as the default resolution for loading document filescodecs.Options.RasterizeDocument.Load.Resolution = 300;// Get the number of pages of the input filevar pageCount = codecs.GetTotalPages(inFileName);Console.WriteLine("Number of pages {0}", pageCount);// Create an instance of the LEADTOOLS DocumentWritervar docWriter = new DocumentWriter();// Change this file to create a PDF file with overlay imagevar imageOverText = false;// Set the optionsif (format == DocumentFormat.Pdf){// If PDF, set to PDF/Avar pdfOptions = docWriter.GetOptions(format) as PdfDocumentOptions;pdfOptions.DocumentType = PdfDocumentType.PdfA;if (imageOverText)pdfOptions.ImageOverText = true;docWriter.SetOptions(format, pdfOptions);}// Begin a new PDF documentdocWriter.BeginDocument(outFileName, format);// Add the pagesfor (var pageNumber = 1; pageNumber <= pageCount; pageNumber++){// Load the page as SVGConsole.WriteLine("Loading page {0}", pageNumber);var page = new DocumentSvgPage();page.SvgDocument = codecs.LoadSvg(inFileName, pageNumber, null);if (imageOverText){// If we are using image/text, then load the overlay raster imagepage.Image = codecs.Load(inFileName, pageNumber);}// Add the page to the current documentConsole.WriteLine("Adding page {0}", pageNumber);docWriter.AddPage(page);if (page.SvgDocument != null)page.SvgDocument.Dispose();if (page.Image != null)page.Image.Dispose();}// Done, finishConsole.WriteLine("Converting to final format");docWriter.EndDocument();codecs.Dispose();Console.WriteLine("Viewing the result");// Open the document in the default viewerProcess.Start(outFileName);
Dim inFileName As String = "C:\users\Public\Documents\LEADTOOLS Images\Leadtools.docx"Dim format As DocumentFormat = DocumentFormat.Pdf' Create the output file nameDim dir As String = Path.GetDirectoryName(inFileName)Dim outFileName As String = Path.Combine(dir, "DocumentWriterTutorial." + DocumentWriter.GetFormatFileExtension(format))Dim codecs As New RasterCodecs' Set 300 as the default resolution for loading document filescodecs.Options.RasterizeDocument.Load.Resolution = 300' Get the number of pages of the input fileDim pageCount As Integer = codecs.GetTotalPages(inFileName)Console.WriteLine("Number of pages {0}", pageCount)' Create an instance of the LEADTOOLS DocumentWriterDim docWriter As New DocumentWriter()' Change this file to create a PDF file with overlay imageDim imageOverText As Boolean = False' Set the optionsIf format = DocumentFormat.Pdf Then' If PDF, set to PDF/ADim pdfOptions = DirectCast(docWriter.GetOptions(format), PdfDocumentOptions)' pdfOptions.DocumentType = PdfDocumentType.PdfAIf imageOverText Then pdfOptions.ImageOverText = TruedocWriter.SetOptions(format, pdfOptions)End If' Begin a new PDF documentdocWriter.BeginDocument(outFileName, format)' Add the pagesFor pageNumber As Integer = 1 To pageCount' Load the page as SVGConsole.WriteLine("Loading page {0}", pageNumber)Dim page As New DocumentSvgPage()page.SvgDocument = codecs.LoadSvg(inFileName, pageNumber, Nothing)If imageOverText Then' If we are using image/text, then load the overlay raster imagepage.Image = codecs.Load(inFileName, pageNumber)End If' Add the page to the current documentConsole.WriteLine("Adding page {0}", pageNumber)docWriter.AddPage(page)If Not IsNothing(page.SvgDocument) Then page.SvgDocument.Dispose()If Not IsNothing(page.Image) Then page.Image.Dispose()Next' Done, finishConsole.WriteLine("Converting to final format")docWriter.EndDocument()codecs.Dispose()Console.WriteLine("Viewing the result")' Open the document in the default viewerProcess.Start(outFileName)
Build and Run the program to test it.
|
Products |
Support |
Feedback: Tutorial: Document Writers Tutorial |
Introduction |
Help Version 19.0.2017.6.21
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.