I have a problem related to pdf drawing in iPhone. When I draw the pdf in ipad it works fine but in iphone quality of image of page is not good. That image contains dark spots at the place of gray background.
Can anyone help me to solve this problem?
thanks.
- (UIImage *) imageForPageIndex:(NSUInteger)pageIndex {
UIImage *image = nil;
if ([delegate illustration_Enable])
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL,
pageSize.width,
pageSize.height,
8, /* bits per component*/
pageSize.width * 4, /* bytes per row */
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));
[self renderPageAtIndex:pageIndex OnContext:context];
CGImageRef cgimage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
image = [UIImage imageWithCGImage:cgimage];
CGImageRelease(cgimage);
}
else
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL,
pageSize.width,
pageSize.height,
8, /* bits per component*/
pageSize.width * 4, /* bytes per row */
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));
[self renderPageAtIndex:pageIndex OnContext:context];
CGImageRef cgimage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
image = [UIImage imageWithCGImage:cgimage];
CGImageRelease(cgimage);
}
return image;
}
-(void)renderPageAtIndex:(int)index OnContext:(CGContextRef)ctx{
if ([delegate illustration_Enable])
{
if (index-1 == [imageList count]) {
return;
}
UIImage *image = nil;
image = [UIImage imageWithContentsOfFile:[imageList objectAtIndex:index-1]];
CGRect rect1 = CGRectMake(0, 0, image.size.width, image.size.height);
CGRect rect2 = CGContextGetClipBoundingBox(ctx);
CGAffineTransform transform = [self aspectFill:rect1 :rect2];
CGContextConcatCTM(ctx, transform);
CGContextDrawImage(ctx, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
}
else
{
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index);
CGRect rect1 = CGPDFPageGetBoxRect(page,kCGPDFMediaBox);
CGRect rect2 = CGContextGetClipBoundingBox(ctx);
CGAffineTransform transform;
if (takeBookmarkImg)
{
transform = [self aspectFill:rect1 :rect2];
}
else
{
transform = [self aspectFit:rect1 :rect2];
}
CGContextConcatCTM(ctx, transform);
CGContextDrawPDFPage(ctx, page);
}
}
- (CGAffineTransform) aspectFit:(CGRect)innerRect :(CGRect) outerRect {
scaleFactor = MIN(outerRect.size.width/innerRect.size.width, outerRect.size.height/innerRect.size.height);
baseScaleFactor = scaleFactor;
CGAffineTransform scale = CGAffineTransformMakeScale(scaleFactor, scaleFactor);
CGRect scaledInnerRect = CGRectApplyAffineTransform(innerRect, scale);
CGAffineTransform translation =
CGAffineTransformMakeTranslation((outerRect.size.width - scaledInnerRect.size.width) / 2 - scaledInnerRect.origin.x-(totalMoveX+moveX),
(outerRect.size.height - scaledInnerRect.size.height) / 2 - scaledInnerRect.origin.y+(totalMoveY+moveY));
return CGAffineTransformConcat(scale, translation);
}
.
To preserve image quality, you'll need a higher DPI. Save your changes then download the document as a PDF. Alternatively, save your Word document as a PDF and change DPI in the advanced settings before you download it.
Incorrect Settings If this happens, check your output settings. Some PDF converters default to a relatively low resolution for output, resulting in a fuzzy-looking result. Use the same resolutions you would for originals, and don't choose images made at screen resolution for a document you intend to print.
When you save a PDF file as a JPG file, there would be a certain loss of quality. That is mainly because text and images stored in PDF files are saved in vector format. On the other hand, images in JPG files are saved in raster format.
Just a wild guess as it is hard to say without some actual screenshots, but you do not use CGContextSetInterpolationQuality in your render code. Maybe CGContextSetInterpolationQuality(your_context, kCGInterpolationHigh)
fixes the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With