簡體   English   中英

旋轉PDF圖形上下文中的所有頁面

[英]Rotate all pages in a PDF graphics context

我正在創建一個包含多個頁面的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°。 如何才能做到這一點?

可以使用UIGraphicsBeginPDFPageWithInfo(bounds,dict)代替UIGraphicsBeginPDFPage; 在字典中,設置鍵“ Rotate”和值(NSNumber)90。EG:

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

您可以通過以UIImage格式一頁一頁地將圖像旋轉到90度,然后將圖像束轉換為PDF來完成。

暫無
暫無

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

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