Posts

Post not yet marked as solved
0 Replies
292 Views
Hi,I'm trying to create a PDF which contains some graphics and text. The PDF created on the Mac is invalid, while OK on iOS. I've simplified the app as shown below, which still generates an invalid PDF. Any clue what I'm doing wrong? CGRect pageRect = CGRectMake(0, 0, 842, 595); //A4 CGContextRef pdfContext; NSMutableData* pdfData = [NSMutableData data]; CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((CFMutableDataRef) pdfData ); pdfContext = CGPDFContextCreate( consumer, &pageRect, (__bridge CFDictionaryRef)@{(NSString*)kCGPDFContextTitle : @"Tricity App", (NSString*)kCGPDFContextCreator: @"Tricity" }); CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, pageRect.size.height); CGContextBeginPage (pdfContext, &pageRect); CGContextConcatCTM(pdfContext, flipVertical); UIGraphicsPushContext(pdfContext); [@"Test" drawInRect:CGRectMake(100, 100, 300, 300) withAttributes:nil]; UIGraphicsPopContext(); CGContextEndPage (pdfContext); CGContextRelease (pdfContext); NSURL* url = [[[NSFileManager defaultManager] temporaryDirectory] URLByAppendingPathComponent:@"temp.pdf"]; [pdfData writeToURL:url atomically:YES]; UIDocumentPickerViewController* ctrl = [[UIDocumentPickerViewController alloc] initWithURL:url inMode:UIDocumentPickerModeMoveToService]; [self presentViewController:ctrl animated:YES completion:nil];ThanksTom
Posted
by Tom Nys.
Last updated
.