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

我怕爱的太早我们不能终老 提交于 2019-12-23 05:46:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!