Blank document automatically loaded
When you initialize the library there is always a one page blank document in memory. It is
selected and ready to use by default. This is due to the design of the library. There must
always be at least one document in memory, so if you try to delete that document using the
DeletePages function, the library will automatically re-create a one page blank document.
The blank one page document uses a Letter page size which is 8.5 x 11 inches or 215.9 mm ×
279.4 mm. The page size can be changed using the SetPageSize
New documents automatically selected
Whether you load an existing document using the LoadFromFile function or create a new
document using the NewDocument function, it will automatically be selected in memory and the
documents ID can be retrieved using the SelectedDocument function.
Multiple documents in memory permitted
You can have more than one document in memory and can swap between them using the ID
returned from calls such functions as NewDocument and SelectedDocument. You can also
count all documents in memory using the DocumentCount function and then retrieve each
documents ID or filename using GetDocumentID or GetDocumentFileName. All of the document
management related functions can be seen in the document management section in the
Origin point for drawing operations
The origin has coordinates of “0,0” and is the starting point for finding all other points. The origin
point for a page in a PDF typically starts at a page corner. The default origin for Debenu Quick
PDF Library is the bottom left page corner.
Using the SetOrigin function in Debenu Quick PDF Library you can change the point of origin to
be any page corner (bottom left, top left, top right, bottom right).
By default calling DrawText(10, 10, “Test”) will result in the text being drawn at 10 points in from
the left of the page and 10 points up from the bottom of the page, but if you call SetOrigin(1)
prior to DrawText then the text will be drawn at 10 points in from the left of the page and 10
points down from the top of the page because passing the value 1 to the Origin parameter for
the SetOrigin function changes the origin to top left of the page.
The default point of origin in Adobe Acrobat was the bottom left page corner up until Acrobat
8, at which point Adobe switched the point of origin to the top left page corner. As mentioned
above, you can set Debenu Quick PDF Library to use any page corner in a PDF.
In version 7.25 of Debenu Quick PDF Library we added a new function called NormalizePage
that moves and/or rotates the contents of the page so that subsequent drawing operations are
at the expected position on the page. All the page boundary boxes are adjusted to the physical
size of the page and the page's rotation attribute is reset to zero.
In PDF the coordinate system is called default user space. The default for the size of the unit in
default user space (1/72 inch) is approximately the same as a point, a unit widely used in the
printing industry. It is not exactly the same, however; there is no universal definition of a point.
Using the SetMeasurementUnits function you can change the units for all measurements given
to and returned from the library. The available options are default user space, millimeters and
Unicode, UTF-8 and the DLL and Delphi Editions
Versions of Debenu Quick PDF Library prior to version 8 required that you encode Unicode
characters using UTF-8, however, with the release of version 8 Unicode is handled natively by
the library so UTF-8 encoding and decoding is no longer required.
There are three different ways that fonts can be referenced or stored in PDF files. They are:
Full Font Embedding = Larger file size
Recipient doesn’t need the same font to view or edit the file
Subset Font Embedding = Smaller file size
Recipient doesn’t need the same font to view but does need the same font installed in order to
edit the file
No Font Embedding = Smallest file size
Recipient needs to have same fonts installed
Each option has its merits. As long as option 1 or 2 above when you are building your PDF files,
then you can be sure that when your PDF is rendered or printed the font you’ve specified will
be used. If you use option 3, then the PDF viewer will attempt to locate the specified font on
the local machine but if it cannot be found then it will use a substitute font during the viewing/
When a PDF is displayed on your screen it is rendered in exactly the same fashion as it would
be prior to being printed.
Processing digitally signed PDF files
Any changes that you make to a PDF after it has been digitally signed will invalidate the digital
signature. PDF files that contain digital signatures must be incrementally updated -- meaning
that the contents of the PDF are updated without rewriting the entire file by way of appending
changes to the end of the file. If digitally signed PDF files are not updated this way then the
digital signature will not only be invalidated, but it will be completely broken too.
When using Debenu Quick PDF Library it’s important to note that the combination of
LoadFromFile and SaveToFile does not incrementally update the file. Instead it completely
rewrites the contents of the PDF and breaks the digital signature. If you’re working with a PDF
that has a digital signature and you do not want to break or remove the digital signature, then
you should not use the SaveToFile function.
If you need to modify a PDF that has been digitally signed then you should use the DAOpenFile
and DAAppendFile functions as the DAAppend function does incrementally update PDF files,
which means that the digital signature will be invalidated, but not broken.
Optional Content Groups, Layers and Content Streams: What is the difference?
In version 8 of Debenu Quick PDF Library the functions that used “layer” in the name
were renamed so that they used “content stream” instead. So for example, in 7 and earlier
versions there was a function called NewLayer, but in version 8 and future versions it’s called
We decided to rename these functions due to a naming conflict with Adobe. Here’s the back
In Debenu Quick PDF Library 7 and earlier versions layers and optional content groups do not
refer to the same technology, however, in Adobe Acrobat, they do. Confused? There's a simple
explanation for this anomaly:
A page can have one or more content streams. These content streams are combined into one
long string by the PDF viewer.
When Debenu Quick PDF Library was first developed (about 10 years ago) we called these
individual content streams "layers" as they enabled you to move groups of things on top of
and below other things and each new function in this area included the term layer in its name
(NewLayer, LayerCount, MoveLayer, etc.).
However, in version 1.5 of the PDF specification (after we'd already begun using the term layer
to describe content streams for a few years) Adobe added a new feature called optional content
groups. This new feature was technically referred to as optional content groups (OCGs) in the
PDF specification, but in Adobe Acrobat and Adobe Reader, Adobe elected to use the term
layers instead. And thus the confusion began:
We previously used the term “layers” to describe content streams and Adobe uses the
term “layers” to describe optional content groups.
So to avoid any further question, as of Debenu Quick PDF Library 8, we have renamed all
functions that use the term “layer” to use “content stream” instead. This means that NewLayer is
now called NewContentStream and so on. The names of the Optional Content Group functions
rename the same.
Need Appearances and Form Fields
A form field in a PDF is an interactive element that floats above the actual content of the PDF.
In order for a form field to be displayed it must have an associated appearance stream that tells
the conforming PDF viewer how to render the form fields.
Appearance streams can be generated in advance, using the UpdateAppearanceStream
function, or you can tell the conforming PDF viewer to automatically generate the necessary
appearance streams when the PDF is opened by using the SetNeedAppearances function to
set the NeedAppearances flag to true.
If the NeedAppearances flag is set to false and no appearance stream has been generated in
advance for the form fields, then the form fields will not be shown in the conforming PDF viewer.
After existing form fields have been updated the appearance stream must be updated,
so if NeedAppearances flag is set to false then you will need to make a new call to the
These are the most common tasks for using Debenu Quick PDF Library, but it is not an
exhaustive list, our PDF SDK is capable of far more than is covered here. The sample code
PDF creation deals with creating PDF files programmatically from scratch.
Create a simple PDF
Debenu Quick PDF Library allows you to create new PDF files with very few lines of code. If you
wanted to create a blank document with no content then all you would need to do is make one
simple call to the SaveToFile function and that would save the blank document that is already in
memory to disk. Making a simple PDF with just one line of text is not much harder.
/* Create a simple PDF */
// Set page origin to top left, default
// is the bottom left
// Draw some text on the PDF
QP.DrawText(100, 100, "Hello World");
// Save the new PDF
That’s it. This is your basic building block and you can make your PDF files as simple or as
complex as you need them to be.
Create a complex PDF
Debenu Quick PDF Library lets you add text, images, vector graphics, form fields, annotations
and much more to PDF files. You won’t necessarily need all of these elements in your PDF, but
here’s an example of how some of them fit together.
/* Create a complex PDF */
// Set page origin to top left, default is the bottom left
// Invoice number text
QP.DrawText(55, 65, "Invoice #");
QP.SetTextColor(0, 0.5, 1);
QP.DrawText(140, 65, "1564824");
// Company logo
QP.SetFillColor(0, 0, 0);
QP.SetLineColor(1, 1, 1);
QP.DrawCircle(475, 15, 5, 2);
QP.DrawCircle(490, 20, 10, 2);
QP.DrawCircle(505, 25, 15, 2);
QP.DrawCircle(520, 30, 20, 2);
QP.DrawCircle(535, 35, 25, 2);
QP.DrawCircle(550, 40, 30, 2);
QP.DrawHTMLTextBox(470, 38, 100, 100, "THE<br>CIRCLE<br>COMPANY.");
// Draw some lines to give the invoice structure
QP.SetLineColor(0, 0, 0);
QP.DrawLine(20, 150, 592, 150);
QP.DrawLine(20, 200, 592, 200);
QP.DrawLine(400, 250, 592, 250);
// Text color for body
QP.SetTextColor(0, 0, 0);
// Invoice headings
QP.DrawText(50, 145, "Description");
QP.DrawText(225, 145, "Quantity");
QP.DrawText(375, 145, "Unit Price");
QP.DrawText(525, 145, "Amount");
// Invoice content
QP.DrawText(50, 195, "Fictional Product 1.0");
QP.DrawText(245, 195, "5");
QP.DrawText(385, 195, "199.00");
QP.DrawText(532, 195, "995.00");
// Invoice totals
QP.DrawText(455, 225, "Sub-Total");
QP.DrawText(532, 225, "$995.00");
QP.DrawText(455, 245, "Tax");
QP.DrawText(532, 245, "$0.00");
QP.DrawHTMLText(455, 270, 100, "<b>Total</b>");
QP.DrawHTMLText(532, 270, 100, "<b>$995.00</b>");
// Payment due date
QP.DrawHTMLText(50, 400, 100, "<b>Due Date: Today</b>");
// Save the invoice
Convert this code into the language of your choice and then run it. With not too much difficulty at
all you can create a nifty invoice.
Create a PDF/A document
Debenu Quick PDF Library lets you create PDF/A-1b compliant PDF files with a single call to
SetPDFAMode. Currently this only works when creating new PDF documents, so it won’t work
if you try to load an existing document using LoadFromFile. Only certain PDF features are
/* Create a new PDF/A document */
// Call SetPDFAMode to tell Debenu Quick PDF Library that you want to
// create a PDF/A document. Specify which version of PDF/A it
// should use.
// Set page origin for drawing co-ordinates to top left of page
// Now lets add a bunch of different objects to the PDF which
// are supported by the PDF/A specification.
// Add some document properties to the PDF
QP.SetInformation(1, "John Smith");
QP.SetInformation(2, "The Life and Times of John Smith");
QP.SetInformation(3, "A very special book");
QP.SetInformation(4, "book, paperback, ebook");
QP.SetInformation(5, "Mother Earth");
// Embed a font that will be used for drawing some sample text
var fontID1 = QP.AddTrueTypeFont("Times New Roman", 1);
// Select the font using its font ID
// Draw normal text
QP.DrawText(25, 25, "This text was drawn using the DrawText function.");
Debenu Quick PDF Library supports converting images to PDF, PDF to images and PDF to text.
Convert an image to PDF
Converting images to PDF files is quite a simple task.
/* Image to PDF conversion */
// Load your image into memory
// Get width, height of the image
lWidth = QP.ImageWidth();
lHeight = QP.ImageHeight();
// Reformat the size of the page in the selected document
// Draw the image onto the page using the specified width/height
QP.DrawImage(0, lHeight, lWidth, lHeight);
// Store the updated PDF where you like
Convert a PDF to an image
When a PDF is displayed it is actually rendered as an image.
/* PDF to image conversion */
// Load the sample file
// Calculate the number of pages
iNumPages = QP.PageCount();
// Render each page of the document to a separate file.
// To view the images open the output folder.
QP.RenderDocumentToFile(72, 1, iNumPages, 0, "image.bmp");
Convert a PDF to text
Extracting text from a PDF can at times be a difficult task. If a PDF has been scanned from
paper and no OCR process has been performed then the page in a PDF might display what
looks like text but in the objects in the PDF no text actually exists, just an image. You can use
the HasFontResources function to check if a PDF has any text. Extracting text from a PDF that
does indeed contain text objects is a relatively straight forward process using one of the text
/* PDF to text conversion */
// Load the test file and Iterate through each page in the
// PDF and append it to a text file.
strInputFilePath = "apply_ fingerprint.pdf";
// Calculate the number of pages
iNumPages = QP.PageCount();
strText = "";
nPage = 0;
// Loop through each page in the PDF and extract the text from the page
for(nPage = 1; nPage<=iNumPages; nPage++)
strText = strText + QP.ExtractFilePageText(strInputFilePath, "", nPage, 0);
// Write all the data to a file
s = oFSO.CreateTextFile("extracted_text.txt", 1);
Documents you may be interested
Documents you may be interested