Search Results

Search found 5 results on 1 pages for 'cgpdfcontext'.

Page 1/1 | 1 

  • PDF files created on iPad dont display correctly on Windows

    - by user286028
    My iPhone app creates PDF files (in Arial font). The plain iPhone 3.1.x version works great (other than the known issue that PDFs created on the iPhone cant be viewed correctly in Google Docs or the BlackBerry). As I am updating my project for OS 3.2 and the iPad, it works just the same, and the PDFs still look great on the iPhone, iPad and MacOS (Preview app). But now on Windows (Vista), Acrobat 9.3.1 says "Cannot extract the embedded font 'XYZABC+ArialMT'. Some characters may not display or print correctly". And in fact Acrobat then uses some generic font instead of Arial (or whatever other font I try). Quartz 3.2 seems to generate these "random" embedded font names each time it creates a PDF (the XYZABC changes around each time). I can't tell whether the problem is just the somewhat strange "temporary" embedded font name with the plus sign, or the way Quartz 3.2 is embedding fonts. I have tried my existing code (using CGPDFContext* funtions), and also the newly supported UIGraphics* functions, with the same results. Has anyone else tried creating PDFs on the iPad yet and gotten them to display correctly on Windows?

    Read the article

  • iPhone: CGPDFPageRef & CGPDFPageRelease memory leak and cryptic error message

    - by carloe
    Could someone tell me why the code below outputs "missing or invalid MediaBox" in the console? The code works fine if I remove CGPDFPageRelease(page);, but then my app starts leaking like crazy. -(CGSize)dimensionOfPageAtIndex:(int)index { CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index); CGRect tempRect = CGPDFPageGetBoxRect(page, kCGPDFBleedBox); CGSize tempSize = CGSizeMake(tempRect.size.width, tempRect.size.height); CGPDFPageRelease(page); return tempSize; } I also have this code in my app, and releasing the pageref here works just fine... -(UIImage *)pageAtIndex:(NSInteger)pageNumber withWidth:(CGFloat)width andHeight:(CGFloat)height { if((pageNumber>0) && (pageNumber<=pageCount)) { CGFloat scaleRatio; // multiplier by which the PDF Page will be scaled UIGraphicsBeginImageContext(CGSizeMake(width, height)); CGContextRef context = UIGraphicsGetCurrentContext(); CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber); CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFBleedBox); //Figure out the orientation of the PDF page and set the scaleRatio accordingly if(pageRect.size.width/pageRect.size.height < 1.0) { scaleRatio = height/pageRect.size.height; } else { scaleRatio = width/pageRect.size.width; } //Calculate the offset to center the image CGFloat xOffset = 0.0; CGFloat yOffset = height; if(pageRect.size.width*scaleRatio<width) { xOffset = (width/2)-(pageRect.size.width*scaleRatio/2); } else { yOffset = height-((height/2)-(pageRect.size.height*scaleRatio/2)); } CGContextTranslateCTM(context, xOffset, yOffset); CGContextScaleCTM(context, 1.0, -1.0); CGContextSaveGState(context); CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFBleedBox, CGRectMake(0, 0, pageRect.size.width, pageRect.size.height), 0, true); pdfTransform = CGAffineTransformScale(pdfTransform, scaleRatio, scaleRatio); CGContextConcatCTM(context, pdfTransform); CGContextDrawPDFPage(context, page); CGContextRestoreGState(context); UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext(); CGContextRelease(context); CGPDFPageRelease(page); return tempImage; } return NO; }

    Read the article

  • Portion from CGPDFPage + Scale (zoom)

    - by malcom
    I wanna take a rect from CGPDFPage (the portion of image around the user's touch point(x,y)) and scale it by a scaleFactor (ie 2x). Below the code I've used to get CGPDFPage's rect. The problem with it is the scaleFactor support. The idea is: 1) pageRect size is pageRect.size *2 2) myThumbRect (the region to zoom) become resultImageSize/scaleFactor (because the final output will be scaleFactor times bigger) 3) pointOfClick (x,y) become pointOfClick(2x,2y) 4) scale up the context by factor CGContextScaleCTM(ctx, scaleFactor, -scaleFactor); 5) grab the rect However the result is an empty image. Any idea? -(UIImage *) zoomedPDFImageAtPoint:(CGPoint) pointOfClick size:(CGSize) resultImageSize scale:(CGFloat) scaleFactor { // get the rect of our page CGRect pageRect = CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox); // my thumb rect is a portion of our CGPDFPage with size as /scaleFactor of resultImageSize // then we need to scale the image portiong by *scaleFactor and draw it in our resultImageSize sized graphic context CGSize myThumbRect = resultImageSize; // page rect has size as original size * scaleFactor //resultImageSize = pageRect.size; // to remove, i've used it to see where the rect is printed in final image pointOfClick = CGPointMake(-pointOfClick.x, -pointOfClick.y); NSLog(@"Click (%0.f,%0.f) Page (%0.f,%0.f ; %0.f,%0.f)",pointOfClick.x,pointOfClick.y,pageRect.origin.x,pageRect.origin.y,pageRect.size.width,pageRect.size.height); // create a new context for resulting image of my desidered size UIGraphicsBeginImageContext(resultImageSize); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSaveGState(ctx); // because rect is that for drawing in a flipped coordinate system, this translate the lower-left corner of the rect // in an upright coordinate system CGContextTranslateCTM(ctx, CGRectGetMinX(pageRect),CGRectGetMaxY(pageRect)); // scale to flip the coordinate system so that the y axis goes up the drawing canvas CGContextScaleCTM(ctx, 1, -1); // translate so the origin is offset by exactly the rect origin CGContextTranslateCTM(ctx, -(pageRect.origin.x), -(pageRect.origin.y)); // zoomRect is interested region.the clickPoint is the center of this region CGRect zoomedRect = CGRectMake(-pointOfClick.x, (pageRect.size.height-(-pointOfClick.y)),myThumbRect.width,myThumbRect.height); zoomedRect.origin.y-=(myThumbRect.height/2.0); zoomedRect.origin.x-=(myThumbRect.width/2.0); NSLog(@"Zoom region at (%0.f,%0.f) (%0.f,%0.f)",zoomedRect.origin.x,zoomedRect.origin.y,zoomedRect.size.width,zoomedRect.size.height); // now we need to move clipped rect to the origin // x: x was moved subtracting current click x coordinate and adding the half of zoomed rect (because zoomedRect contains pointsOfClick at it's center) // same with y but inverse (because ctm is flipped) CGPoint translateToOrigin = CGPointMake(pointOfClick.x+(zoomedRect.size.width/2.0), -pointOfClick.y-(zoomedRect.size.height/2.0));//(pageRect.size.height-zoomedRect.size.height)+pointOfClick.y); NSLog(@"Translate zoomed region to origin using translate by (%0.f,%0.f)",translateToOrigin.x,translateToOrigin.y); CGContextTranslateCTM(ctx, translateToOrigin.x,translateToOrigin.y); CGContextClipToRect (ctx, zoomedRect); // now draw the document CGContextDrawPDFPage(ctx, myPageRef); CGContextRestoreGState(ctx); // generate image UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return finalImage; }

    Read the article

  • CGPDFContextCreateWithURL not correctly creating context

    - by mjdth
    Using the following code, the ctx is not correctly being created. It remains nil: #import <QuartzCore/QuartzCore.h> @implementation UIView(PDFWritingAdditions) - (void)renderInPDFFile:(NSString*)path { CGRect mediaBox = self.bounds; CGContextRef ctx = CGPDFContextCreateWithURL((CFURLRef)[NSURL URLWithString:path], &mediaBox, NULL); CGPDFContextBeginPage(ctx, NULL); CGContextScaleCTM(ctx, 1, -1); CGContextTranslateCTM(ctx, 0, -mediaBox.size.height); [self.layer renderInContext:ctx]; CGPDFContextEndPage(ctx); CFRelease(ctx); } @end In the console it shows: <Error>: CGPDFContextCreate: failed to create PDF context delegate. I've tried several different paths so I'm fairly certain that is not the problem. Thanks for any advice!

    Read the article

  • Rendering UIImage/CGImage into CGPDFContext results in... blankness!

    - by quixoto
    Hi all, I'm trying to take an image that I have in a image object and render into a Core Graphics PDF context-- happens to be on an iPhone but this question surely applies equally to desktop Quartz. This UIImage is a simple color-on-white image at about 600x800 resolution. If I (say) turn it into a PNG file, that file looks exactly as expected-- so the data is OK. Here's what I'm doing to generate the PDF: NSMutableData * outputData = [[NSMutableData alloc] init]; CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData((CFMutableDataRef)outputData); CFMutableDictionaryRef attrDictionary = NULL; attrDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(attrDictionary, kCGPDFContextTitle, @"My Awesome Document"); CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, NULL, attrDictionary); CFRelease(dataConsumer); CFRelease(attrDictionary); CGImageRef pageImage = [myUIImage CGImage]; CGPDFContextBeginPage(pdfContext, NULL); CGContextDrawImage(pdfContext, CGRectMake(0, 0, [myUIImage size].width, [myUIImage size].height), pageImage); CGPDFContextEndPage(pdfContext); CGContextRelease(pdfContext); Resulting PDF, which ends up in outputData, seems like a valid PDF file (opens correctly, document title is present in metadata), but it consists of precisely one blank page. What am I doing wrong? Thanks.

    Read the article

1