Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have only one option is to <code>scale down</code> to the <code>ratio</code> of the <code>printed format</code> from all pages of PDF then print it. I have done is got all pages of <code>pdf into images</code> and scaled that down to requirement :</p> <pre><code>NSString *strFilePath = [[NSBundle mainBundle] pathForResource:@"pdftouch" ofType:@"pdf"]; pic.printingItems = [[self allPagesImageFromPDF:strFilePath] copy]; </code></pre> <p>Add all three methods :</p> <p><code>Convert all PDF pages into UIImages</code></p> <pre><code>-(NSMutableArray *)allPagesImageFromPDF:(NSString *)strPath { NSMutableArray *arrImages = [NSMutableArray array]; CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:strPath]); NSInteger numberOfPages = CGPDFDocumentGetNumberOfPages(pdf); for (NSInteger pageIndex = 1; pageIndex &lt;= numberOfPages; pageIndex++) { UIImage *img = [self getThumbForPage:pdf pageIndex:pageIndex]; [arrImages addObject:[self resizedImage:img]]; } return arrImages; } </code></pre> <p><code>Resize images</code></p> <pre><code>-(UIImage *)resizedImage:(UIImage *)image { UIGraphicsBeginImageContext(CGSizeMake(612, 792)); //A4 size [image drawInRect:CGRectMake(0,0,612, 792)]; //A4 size UIImage *resizedImg = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resizedImg; } </code></pre> <p><code>Get UIImage from CGPDFPageRef</code></p> <pre><code>-(UIImage *)getThumbForPage:(CGPDFDocumentRef)pdfRef pageIndex:(int)page_number{ // Get the page CGPDFPageRef myPageRef = CGPDFDocumentGetPage(pdfRef, page_number); // Changed this line for the line above which is a generic line CGRect pageRect = CGPDFPageGetBoxRect(myPageRef, kCGPDFMediaBox); //CGFloat pdfScale = width/pageRect.size.width; //pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale); pageRect.origin = CGPointZero; UIGraphicsBeginImageContext(pageRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); // White BG CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0); CGContextFillRect(context,pageRect); CGContextSaveGState(context); // Next 3 lines makes the rotations so that the page look in the right direction CGContextTranslateCTM(context, 0.0, pageRect.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFMediaBox, pageRect, 0, true)); CGContextDrawPDFPage(context, myPageRef); CGContextRestoreGState(context); UIImage *thm = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return thm; } </code></pre> <p><strong>EDIT</strong> : Refer <a href="https://stackoverflow.com/questions/7652082/printing-uiimage-using-airprint-causes-cut-off-content">printing-uiimage-using-airprint-causes-cut-off-content</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload