|
dreamsys software |
|
DreamSys Tiff to PDF API
Download DreamSys Tiff to PDF API
The DreamSys PDF API is a DLL that can convert TIFF images into a PDF. You can create multiple chapters (PDF Section) to organize your images, this will create bookmarks in the PDF to link to specific pages. The API is written in C++, but can be used in an application written in C, C++, C#, VB, Java or any other language that allows you to import functions from a DLL.
The API will not load the actual TIFF data into memory until it is time to write that TIFF to the file, so it can handle very large PDFs while using very little memory.
This API is also thread safe, you can create multiple PDFs on separate threads and they will not conflict.
//Create a PDF object for tiff 2 pdf conversion...
PDF_HANDLE hPdf = DSSPDF_New("My PDF", "Rocky's Producer");
//Create a section (bookmark in the pdf) and add 2 pages to it.
SECTION_HANDLE hSec = DSSPDF_AddSection(hPdf, "Section 1");
DSSPDF_AddFilePage(hSec, "c:\\test1.tif");
DSSPDF_AddFilePage(hSec, "c:\\test2.tif");
//Create another section and add 2 pages to it.
hSec = DSSPDF_AddSection(hPdf, "Section 2");
DSSPDF_AddFilePage(hSec, "c:\\test3.tif");
DSSPDF_AddFilePage(hSec, "c:\\test4.tif");
//Save the PDF
DSSPDF_Save(hPdf, "c:\\test.pdf");
//Free the PDF data (this includes all the sections as well).
DSSPDF_Free(hPdf);
If you have need of a more flexible way of loading your TIFF files, you can call the function DSSPDF_AddPage and use the TIFF_DATA data structure. The function DSSPDF_AddFilePage makes use of this. Remember, you must make this code threadsafe if you want the API to remain thread safe! As an example of how to use this method, I will show you the implementation of the AddPage function.
//First you create a class (or set of functions) to wrap your way of loading
//the TIFF files. In this case, we load from a file...
class TiffFileReader
{
public:
TiffFileReader(const string &fn);
~TiffFileReader()
{
delete[] data;
}
static int GetTiff(void *p, byte **dat, int *size);
static void FreeTiff(void *p);
private:
int dataSize;
byte *data;
string fileName;
};
TiffFileReader::TiffFileReader(const string &fn)
{
fileName = fn;
}
int TiffFileReader::GetTiff(void *p, byte **dat, int *size)
{
TiffFileReader *tr = (TiffFileReader *)p;
FILE *fp = fopen(tr->fileName.c_str(), "rb");
if (!fp)
return 0;
fseek(fp, 0, SEEK_END);
*size = (int)ftell(fp);
tr->data = new byte[*size];
*dat = tr->data;
fseek(fp, 0, SEEK_SET);
fread(tr->data, 1, *size, fp);
fclose(fp);
return 1;
}
void TiffFileReader::FreeTiff(void *p)
{
TiffFileReader *tr = (TiffFileReader *)p;
delete tr;
}
Now, this is how we will use this method: TIFF_DATA *td = new TIFF_DATA(); td->getTiff = TiffFileReader::GetTiff; td->freeTiff = TiffFileReader::FreeTiff; TiffFileReader *tr = new TiffFileReader(fileName); td->data = tr; DSSPDF_AddPage(td); Questions or comments on the API? Please feel free to contact us if you need help using the API or have additional questions, or check the forums. |