簡體   English   中英

使用AirPrint打印鎖定的pdf時如何將密碼傳遞給UIPrintInteractionController?

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

我想使用AirPrint在iOS上打印鎖定的pdf,我知道密碼,並且我想知道在使用它進行打印時是否可以將密碼傳遞給UIPrintInteractionController 因為我不想使用CGPDFDocumentUnlockWithPassword來解鎖pdf並繪制每一頁。

我發現使用AirPrint時不必通過密碼。
使用CGPDFDocumentUnlockWithPassword解鎖了pdf。您得到了CGPDFDocumentRef,從UIPrintPageRenderer聲明了一個子類。 實現-(void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect在上下文中呈現每個頁面。 可能是這樣

- (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獲得頁面范圍

最后不要忘記將其設置為UIPrintInteractionController。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM