←Select platform

DocumentWriterSvgPage Class

Data for one SVG page to be added to a document file.
public class DocumentWriterSvgPage : DocumentWriterPage 
@interface LTDocumentWriterSvgPage : LTDocumentWriterPage<NSCopying> 
public class DocumentWriterSvgPage extends DocumentWriterPage 
public ref class DocumentWriterSvgPage : public DocumentWriterPage  
class DocumentWriterSvgPage(DocumentWriterPage): 

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.

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); 
   // Finally finish writing the PDF file on disk 
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(); 
   // 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); 
   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); 
   // Finally finish writing the PDF file on disk 
   assertTrue((new File(outputFileName)).exists()); 

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.