问题
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.
回答1:
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 .
来源:https://stackoverflow.com/questions/12031929/how-to-pass-a-password-to-uiprintinteractioncontroller-when-using-airprint-to-pr