简体   繁体   中英

How to pass a password to UIPrintInteractionController when using AirPrint to print a locked pdf?

I would like to use AirPrint to print a locked pdf At iOS, and I know the password, and I would like to know if there is a way to pass the password to the UIPrintInteractionController when I use it to print? Because I don't want to use CGPDFDocumentUnlockWithPassword to unlock the pdf and draw every page.

I found it is not necessary to pass the password when using AirPrint.once you
unlocked the pdf use CGPDFDocumentUnlockWithPassword.You got a CGPDFDocumentRef,declare a sub class from UIPrintPageRenderer. implementate - (void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect to render each page in context. It can be like this

- (void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect
{
    CGRect pageRect = CGPDFPageGetBoxRect([_item openPage:pageIndex +1], kCGPDFMediaBox);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
    CGContextFillRect(context,printableRect);
    CGContextTranslateCTM(context, 0.0, printableRect.size.height);
    CGContextTranslateCTM(context, printableRect.origin.x, printableRect.origin.y);
    CGContextScaleCTM(context, printableRect.size.width/pageRect.size.width, -printableRect.size.height/pageRect.size.height);
    CGContextSaveGState(context);
    CGContextDrawPDFPage(context, [_item openPage:pageIndex + 1]);
    CGContextRestoreGState(context);


} 

and you don't need to set printingItem or printingItems. because you can get the page range by implementate - (NSInteger)numberOfPages

at last dont't forget to set it to UIPrintInteractionController .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM