#include "l_bitmap.h"
L_LTFIL_API L_INT L_LoadSvgMemory(pBuffer, pOptions, nBufferSize, pLoadOptions, pFileInfo)
Loads a page from an image, document or vector data as an SVG file.
Pointer to the file in memory to be checked.
Pointer to a structure that contains the options used for loading SVG files. This can be NULL to use the default options.
Size of the file in memory (in bytes).
Pointer to extended load options.
Pointer to optional extended load options. Pass NULL to use the default load options.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Support for loading as SVG is only available in Document and Medical Imaging toolkits.
Before calling this function, you may need to get or set file information, such as the page number of a multipage file or the resolution of a PCD file. Refer to Getting and Setting File Information.
Note: More options are available in the LOADFILEOPTION structure.
Use this function to load a page from any supported image, document or vector file as SVG (Scalable Vector Graphics).
The SVG loaded by this function will be returned in the LOADSVGOPTIONS structure.
You must check the resulting SVG document flatness and perform the necessary operation before continuing.
For more information, refer to L_LoadSvg.
Required DLLs and Libraries
LTSVG
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.
This example will save an SVG document to a memory buffer and reload it.
// read the file into the buffer. The error checking is reduced for clarity
L_INT ReadFileIntoBuffer(L_UCHAR* buffer, L_OFFSET bufferSize, L_TCHAR* fileName)
{
DWORD bytesRead;
HANDLE hFile = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
return ERROR_FILENOTFOUND;
ReadFile(hFile, buffer, (DWORD)bufferSize, &bytesRead, NULL);
CloseHandle(hFile);
return SUCCESS;
}
L_INT LoadSvgMemoryExample(L_VOID)
{
L_INT ret = SUCCESS;
L_UCHAR* buffer; /* Pointer to the data in memory */
L_TCHAR* srcFileName = MAKE_IMAGE_PATH(TEXT("Leadtools.pdf"));
FILEINFO fileInfo;
memset(&fileInfo, 0, sizeof(FILEINFO));
fileInfo.uStructSize = sizeof(FILEINFO);
LOADFILEOPTION loadFileOption;
L_GetDefaultLoadFileOption(&loadFileOption, sizeof(LOADFILEOPTION));
loadFileOption.PageNumber = 1;
ret = L_FileInfo(srcFileName, &fileInfo, sizeof(FILEINFO), 0, NULL);
if(ret != SUCCESS)
return ret;
// allocate a memory buffer large enough to contain the file
L_SIZE_T bufferSize = (L_SIZE_T)fileInfo.SizeDisk;
buffer = (L_UCHAR*)malloc(bufferSize);
if(!buffer)
return ERROR_NO_MEMORY;
ret = ReadFileIntoBuffer(buffer, fileInfo.SizeDisk, srcFileName);
if(ret != SUCCESS)
{
free(buffer);
return ret;
}
// Check if the file can be loaded as SVG
L_BOOL canLoadSvg = TRUE;
ret = L_CanLoadSvgMemory(buffer, &canLoadSvg, bufferSize, &loadFileOption, &fileInfo);
if(ret != SUCCESS)
{
free(buffer);
return ret;
}
if(canLoadSvg)
{
// Load the file
LOADSVGOPTIONS options;
memset(&options, 0, sizeof(LOADSVGOPTIONS));
options.uStructSize = sizeof(LOADSVGOPTIONS);
ret = L_LoadSvgMemory(buffer, &options, bufferSize, &loadFileOption, &fileInfo);
// Save the result
if(ret == SUCCESS)
{
ret = L_SvgSaveDocument(MAKE_IMAGE_PATH(TEXT("Leadtools.pdf.svg")), options.SvgHandle, NULL);
L_SvgFreeNode(options.SvgHandle);
}
}
return ret;
}