2011-08-16 32 views
1

我使用与此类似的代码创建了一个带有cgcontext的pdf。它创建一个PDF文件与单个页面。为我的pdf创建第二个页面需要什么?将页面添加到由cgcontext生成的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); 
+0

你解决了这个问题吗?如果是这样,请发布答案。 – Hitesh

回答

0

我想我应该在我问之前更努力地搜索过。我找到了答案here

相关问题