Xojo Conferences
MBSOct2019CologneDE

DynaPDF Manual - Page 596

Previous Page 595   Index   Next Page 597

Function Reference
Page 596 of 770
m_PDF.SetPageCoords(TPageCoord.pcTopDown);
m_PDF.Append();
m_PDF.SetFont("Arial", TFStyle.fsRegular, 20.0, false, TCodepage.cpUnicode);
m_PDF.WriteFTextEx(
50.0,
50.0,
495.0,
-1.0,
TTextAlign.taCenter,
"A small example that shows how RenderPage() can be used...");
m_PDF.EndPage();
// Get the page object
IntPtr pagePtr = m_PDF.GetPageObject(1);
int w = pictureBox1.Width;
// The picture box was placed on the form.
int h = pictureBox1.Height;
// Calculate the image size
m_PDF.CalcPagePixelSize( pagePtr,
TPDFPageScale.psFitBest,
1.0f,
w,
h,
TRasterFlags.rfDefault,
ref w,
ref h);
// Create a bitmap in this size
Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Imaging.BitmapData bd = bmp.LockBits(
new Rectangle(0, 0, w, h),
System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format32bppRgb);
// Create a rasterizer for the bitmap
IntPtr ras = m_PDF.CreateRasterizer( IntPtr.Zero,
bd.Scan0,
w,
h,
bd.Stride,
DynaPDF.TPDFPixFormat.pxfBGRA);
TPDFRasterImage img = new DynaPDF.TPDFRasterImage();
img.StructSize
= System.Runtime.InteropServices.Marshal.SizeOf(img);
img.InitWhite
= 1;
img.DefScale
= TPDFPageScale.psFitBest;
// A 32 bit image has a transparent background. The flag rfCompositeWhite makes sure that the
// image gets pre-blended with a white background.
img.Flags
= TRasterFlags.rfInitBlack | TRasterFlags.rfCompositeWhite;
img.Matrix.a
= 1.0; // Identity matrix
img.Matrix.d
= 1.0; // Identity matrix
// Render the page
m_PDF.RenderPage(pagePtr, ras, ref img);
bmp.UnlockBits(bd);
pictureBox1.Image
= bmp;
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
m_PDF.DeleteRasterizer(ref ras);
m_PDF.FreePDF();
}
 

Previous topic: How to save the image on disk?

Next topic: RenderPageEx (Rendering Engine)