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();

明らかに、現時点では、各ページで同じものをレンダリングしているだけです。

上記のコードを「1ページ目に最初の782pxのみを印刷し、次に2ページ目に次の782pxを印刷する」と言うにはどうすればよいですか?

どうもありがとう。

4

1 に答える 1

3

各ページを開始するときに、コンテキストを上向きに変換してみてください。

CGContextBeginPDFPage();
CGContextTranslateCTM(pdfContext, 0.0, -782.0);
[self.receiptContentView.layer renderInContext:pdfContext];
于 2013-03-13T18:52:53.817 に答える