2011-08-16 37 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

相關問題