dreamsys software

DreamSys Free PDF Library (Text and Image to PDF)

Download DreamSys Free PDF Library
The DreamSys PDF Library is free for personal use only.
Need a license to use commercially?

The DreamSys Free PDF Library is a DLL that can convert images to PDF. You can also create text pages and add text to your images. The image types supported in the current version are TIFF, JPG (JPEG) and BMP (bitmap). The images can be loaded as a callback so that they aren't loaded into memory until they are written to disk so that they can be freed and large PDFs can be written using a minimal amount of memory. You can create multiple chapters (PDF Sections) 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. This API is also thread safe, you can create multiple PDFs on separate threads and they will not conflict.

You can freely use this API in your own programs as long as they are public and freely available. If you want to use this code in your own business applications, you can for a small fee, click the "buy now" button at the top of the page.

Included in the zip file is a set of C++ wrapper classes that use the C library to make it easier to integrate into your applications. The following are a couple examples of how to use the PDF library to convert images to PDFs:

 * This first example shows you how to use the C++ wrapper classes to easily
 * generate a PDF from a JPG, TIFF, and BMP file.  It shows how to create a
 * blank text page and add text to it.
 * It also shows how to add text to an image page.
void PdfTest1()
		//Create the PDF object.
		dreamsys::DreamSysPDF pdf("My Title", "Rocky's Test App");

		//Add a section to the PDF.  This is a PDF bookmark.  It's index will be 0.
		pdf.addSection("Section One");

		//Add a sectond section to the PDF.  It's index will be 1
		pdf.addSection("Section Two");

		//Add a TIFF file to section at index 0.
		pdf.addImagePage(0, TYPE_TIFF, "test.tif");

		//Add a font to the PDF, type is Arial and the name we use for it is "AR".
		pdf.addType1Font("AR", "Arial");

		//Create a blank text page, size 200x200.
		pdf.addTextPage(0, 200, 200);

		//Create a text object, and have it use the "AR" font.
		dreamsys::PDFText txt("This is some test text.", "AR");

		//Put the text at location 20/100
		txt.setLocation(20, 100);

		//Add this text object to the text page. (section index 0, page index 1)
		pdf.addText(0, 1, txt);

		//Add a BMP file to section at index 0.
		pdf.addImagePage(0, TYPE_BMP, "test.bmp");

		//Add a JPG file to section at index 0.
		pdf.addImagePage(0, TYPE_JPG, "test2.jpg");

		//Load a jpg from a file to test adding a file by a memory buffer.
		FILE *fp = fopen("test2.jpg", "rb");

		if (!fp)
			throw dreamsys::PDFException("File not found, create test files...");

		fseek(fp, 0, SEEK_END);
		int fsz = (int)ftell(fp);
		fseek(fp, 0, SEEK_SET);
		byte *b = new byte[fsz];

		fread(b, fsz, 1, fp);

		//Add the jpg by a loaded memory buffer.
		//Add it to the second section (index 1)
		pdf.addImagePage(1, TYPE_JPG, b, fsz);

		//Set the layout to be single page.

		//Set the page mode to not show any of the left side bars.

		//Save the PDF and show the result (0 is DSSPDF_OK).
		printf("Save result: %d\r\n", pdf.save("test1.pdf"));
	catch(dreamsys::PDFException &e)
		printf("ERROR! %s\r\n", e.getMsg().c_str());
		printf("UNKNOWN ERROR!\r\n");

As you can see, the library is very easy to use with the C++ wrapper classes, it is also pretty simple to use the C API directly, here is an example:

 * This second example shows you how to use the C API directly to easily generate a
 * PDF from a JPG, TIFF, and BMP file.  It shows how to create a blank text page and
 * add text to it.  It also shows how to add text to an image page.
void PdfTest2()
	//Create a PDF.
	PDF_HANDLE hPdf = DSSPDF_Create("My PDF", "Rocky's Producer");

	//Add a section to the PDF.
	SECTION_HANDLE hSec = DSSPDF_AddSection(hPdf, "Section 1");
	PAGE_HANDLE img1Page = DSSPDF_AddImageFilePage(hSec, TYPE_TIFF, "test.tif");

	//Create a text only page of size 8.5x11 inches.
	PAGE_HANDLE pi = DSSPDF_AddTextOnlyPage(hSec,  72 * 8.5, 72 * 11);

	//Add a font, use the name F1.
	DSSPDF_AddType1Font(hPdf, "F1", "Times-Bold", "WinAnsiEncoding");

	//Create some test text.
	TEXT_HANDLE pt = DSSPDF_TextCreate("Testing Text...");

	//Set the font of this text object.
	DSSPDF_TextSetFont(pt, "F1", 48);

	//Add this text to the text only page.
	DSSPDF_AddTextToPage(hPdf, pi, pt);

	//Create some more text.
	pt = DSSPDF_TextCreate("Test Image Overlay Text.");
	DSSPDF_TextSetLocation(pt, 20, 500);
	DSSPDF_TextSetRGB(pt, 1, 0, 0);
	DSSPDF_TextSetFont(pt, "F1", 16);

	//Add this text to the image as an overlay.  Add it by index.
	DSSPDF_AddTextToPageByIndex(hPdf, hSec, 0, pt);

	//Create more text.
	pt = DSSPDF_TextCreate("Testing Text Type Two... This\nis some very long text.");
	DSSPDF_TextSetLocation(pt, 100, 500);
	DSSPDF_TextSetRGB(pt, 0, 0, 1);
	DSSPDF_TextSetFont(pt, "F1", 24);

	//Add this text to the text only page as well..
	DSSPDF_AddTextToPage(hPdf, pi, pt);

	//A simple one liner.
	pt = DSSPDF_TextCreate("Just one line");
	DSSPDF_TextSetLocation(pt, 100, 700);
	DSSPDF_TextSetRGB(pt, 1, 0, 0);
	DSSPDF_TextSetFont(pt, "F1", 8);

	//Add this to the image page as well.
	DSSPDF_AddTextToPage(hPdf, img1Page, pt);

	//Create another section.
	hSec = DSSPDF_AddSection(hPdf, "Section 2");

	//Add a JPG file to the PDF.
	DSSPDF_AddImageFilePage(hSec, TYPE_JPG, "test.jpg");

	//Add a BMP file to the PDF.
	DSSPDF_AddImageFilePage(hSec, TYPE_BMP, "test.bmp");

	//Add more page text...
	DSSPDF_AddTextToPageByIndex(hPdf, hSec, 1, pt);

	//Set some of the PDF properties...
	DSSPDF_SetAuthor(hPdf, "Rocky D. Pulley");
	DSSPDF_SetSubject(hPdf, "Testing DLL");
	DSSPDF_SetKeywords(hPdf, "this, is, a, test, PDF");
	DSSPDF_SetPageMode(hPdf, "UseOutlines");

	//Save the file.
	int ret = DSSPDF_SaveToFileName(hPdf, "test2.pdf");

	//Print the return code of save (0 is good).
	printf("return value: %d\n", ret);

The above examples both show how to save the PDF to a file. The PDF Library is more flexible than this, it also supports using your own function for writing data, this can be used to write data to an output stream (ostream), a socket, or any other type of output. Here is an example of how it is used internally to write to a file:

	//The callback function for writing is defined as follows:
	typedef int (*WriteDataProc)(void *, byte *, int);

	//Here is how you would write your own function to use as the callback:
	int FileWriter(void *ud, byte *data, int size)
		if (fwrite(data, 1, size, (FILE *)ud) != size)

		return DSSPDF_OK;

	//Now to use your new callback function in your code, you would do something like this:
		PDF_RESULT result;
		FILE *fp = fopen(fileName, "wb");

		if (!fp)

		//pass the file pointer as the user data parameter.
		result = DSSPDF_SaveToWriter(hPdf, FileWriter, fp);


		return result;

Questions or comments on the API? Please feel free to contact us if you need help using the API or have additional questions. As stated before, the library supports jpg2pdf, tiff2pdf, and bmp2pdf as well as text2pdf, let us know if there are any other formats that you wish to have supported.

Blog Entries
Blob Entry 1
Blob Entry 2
Blob Entry 3
Blob Entry 4
Blob Entry 5
Blob Entry 6