Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

Using with C# in VS 2008

Question

I am investigating using QuickPDF to work within an application. I have written some scan code to create a PDF from scanning. So each page is an image in effect. I want a very simple viewer. It will show a page at a time. It allows the user to "delete" the page from the pdf and rotate the page 90degrees at a time. If the user has their scanner set to landscape then I scroll through the scanned in PDF rotating each page 90deg clockwise.

This was written in a previous app (in Delphi using a VCL library). I now need to add the same functionality within a c# app in 2008. So a learning curve for me. I have most of it written and looking around for a rendering library I came across this library.

I found the sample code using DC to render a page from the loaded PDF file. I have tried to google some info on how to use this function within a WinForm.

I have an area with a PanelControl. Is it possible to getDC of the panel and render the page to that? Or should I be using another component? Or am I barking up the wrong tree.

Answer

I have done more digging and in searching for PictureBox I saw some sample code for the "DA" series of functions. I have translated this and have an initial set of code that still needs some work to get it to display well. But it is a start. So for anyone else checking out the library using VS & c#

private void DisplayPage()
{
//let's try quick pdf
//Using the DLL solution where the *.cs file is included with the project
DLL myDLL = new DLL("QuickPDFDLL0721.dll");
int InstanceID;
InstanceID = myDLL.QuickPDFCreateLibrary();
if (myDLL.QuickPDFUnlockKey(InstanceID, "temp code that came with trial") == 1)
{
//scanned in pdf's filename is stored in string. Need to convert for library
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
Byte[] BytesMessage = UTF8.GetBytes(ScannedFile);
//Now load the whole file to get at page
myDLL.QuickPDFLoadFromFile(InstanceID, BytesMessage);
myDLL.QuickPDFSelectPage(InstanceID, CurrentPageNo);

int dpi = CurrentZoom;
double pWidth = myDLL.QuickPDFPageWidth(InstanceID);
double pHeight = myDLL.QuickPDFPageHeight(InstanceID);
// Calculate Dimension of final output image
Bitmap b = new Bitmap(Convert.ToInt32(pWidth * dpi), Convert.ToInt32(pHeight * dpi));

// This will Draw render image on GDI
using (Graphics g = Graphics.FromImage(b))
{
IntPtr dc = g.GetHdc();
int ans = myDLL.QuickPDFRenderPageToDC(InstanceID, 150, CurrentPageNo,(int)dc);
g.ReleaseHdc(dc);
}

// Assign rendered image to PictureBox Control which will display PDF on Windows Form.
pictureBox1.Image = b;
pictureBox1.BorderStyle = BorderStyle.Fixed3D;
}
myDLL.QuickPDFReleaseLibrary(InstanceID);
//Show on screen which page we are displaying
teGoToPage.Text = CurrentPageNo.ToString();
}

© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum