←Select platform

SvgDocument Property

Summary
The SVG document representation of the page.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public ISvgDocument SvgDocument { get; set; } 
@property (nonatomic, strong) id<ISvgDocument> svgDocument; 
public ISvgDocument getSvgDocument() 
public void setSvgDocument(ISvgDocument svgDocument) 
public: 
property ISvgDocument^ SvgDocument { 
   ISvgDocument^ get(); 
   void set (    ISvgDocument^ ); 
} 
SvgDocument # get and set (DocumentWriterSvgPage) 

Property Value

An SvgDocument that contains the SVG document representation of the page.

Remarks

The SvgDocument property must contain an ISvgDocument object --it cannot be null. This SVG document is used in the DocumentWriter.AddPage or DocumentWriter.InsertPage methods to create the visual representation of the new page added to the document being created.

The LEADTOOLS Document Writer toolkit will not use the ISvgDocument object after the call to DocumentWriter.AddPage or DocumentWriter.InsertPage returns. This handle needs to be disposed to free the resources associated with it by the user.

The SVG objects can be obtained from multiple sources as explained in LEADTOOLS Document Writers.

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 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.

The LEADTOOLS Document Writer supports creating documents with zero or more empty pages inside them. Simply pass a page of type DocumentWriterEmptyPage to DocumentWriter.AddPage or DocumentWriter.InsertPage methods. The dimension of the empty page must be 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 and in any index desired. To use empty pages, make sure the DocumentOptions.PageRestriction property is set to DocumentPageRestriction.Relaxed.

Example
C#
Java
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:\LEADTOOLS23\Resources\Images"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void documentWriterExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String inputFileName = combine(LEAD_VARS_IMAGES_DIR, "LEADTOOLSEditor.docx"); 
   String outputFileName = combine(LEAD_VARS_IMAGES_DIR, "Example.pdf"); 
 
   // Setup a new RasterCodecs object 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.getOptions().getRasterizeDocument().getLoad().setResolution(300); 
 
   // Get the number of pages in the input document 
   ILeadStream leadStream = LeadStreamFactory.create(inputFileName); 
   int pageCount = codecs.getTotalPages(leadStream); 
 
   // Create a new instance of the LEADTOOLS Document Writer 
   DocumentWriter docWriter = new DocumentWriter(); 
 
   // Change the PDF options 
   PdfDocumentOptions pdfOptions = (PdfDocumentOptions) docWriter.getOptions(DocumentFormat.PDF); 
   pdfOptions.setDocumentType(PdfDocumentType.PDFA); 
   docWriter.setOptions(DocumentFormat.PDF, pdfOptions); 
 
   // Create a new PDF document 
   System.out.printf("Creating new PDF document: %s", outputFileName); 
   docWriter.beginDocument(outputFileName, DocumentFormat.PDF); 
 
   // Loop through all the pages 
   for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) { 
      // Get the page as SVG 
      System.out.printf("Loading page %s", pageNumber); 
      DocumentWriterSvgPage page = new DocumentWriterSvgPage(); 
      page.setSvgDocument(codecs.loadSvg(inputFileName, pageNumber, null)); 
 
      // Add the page 
      System.out.printf("Adding page %s", pageNumber); 
      docWriter.addPage(page); 
 
      page.getSvgDocument().dispose(); 
   } 
 
   // Finally finish writing the PDF file on disk 
   docWriter.endDocument(); 
   assertTrue((new File(outputFileName)).exists()); 
   codecs.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 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.