PDFRasterizerRasterize Method |
Draws the page into a given memory buffer.
Namespace:
pdftron.PDF
Assembly:
pdftron (in pdftron.dll) Version: 255.255.255.255
Syntax public void Rasterize(
Page page,
ByteArrayRef in_out_image_buffer,
int width,
int height,
int stride,
int num_comps,
bool demult,
Matrix2D device_mtx,
Rect clip
)
Public Sub Rasterize (
page As Page,
in_out_image_buffer As ByteArrayRef,
width As Integer,
height As Integer,
stride As Integer,
num_comps As Integer,
demult As Boolean,
device_mtx As Matrix2D,
clip As Rect
)
public:
virtual void Rasterize(
[InAttribute] Page^ page,
[InAttribute] ByteArrayRef^ in_out_image_buffer,
[InAttribute] int width,
[InAttribute] int height,
[InAttribute] int stride,
[InAttribute] int num_comps,
[InAttribute] bool demult,
[InAttribute] Matrix2D^ device_mtx,
[InAttribute] Rect^ clip
) sealed
function Rasterize(page, in_out_image_buffer, width, height, stride, num_comps, demult, device_mtx, clip);
Parameters
- page
- Type: pdftron.PDFPage
The page to rasterize.
- in_out_image_buffer
- Type: pdftron.CommonByteArrayRef
A pointer to a memory buffer. The buffer must contain at least (stride * height) bytes.
- width
- Type: SystemInt32
The width of the target image in pixels.
- height
- Type: SystemInt32
The height of the target image in pixels (the number of rows).
- stride
- Type: SystemInt32
Stride determines the physical width (in bytes) of one row in memory. If this value is negative the direction of the Y axis is inverted. The absolute value of stride is of importance, because it allows rendering in buffers where rows are padded in memory (e.g. in Windows bitmaps are padded on 4 byte boundaries). Besides allowing rendering on the whole buffer stride parameter can be used for rendering in a rectangular subset of a buffer.
- num_comps
- Type: SystemInt32
The number (4 or 5) representing the number of color components in the device color space. For BGR+Alpha set this parameter to 4, and for CMYK+Alpha use 5. If other values are set, exceptions will be thrown.
- demult
- Type: SystemBoolean
Specifies if the alpha is de-multiplied from the resulting color components.
- device_mtx
- Type: pdftron.CommonMatrix2D
Device transformation matrix that maps PDF page from PDF user space into device coordinate space (e.g. pixel space). PDF user space is represented in page units, where one unit corresponds to 1/72 of an inch.
- clip
- Type: pdftron.PDFRect
Optional parameter defining the clip region for the page. If the parameter is null or is not specified, PDFRasterizer uses page's crop box as a default clip region.
Examples float drawingScale = 2;
Matrix2D matrix = new Matrix2D(drawingScale, 0, 0, drawingScale, 0, 0);
var bbox = pdf_page.GetMediaBox();
bbox.Normalize();
int width = (int)(bbox.Width() * drawingScale);
int height = (int)(bbox.Height() * drawingScale);
int comps = 4;
int stride = ((width * comps + 3) / 4) * 4;
ByteArrayRef buf1 = new ByteArrayRef(stride * height);
PDFRasterizer rast = new PDFRasterizer();
rast.Rasterize(pdf_page, buf1, width, height, stride, 4, false, matrix, null);
byte[] bytes = buf1.Value;
WriteableBitmap wb = new WriteableBitmap(width, height);
System.IO.Stream pixelStream = wb.PixelBuffer.AsStream();
pixelStream.Seek(0, System.IO.SeekOrigin.Begin);
pixelStream.Write(bytes, 0, bytes.Length);
See Also