我正在使用类似于此的代码创建带有cgcontext的pdf。它创建一个单页的pdf文件。为我的pdf创建第二页需要什么?
换句话说,我想将我的内容分为两页。无论如何要做到这一点?
// Make the pdf A4 size.
CGRect sizeOfA4 = CGRectMake(0, 0, 595, 842);
CGContextRef pdfContext = [self createPDFContext:sizeOfA4 path:(CFStringRef)writableDBPath];
CGContextBeginPage (pdfContext,nil); // 6
// push the matrix
CGContextSaveGState(pdfContext);
// turn PDF upsidedown
CGAffineTransform transform = CGAffineTransformIdentity;
// translates the cooridinate system by the height of the view.
transform = CGAffineTransformMakeTranslation(xPos, aUIView.bounds.size.height+yPos);
// scales existing transform
transform = CGAffineTransformScale(transform, 1.0*scale, -1.0*scale);
CGContextConcatCTM(pdfContext, transform);
// Draw view into PDF
// Is renderInContext deprecated? Something to look into.
[aUIView.layer renderInContext:pdfContext];
// pop the matrix
CGContextRestoreGState(pdfContext);
// turn PDF upsidedown
CGAffineTransform transformB = CGAffineTransformIdentity;
// translates the cooridinate system by the height of the view.
transformB = CGAffineTransformMakeTranslation(0.0, 842);
// scales existing transform
transformB = CGAffineTransformScale(transformB, 1.0, -1.0);
CGContextConcatCTM(pdfContext, transformB);
CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextSetTextMatrix(pdfContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
// loop through array of dictionaries of texts
for (id object in arrayOfTexts) {
NSString *textNSString = [object objectForKey:@"text"];
const unsigned char *text = (const unsigned char *) [textNSString UTF8String];
float x = [[object objectForKey:@"x"] floatValue];
float y = [[object objectForKey:@"y"] floatValue];
CGContextShowTextAtPoint (pdfContext, x, y, text, strlen(text));
}
CGContextEndPage (pdfContext); // 8
CGContextRelease (pdfContext);