PDF rendering using CGContextDrawPDFPage : cannot find CropBox

一曲冷凌霜 提交于 2019-12-06 13:06:50

That doesn't look like metadata, but rather like the media box was being used to crop the PDF instead of the crop box. In your code you probably have something like this:

  CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh); 
  CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault); 
  CGContextSetRGBFillColor( ctx, 1.0, 1.0, 1.0, 1.0 );
  CGContextFillRect( ctx, CGContextGetClipBoundingBox( ctx ));

  CGContextTranslateCTM( ctx, 0.0, self.bounds.size.height );
  CGContextScaleCTM( ctx, 1.0, -1.0 );
  CGAffineTransform pdfXfm = CGPDFPageGetDrawingTransform( pdfPage, kCGPDFMediaBox, self.bounds, 0, true );
  CGContextConcatCTM( ctx, pdfXfm );
  CGContextDrawPDFPage( ctx, pdfPage );

Try using kCGPDFCropBox in CGPDFGetPageDrawingTransform, that could help

I believe those markings are drawn outside the visible page area. Since you do not clip the content at page boundary, everything in the page content is displayed.
This code should help (before drawing the page):

CGContextAddRect(ctx, cropBoxRect);
CGContextClip(ctx);

This article shows how to display properly a PDF page on iOS: http://ipdfdev.com/2011/03/23/display-a-pdf-page-on-the-iphone-and-ipad/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!