#include "l_bitmap.h"
L_LTSVG_API L_INT L_SvgLoadDocument(fileName, docHandle, options)
const L_TCHAR* fileName; |
name of the file to load |
L_SvgNodeHandle* docHandle; |
address of the SVG document handle |
const L_SvgLoadOptions* options; |
pointer to load options |
Loads an SVG document from an SVG file on disk.
Parameter |
Description |
| fileName | Character string containing the name of the file to load. |
| docHandle | Pointer to the L_SvgNodeHandle referencing the target SVG document. |
| options | Optional pointer to a structure containing SVG load options. Pass NULL to use the default options. |
| SUCCESS | The function was successful. |
| < 1 | An error occurred. Refer to Return Codes. |
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
| LTSVG File format DLLs For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Win32, x64, Linux.
| Functions: | L_SvgCreateDocument, L_LoadSvg, L_SvgFreeNode |
| Topics: | Working with SVG |
This example will use the LEADTOOLS Document Writer to create a PDF file from SVG files.
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileNamestatic L_INT CreateSvgPages(L_TCHAR* srcFileName, L_TCHAR* outDir){// Extract all the pages from the source file as SVGFILEINFO 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 documentnRet = 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 SVGnRet = L_SvgSaveDocument(dstFileName, svgOptions.SvgHandle, NULL);// Free the SVG documentL_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 WriterDOCUMENTWRITER_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 SVGL_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 itL_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 writerwprintf(L_TEXT("Adding ...\n"));DOCWRTSVGPAGE svgPage = {0};svgPage.hSvgHandle = flatDocHandle;nRet = L_DocWriterAddPage(hDocument, DOCWRTPAGETYPE_SVG, (L_VOID*)&svgPage);// Free the flat SVG documentif(!isFlat)L_SvgFreeNode(flatDocHandle);}// Free the SVG documentL_SvgFreeNode(docHandle);}// Finish upwprintf(L_TEXT("Finishing ...\n"));nRet = L_DocWriterFinish(hDocument);return nRet;}