Hello world — your first PDF application with C#
Before we starting this tutorial make sure that you've read through the previous tutorial which explains how to get up and running with C# and Debenu Quick PDF Library.
Step By Step
This example uses the ActiveX edition of Debenu Quick PDF Library.
To begin with add a button to your Windows Forms Application. Double-click the button to add an OnClick event, and fill in the following event code.
Lets start. Create an instance of Debenu Quick PDF Library.
DebenuPDFLibraryAX01211.PDFLibrary QP = new DebenuPDFLibraryAX01211.PDFLibrary();
Before you can successfully make calls to functions in the PDF API you will need to unlock the library by calling the UnlockKey function with your license key. You can also check the type of license that you're using by calling the LicenseInfo function.
int result = QP.UnlockKey("your_license_key");
if (result == 1)
{
When an instance of Debenu Quick PDF Library is initiated a blank document is automatically created and loaded into memory, so it's not necessary to create a new document before starting to call drawing commands.
First we'll set the origin for co-orindates to be the top left corner of a page using the SetOrigin function.
Now we'll draw some text onto the PDF file using the DrawText function. We'll also add a link to the document using the AddLinkToWeb function.
Then save the file to disk using the SaveToFile function. Change the path in the SaveToFile function to an existing folder on your computer.
QP.SetOrigin(1);
QP.DrawText(100, 100, "Hello world from C#");
QP.DrawText(300, 100, "http://www.quickpdflibrary.com/");
QP.AddLinkToWeb(290, 85, 190, 20, "http://www.quickpdflibrary.com/", 1);
QP.SaveToFile("HelloCSharpWorld.pdf");
Display an error message if the library could not be unlocked.
}
else
{
MessageBox.Show("Sorry, but the license key you provided could not be validated.");
}
That's all there is to it. In this sample you learnt how to register the license key, create a blank PDF, draw text on the PDF and then save the PDF to disk.
Now all you need to do is run your new application and click on the button to see this code in action. Good luck!
The full code for this sample has been provided below.
Full Sample Code
DebenuPDFLibraryAX01211.PDFLibrary QP = new DebenuPDFLibraryAX01211.PDFLibrary();
int result = QP.UnlockKey("your_license_key");
if (result == 1)
{
QP.SetOrigin(1);
QP.DrawText(100, 100, "Hello world from C#");
QP.DrawText(300, 100, "http://www.quickpdflibrary.com/");
QP.AddLinkToWeb(290, 85, 190, 20, "http://www.quickpdflibrary.com/", 1);
QP.SaveToFile("HelloCSharpWorld.pdf");
}
else
{
MessageBox.Show("Sorry, but the license key you provided could not be validated.");
}
Congratulations! You've created your first PDF application using C# and Debenu Quick PDF Library.
Let us know what you think
We provide code samples to give you a good idea of how to use the Debenu Quick PDF Library with the language of your choice. There is a steadily growing collection of code samples to get you started, but if you suggestions for other samples you would like to see, please let us know.