В моем приложении мне нужно создать PDF.Этот PDF-файл должен иметь макет с несколькими полями, в которые пользователь будет писать текст.
Моя проблема в том, что слои всегда имеют начало 0,0 (x, y), в то время как я хочу нарисовать прямоугольники в определенных местах вpdf.
Вот мой код:
-(IBAction)genPdf:(id)sender {
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100) ];
aView.layer.borderColor = [UIColor redColor].CGColor;
aView.layer.borderWidth = 2;
aView.layer.cornerRadius = 8;
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = @"test.pdf";
NSURL *fileURL = [NSURL fileURLWithPathComponents:[NSArray arrayWithObjects:documentsDirectory, filename, nil]];
// Create PDF context
CGRect pdfSize = CGRectMake(0, 0, 420, 596);
CGContextRef pdfContext = CGPDFContextCreateWithURL((CFURLRef)fileURL, &pdfSize, NULL);
CGPDFContextBeginPage(pdfContext, NULL);
UIGraphicsPushContext(pdfContext);
// Flip coordinate system
CGRect bounds = CGContextGetClipBoundingBox(pdfContext);
CGContextScaleCTM(pdfContext, 1.0, -1.0);
CGContextTranslateCTM(pdfContext, 0.0, -bounds.size.height);
// Drawing commands
[aView.layer renderInContext:pdfContext]; // should be origin.x and .y 10,10 but is 0,0!!!!
// Clean up
UIGraphicsPopContext();
CGPDFContextEndPage(pdfContext);
CGPDFContextClose(pdfContext);
}
Спасибо за помощь.
Макс