Frequently Asked Question:
RenderPDFToVariant in VB6 ?
Could you provide me a code sample that shows me how to use RenderPDFToVariant or RenderPDFToDC in combination with a VB6 PictureBox ? Finally i need to copy the Picture to the clipboard f.e. using Clipboard.Setdata Picture1.Image, vbCFBitmap.
Here is some code from C# using the Quick PDF ActiveX control that basically does the same thing. I don't know enough about VB6 to be able to translate it.
The ActiveX version returns this data as a 'Variant'. You will need to work out how to get this data into the pictureBox1.Image property of the VB control.
private void ShowPDF(string fileName)
{
PDFLibrary qp = new PDFLibrary();
qp.UnlockKey(LicenseKey);
qp.LoadFromFile(fileName);
// Fit width of PDF to width of picture box
int dpi = Convert.ToInt32((pictureBox1.Width * 72) / qp.PageWidth());
byte[] bmpData = (byte[])qp.RenderPageToVariant(dpi, 1, 0);
MemoryStream ms = new MemoryStream(bmpData);
Bitmap bmp = new Bitmap(ms);
pictureBox1.Image = bmp;
ms.Dispose();
}
NOTE : If you need to use this code with C# and the DLL then simply replace RenderPageToVariant with RenderPageToString and code will work exactly the same way.
Here is some very basic code to show how to call DARenderPageToDC to a Bitmap. This code does not account for DPI or scrolling in any meaningful way. The Bitmap is then attached to a PictureBox just to show that the call is working.
int dpi = (int)this.CreateGraphics().DpiX;
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
int Handle = QP.DAOpenFileReadOnly("Moby_Dick_NT_2.pdf", null);
int PageRefNo = QP.DAFindPage(Handle, 1);
Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
using (Graphics g = Graphics.FromImage(b))
{
IntPtr dc = g.GetHdc();
QP.DARenderPageToDC(Handle, PageRefNo, dpi, (int)dc); // 50 dpi only
g.ReleaseHdc(dc);
GraphicsUnit gUnit = GraphicsUnit.Point;
g.PageUnit = gUnit;
}
pictureBox1.Image = b;
QP.DACloseFile(Handle);