L_SvgLoadDocument

#include "l_bitmap.h"

L_LTSVG_API L_INT L_SvgLoadDocument(fileName, docHandle, options)

Loads an SVG document from an SVG file on disk.

Parameters

const L_TCHAR* fileName

Character string containing the name of the file to load.

L_SvgNodeHandle* docHandle

Pointer to the L_SvgNodeHandle referencing the target SVG document.

const L_SvgLoadOptions* options

Optional pointer to a structure containing SVG load options. Pass NULL to use the default options.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

Support for SVG is available in Document and Medical Imaging toolkits.

To get and set information on the document bounds and resolution refer to SVG Size, Bounds and Flat.

Use L_LoadSvg to load other compatible file formats (like PDF, Doc / DocX, etc.) as SVG.

When the SVG document data is no longer needed, you must call L_SvgFreeNode to free storage allocated for the SVG document.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example will use the LEADTOOLS Document Writer to create a PDF file from SVG files.

static L_INT CreateSvgPages(L_TCHAR* srcFileName, L_TCHAR* outDir) 
{ 
   // Extract all the pages from the source file as SVG 
   FILEINFO fileInfo; 
   memset(&fileInfo, 0, sizeof(fileInfo)); 
   fileInfo.uStructSize = sizeof(FILEINFO); 
   L_INT nRet = L_FileInfo(srcFileName, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL); 
   if(nRet == SUCCESS) 
   { 
      L_INT pageCount = fileInfo.TotalPages; 
 
      for (L_INT pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
      { 
         LOADSVGOPTIONS svgOptions = {0}; 
         svgOptions.uStructSize = sizeof(LOADSVGOPTIONS); 
 
         LOADFILEOPTION loadOptions = {0}; 
         L_GetDefaultLoadFileOption(&loadOptions, sizeof(LOADFILEOPTION)); 
         loadOptions.PageNumber = pageNumber; 
 
         // Load as SVG from source document 
         nRet = L_LoadSvg(srcFileName, &svgOptions, &loadOptions); 
 
         L_TCHAR dstFileName[L_MAXPATH] = {0}; 
         wsprintf(dstFileName, L_TEXT("%s\\Page%d.svg"), outDir, pageNumber); 
 
         L_TCHAR msg[1024] = {0}; 
         wsprintf(msg, L_TEXT("Saving to: %s\n"), dstFileName); 
         wprintf(msg); 
 
         // Save it to disk as SVG 
         nRet = L_SvgSaveDocument(dstFileName, svgOptions.SvgHandle, NULL); 
 
         // Free the SVG document 
         L_SvgFreeNode(svgOptions.SvgHandle); 
      } 
 
      return pageCount; 
   } 
 
   return 0; 
} 
 
L_INT SvgLoadDocumentExample(L_VOID) 
{ 
   L_INT nRet = SUCCESS; 
   L_TCHAR srcFileName[L_MAXPATH] = MAKE_IMAGE_PATH(TEXT("Leadtools.doc")); 
   L_TCHAR outDir[L_MAXPATH] = MAKE_IMAGE_PATH(TEXT("TempSvgPages")); 
   CreateDirectory(outDir, NULL); 
   L_INT pageCount = CreateSvgPages(srcFileName, outDir); 
 
   // Create a PDF document using Document Writer 
   DOCUMENTWRITER_HANDLE hDocument = NULL; 
   nRet = L_DocWriterInit(&hDocument, 
                           MAKE_IMAGE_PATH(L_TEXT("Output.pdf")),  
                           DOCUMENTFORMAT_PDF, 
                           NULL, 
                           NULL, 
                           NULL); 
 
   for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
   { 
      // Load this SVG 
      L_TCHAR pageFileName[L_MAXPATH] = {0}; 
      wsprintf(pageFileName, L_TEXT("%s\\Page%d.svg"), outDir, pageNumber); 
 
      L_TCHAR msg[1024] = {0}; 
      wsprintf(msg, L_TEXT("Loading: %s\n"), pageFileName); 
      wprintf(msg); 
 
      L_SvgNodeHandle docHandle = NULL; 
      nRet = L_SvgLoadDocument(pageFileName, &docHandle, NULL); 
      if(nRet == SUCCESS) 
      { 
         L_SvgNodeHandle flatDocHandle = docHandle; 
 
         // Check if we need to flat it 
         L_BOOL isFlat = FALSE; 
         L_SvgIsFlatDocument(docHandle, &isFlat); 
         if (!isFlat) 
            L_SvgFlatDocument(docHandle, &flatDocHandle, NULL); 
         L_SvgBounds bounds = {0}; 
         L_SvgGetBounds(flatDocHandle, &bounds, sizeof(L_SvgBounds)); 
         if (!bounds.IsValid) 
            L_SvgCalculateBounds(flatDocHandle, FALSE); 
 
         // Add it to the document writer 
         wprintf(L_TEXT("Adding ...\n")); 
 
         DOCWRTSVGPAGE svgPage = {0}; 
         svgPage.hSvgHandle = flatDocHandle; 
         nRet = L_DocWriterAddPage(hDocument, DOCWRTPAGETYPE_SVG, (L_VOID*)&svgPage); 
 
         // Free the flat SVG document 
         if(!isFlat) 
            L_SvgFreeNode(flatDocHandle); 
      } 
      // Free the SVG document 
      L_SvgFreeNode(docHandle); 
   } 
   // Finish up 
   wprintf(L_TEXT("Finishing ...\n")); 
   nRet = L_DocWriterFinish(hDocument); 
   return nRet; 
} 

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

LEADTOOLS SVG C API Help