←Select platform

DocumentWriterSvgPage Class

Summary
Data for one SVG page to be added to a document file.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public class DocumentWriterSvgPage : DocumentWriterPage 
@interface LTDocumentWriterSvgPage : LTDocumentWriterPage<NSCopying> 
public class DocumentWriterSvgPage extends DocumentWriterPage 
public ref class DocumentWriterSvgPage : public DocumentWriterPage  
class DocumentWriterSvgPage(DocumentWriterPage): 
Remarks

The DocumentWriterSvgPage class derives from DocumentWriterPage and contains the data for one SVG page to be added to a document file. It is used as a parameter to the DocumentWriter.AddPage or DocumentWriter.InsertPage methods used to add the page.

The DocumentWriterSvgPage.SvgDocument property must contain a valid SVG (ISvgDocument) object that contains the visual representation of the page. This SVG object can obtained through multiple sources as explained in LEADTOOLS Document Writers.

DocumentWriterSvgPage.SvgDocument is used as is when DocumentWriter.AddPage or DocumentWriter.InsertPage is called and the framework does not delete it. You must dispose the object when it is no longer used.

The DocumentWriterSvgPage.Image property is optional and is used only when the document being created is PDF with the Image/Text overlay option. To create a PDF document with image/text overlay, perform the following steps:

SVG documents may or may not have a size. If a document has a size, it is stored in the width and height attributes of the root svg element and can be in any coordinate system. An SVG renderer will typically use this value to determine the final bounding rectangle of the document. SVG documents contain a hierarchy of elements. The final transformation (such as position and size) and style (such as color and fill) may depend on the transformation and style of the parent(s) inside the hierarchy. Calculations have to be done to keep track of this information when converting the SVG file. This procedure is defined by LEADTOOLS as flattening the document.

The DocumentWriterSvgPage.Width and DocumentWriterSvgPage.Height properties can be used to set a custom page size in inches. When the values are the default of 0, the framework will obtain the page width and height automatically from the ISvgDocument object set in SvgDocument when AddPage or InsertPage is called. If it is desired to create pages at a custom size, then simply set the values (in inches) in DocumentWriterSvgPage.Width and DocumentWriterSvgPage.Height before calling AddPage or InsertPage.

The LEADTOOLS Document Writer supports creating documents with zero or more empty pages inside them. Use AddPage or InsertPage with an DocumentWriterEmptyPage with the dimension of the empty page set before hand in the DocumentOptions.EmptyPageWidth and DocumentOptions.EmptyPageHeight and its resolution set to DocumentOptions.EmptyPageResolution. As many empty pages as desired can be added in any index desired. To use empty pages, make sure the DocumentOptions.PageRestriction property is set to DocumentPageRestriction.Relaxed.

For more information, refer to PdfDocumentOptions.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
using Leadtools.Ocr; 
 
 
public void DocumentWriterExample() 
{ 
   var inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "test.docx"); 
   var outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf"); 
 
   // Setup a new RasterCodecs object 
   var codecs = new RasterCodecs(); 
   codecs.Options.RasterizeDocument.Load.Resolution = 300; 
 
   // Get the number of pages in the input document 
   var pageCount = codecs.GetTotalPages(inputFileName); 
 
   // Create a new instance of the LEADTOOLS Document Writer 
   var docWriter = new DocumentWriter(); 
 
   // Change the PDF options 
   var pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; 
   pdfOptions.DocumentType = PdfDocumentType.PdfA; 
   docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); 
 
   // Create a new PDF document 
   Debug.WriteLine("Creating new PDF document: {0}", outputFileName); 
   docWriter.BeginDocument(outputFileName, DocumentFormat.Pdf); 
 
   // Loop through all the pages 
   for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
   { 
      // Get the page as SVG 
      Debug.WriteLine("Loading page {0}", pageNumber); 
      var page = new DocumentWriterSvgPage(); 
      page.SvgDocument = codecs.LoadSvg(inputFileName, pageNumber, null); 
 
      // Add the page 
      Debug.WriteLine("Adding page {0}", pageNumber); 
      docWriter.AddPage(page); 
 
      page.SvgDocument.Dispose(); 
   } 
 
   // Finally finish writing the PDF file on disk 
   docWriter.EndDocument(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Writer Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.