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

Rendering page to viewer consolidating differing measuring units?

Question
I am trying to write a simple viewer using QuickPDF. I am using vs 2008 with C#. I have a winform with a PictureBox filling the client area. I want to display the page into the picture box so that it fills the box (keeping proportion).

I have found some sample code but this doesn't seem to do what I want. I also have an issue with the fact that different elements that seem to be needed use different measuring units.

Can anyone put me in the right direction please.

My current code is:

private int CurrentZoom = 76;
private int CurrentDPI = 96;

private void DisplayPage()
{

//let's try quick pdf
DLL myDLL = new DLL("QuickPDFDLL0721.dll");
int InstanceID;
InstanceID = myDLL.QuickPDFCreateLibrary();
if (myDLL.QuickPDFUnlockKey(InstanceID, "trial license") == 1)
{
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
Byte[] BytesMessage = UTF8.GetBytes(ScannedFile);
myDLL.QuickPDFLoadFromFile(InstanceID, BytesMessage);
myDLL.QuickPDFSelectPage(InstanceID, CurrentPageNo);
myDLL.QuickPDFSetMeasurementUnits(InstanceID, 0);

double pWidth = myDLL.QuickPDFPageWidth(InstanceID) / CurrentZoom;
double pHeight = myDLL.QuickPDFPageHeight(InstanceID) / CurrentZoom;
// Calculate Dimension of final output image

Bitmap b = new Bitmap(Convert.ToInt32(pWidth * CurrentDPI), Convert.ToInt32(pHeight * 
CurrentDPI));

// This will Draw render image on GDI
using (Graphics g = Graphics.FromImage(b))
{
IntPtr dc = g.GetHdc();
int ans = myDLL.QuickPDFRenderPageToDC(InstanceID, CurrentDPI, 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);
teGoToPage.Text = CurrentPageNo.ToString();
}
Answer

After some playing I have the following routine for displaying on a c# winform. CurrentPage is set with buttons first, next, previous and last CurrentZoom is modified with buttons zoomin & zoomout

The PictureBox is created within a panelcontrol. Dock is set to NONE & SizeMode set to NORMAL. The PanelControl has dock set to fill in the clientarea. The PanelControl.AutoScroll is also set to true to provide scroll bars for large pictures.

If this helps other c# people with little experience in this area (like me) great. If there are better ways then please let me know.


private int CurrentPageNo = 1;
private int CurrentZoom = 76;

private void DisplayPage()
{

//let's try quick pdf
DLL myDLL = new DLL("QuickPDFDLL0721.dll");
int InstanceID;
InstanceID = myDLL.QuickPDFCreateLibrary();
if (myDLL.QuickPDFUnlockKey(InstanceID, "license here") == 1)
{
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
Byte[] BytesMessage = UTF8.GetBytes(ScannedFile);
myDLL.QuickPDFLoadFromFile(InstanceID, BytesMessage);
myDLL.QuickPDFSelectPage(InstanceID, CurrentPageNo);

myDLL.QuickPDFSetMeasurementUnits(InstanceID, 0);

double pWidth = (myDLL.QuickPDFPageWidth(InstanceID) / CurrentZoom) + 10;
double pHeight = (myDLL.QuickPDFPageHeight(InstanceID) / CurrentZoom) + 10;
// Calculate Dimension of final output image

Bitmap b = new Bitmap(Convert.ToInt32(pWidth * CurrentZoom), Convert.ToInt32(pHeight * 
CurrentZoom));
pictureBox1.Width = b.Width + 10;
pictureBox1.Height = b.Height + 10;
// This will Draw render image on GDI
using (Graphics g = Graphics.FromImage(b))
{
IntPtr dc = g.GetHdc();
int ans = myDLL.QuickPDFRenderPageToDC(InstanceID, CurrentZoom, 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);
tePageNo.Text = CurrentPageNo.ToString();
}

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