【问题标题】:Split UIView/graphics context into areas将 UIView/图形上下文拆分为区域
【发布时间】:2013-03-01 18:52:24
【问题描述】:

我正在尝试将 UIView 打印为 PDF。

问题是,如果 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 页打印 NEXT 782px”?

非常感谢。

【问题讨论】:

    标签: ios objective-c pdf printing graphicscontext


    【解决方案1】:

    在开始每个页面时尝试向上转换上下文。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 2017-10-30
      • 2020-04-21
      • 2018-08-05
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多