2013-03-13 21 views
1

我試圖將UIView作爲PDF進行打印。將UIView /圖形上下文分割爲多個區域

問題是,如果UIView比頁面高,它會被切斷。

所以我想要做的是遍歷UIView的「頁面高度」,並將它們分別渲染爲PDF頁面。

這裏是我的代碼:

UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, 400, 782), nil); 
CGContextRef pdfContext = UIGraphicsGetCurrentContext(); 

UIGraphicsBeginPDFPage(); 

// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData 
[self.receiptContentView.layer renderInContext:pdfContext]; 

UIGraphicsBeginPDFPage(); 

// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData 
[self.receiptContentView.layer renderInContext:pdfContext]; 

// remove PDF rendering context 
UIGraphicsEndPDFContext(); 
此刻

顯然,它只是呈現在每一頁上同樣的事情。

我該如何更改上面的代碼來說「只打印第一頁上的第一個782px,然後打印第二頁上的下一個782px」?

非常感謝。

回答

3

嘗試在每個頁面啓動時向上轉換上下文。

CGContextBeginPDFPage(); 
CGContextTranslateCTM(pdfContext, 0.0, -782.0); 
[self.receiptContentView.layer renderInContext:pdfContext]; 
+0

啊哈!這非常出色。 :) 謝謝。 – 2013-03-14 08:55:10

相關問題