【问题标题】:Rotate all pages in a PDF graphics context旋转 PDF 图形上下文中的所有页面
【发布时间】:2015-05-07 05:04:47
【问题描述】:

我正在创建一个包含多个页面的 PDF 文件:

NSMutableData *pdfData = [NSMutableData new];
CGRect rect = CGRectMake(0, 0, 300, 100);
UIGraphicsBeginPDFContextToData(pdfData, rect, nil);
for (NSInteger page = 0; page < 10; page++)
{
    UIGraphicsBeginPDFPage();
    // DRAW PAGE
}
UIGraphicsEndPDFContext();

将打印 PDF,但始终沿较长的页面打印。所以最后,在将它发送到打印机之前,我想将每一页旋转 90°。如何做到这一点?

【问题讨论】:

    标签: ios pdf cgcontext airprint cgcontextdrawpdfpage


    【解决方案1】:

    您可以使用 UIGraphicsBeginPDFPageWithInfo(bounds, dict); 代替 UIGraphicsBeginPDFPage; 在字典中,设置键“Rotate”和值 (NSNumber) 90。 例如:

    NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:90] forKey:@"Rotate"];
    UIGraphicsBeginPDFPageWithInfo(bounds, dict);
    

    【讨论】:

      【解决方案2】:

      您可以以UIImage 格式一页一页地将图像旋转90 度,然后将图像束转换为PDF。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-07
        • 1970-01-01
        • 2016-11-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-10
        • 1970-01-01
        相关资源
        最近更新 更多