使用AirPrint打印锁定的pdf时如何将密码传递给UIPrintInteractionController?

问题描述:

我想使用AirPrint在iOS上打印锁定的pdf,并且我知道密码,并且我想知道在使用它进行打印时是否可以将密码传递给UIPrintInteractionController吗?因为我不想使用CGPDFDocumentUnlockWithPassword来解锁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.

我发现使用AirPrint时不必通过密码.一旦您
使用CGPDFDocumentUnlockWithPassword解锁了pdf.您得到了CGPDFDocumentRef,从UIPrintPageRenderer声明了一个子类.实现-(void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect在上下文中呈现每个页面. 可能是这样

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);


} 

,您无需设置printingItem或printingItems. 因为您可以通过实现来获取页面范围 -(NSInteger)numberOfPages

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

不要忘记将其设置为UIPrintInteractionController.

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