簡體   English   中英

使用cgpdfdocumentref進行渲染時,如何使pdf適合屏幕尺寸?

[英]how to fit the pdf to the screen size while rendering using cgpdfdocumentref…?

我是iPad應用程序開發的新手。 我正在iPad中使用CGPDFDocumentRef渲染pdf書籍。 我能夠正確呈現位於頁面中心的pdf。 它在所有側面都留有少量空白。 我正在嘗試縮放我們正居中的圖像以完全適合頁面...任何人都可以幫助我如何使它適合ipad屏幕尺寸嗎?

myPageRef = CGPDFDocumentGetPage(myDocumentRef, pageNo);
CGContextTranslateCTM(ctx,0 , layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0,-1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef,kCGPDFCropBox , layer.bounds, 0, true));
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh); 
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx, myPageRef);

通過使用此代碼,我將獲得pdf文檔位於中心,現在請幫助我確定如何使其適合頁面?

謝謝,
拉朱

您需要CGPDFPageGetDrawingTransform函數來獲得仿射變換,該仿射變換將完全做到這一點。

pdfToPageTransform = CGPDFPageGetDrawingTransform(myPageRef, kCGPDFMediaBox, layer.bounds, 0, true);
CGContextConcatCTM(ctx, pdfToPageTransform);
CGContextDrawPDFPage(ctx, myPageRef)

第三個參數是CGRect,它定義了您希望PDF適合的正方形。最后一個參數表示是否接受變形以適合CGRect。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM