打印预览中未显示条形码。(Objective C)
Barcode is not shown in print preview.(Objective C)
我有一个包含一些条形码的 pdf 文件。
在 WKWebView 中,pdf 预览很好(显示条形码)。
但是在打印预览中条形码没有出现。
这是我正在使用的代码。
#define kPrintingPerPageEdgeInsets UIEdgeInsetsMake(60, 40, 60, 40)
- (void)presentPrintInteractionControllerWithFormatter:(UIPrintFormatter *)printFormatter
jobName:(NSString *)jobName
contentType:(PrintingContentType)contentType
actionSheetBarButtonItem:(UIBarButtonItem *)barButtonItem
printInfoOrientation:(UIPrintInfoOrientation) printOrientation
{
UIPrintInteractionController *printInteractionController = [[self class] createPrintInteractionControllerWithJobName:jobName];
printInteractionController.printFormatter = printFormatter;
printInteractionController.printFormatter.perPageContentInsets = kPrintingPerPageEdgeInsets;
printInteractionController.printInfo.orientation = printOrientation;
[self presentPrintInteractionController:printInteractionController
contentType:contentType
barButtonItem:barButtonItem];
}
+ (UIPrintInteractionController *)createPrintInteractionControllerWithJobName:(NSString *)jobName
{
UIPrintInteractionController *printInteractionController = [UIPrintInteractionController sharedPrintController];
printInteractionController.printingItem = nil;
printInteractionController.printFormatter = nil;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = jobName;
printInteractionController.printInfo = printInfo;
return printInteractionController;
}
我自己找到了解决方案。
我们可以使用 printInteractionController 的 PrintingItem 属性 来打印文档,而不是使用 printFormatter。
printInteractionController.printFormatter = nil;
printInteractionController.printingItem = pdfData;
pdfData是pdf相关的NSData。
我有一个包含一些条形码的 pdf 文件。 在 WKWebView 中,pdf 预览很好(显示条形码)。 但是在打印预览中条形码没有出现。
这是我正在使用的代码。
#define kPrintingPerPageEdgeInsets UIEdgeInsetsMake(60, 40, 60, 40)
- (void)presentPrintInteractionControllerWithFormatter:(UIPrintFormatter *)printFormatter
jobName:(NSString *)jobName
contentType:(PrintingContentType)contentType
actionSheetBarButtonItem:(UIBarButtonItem *)barButtonItem
printInfoOrientation:(UIPrintInfoOrientation) printOrientation
{
UIPrintInteractionController *printInteractionController = [[self class] createPrintInteractionControllerWithJobName:jobName];
printInteractionController.printFormatter = printFormatter;
printInteractionController.printFormatter.perPageContentInsets = kPrintingPerPageEdgeInsets;
printInteractionController.printInfo.orientation = printOrientation;
[self presentPrintInteractionController:printInteractionController
contentType:contentType
barButtonItem:barButtonItem];
}
+ (UIPrintInteractionController *)createPrintInteractionControllerWithJobName:(NSString *)jobName
{
UIPrintInteractionController *printInteractionController = [UIPrintInteractionController sharedPrintController];
printInteractionController.printingItem = nil;
printInteractionController.printFormatter = nil;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = jobName;
printInteractionController.printInfo = printInfo;
return printInteractionController;
}
我自己找到了解决方案。 我们可以使用 printInteractionController 的 PrintingItem 属性 来打印文档,而不是使用 printFormatter。
printInteractionController.printFormatter = nil;
printInteractionController.printingItem = pdfData;
pdfData是pdf相关的NSData。