I’m trying to draw tiles of a PDF file using PDFRasterizer and its clip parameter to replace PDFDraw and SetCropBox (since the latter would require me to write-lock the file, which delays other important tasks like searching)
Problem is the Rasterize method crashes immediately, no matter what parameters I pass, even the simplest case I can think of:
PDFRasterizer * rasterizer = [[PDFRasterizer alloc] initWithType:e_BuiltIn];
Matrix2D * matrix = [[Matrix2D alloc] initWithA:1.0 b:0.0 c:0.0 d:1.0 h:0.0 v:0.0];
int imageWidth = 512;
int imageHeight = 512;
int components = 4;
int stride = components*imageWidth;
NSData * bitmapData = [rasterizer Rasterize:page width:imageWidth height:imageHeight stride:stride num_comps:components demult:NO device_mtx:matrix clip:nil scrl_clp_regions:nil cancel:nil];
This crashes immediately in TRN_PDFRasterizerRasterizeToMemory.
FYI: I tested the Android version with the following snippet and it seems to be working fine:
PDFRasterizer mRasterizer = new PDFRasterizer(); // http://www.pdftron.com/pdfnet/mobile/Javadoc/pdftron/PDF/PDFRasterizer.html
Matrix2D matrix = page.getDefaultMatrix(true, 0, 0); matrix.translate(-rect.left, -rect.top); mRasterizer.rasterize(page, mPixels, WIDTH, HEIGHT, true, matrix, clip_rect);
bitmap.setPixels(mPixels, 0, WIDTH, 0, 0, WIDTH, HEIGHT); …
so it may be something iOS specific (or related to your code).
Will get back to you with more info …
We have addressed the problem in the latest unofficial build for iOS, which is now available for download from the iOS download page. Please e-mail email@example.com if you have any troubles.
Yeah the issues seem fixed.
When could we get this in an official release (without the watermark). I need to ship this out pretty fast. We need rasterization for efficient rendering through CATiledLayer
On Thursday, 1 August 2013 01:08:21 UTC+2, James wrote:
We have addressed the problem in the latest unofficial build for iOS, which is now available for download from the iOS download page. Please e-mail sup...@pdftron.com if you have any troubles.
I don’t completely understand the way rasterizer operates though:
[rasterizer Rasterize:page width:imageWidth height:imageHeight stride:stride num_comps:components demult:NO device_mtx:coordinateMatrix clip:cropBox scrl_clp_regions:nil cancel:nil];
I would expect this to return a bitmap of pixels that results from stretching the cropBox area into an image with imageWidth width and imageHeight height dimensions.
This works fine if the imageWidth and imageHeight is the entire screen (and the matrix used is calculated from that screen and the page dimensions).
However, once I zoom in (which basically means imageWidth/Height remain the same, but cropBox changes) it seems I need to adjust the coordinate matrix further (aside of the already calculated page transform that fits the page on the viewport) so it scales the pixels, in order to make the cropBox stretch to the image bounds.
This is strange to me, and causes some mathematical work. There is nothing wrong with the way this interface works? If so can you advise me how I’d best deal with this?
This is correct, you will need to translate and scale the matrix when zooming in. Are you able to do this to get the output you expect?