Добавление страниц в PDF-файл, созданный cgcontext - PullRequest
1 голос
/ 16 августа 2011

Я создаю PDF с cgcontext, используя код, подобный этому. Создает 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);

1 Ответ

0 голосов
/ 16 августа 2011

Полагаю, мне стоило искать больше, прежде чем я спросил.Я нашел ответ здесь .

...