1

I'm creating a PDF file containige multiple pages:

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

The PDF will be printed, but always in along the longer page side. So at the end and before sending it to a printer, I want to rotate each page by 90°. How can this be done?

Norbert
  • 4,239
  • 7
  • 37
  • 59

2 Answers2

4

Instead of UIGraphicsBeginPDFPage, you can use UIGraphicsBeginPDFPageWithInfo(bounds, dict); In the dictionary, set a key "Rotate" and value (NSNumber) 90. EG:

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

You can do by taking one by one page in UIImage format and rotate image to 90 degree and then convert image bunch to PDF.

Sunny Shah
  • 12,990
  • 9
  • 50
  • 86