【发布时间】:2021-01-26 07:44:26
【问题描述】:
我正在开发一个需要预览和打印文档的应用程序。 我可以预览它,但不能打印它。
PS:我在网上搜索,发现有一个方法printwithinfo, 但是当我尝试使用它时,它会说“无法识别的方法”
这是我正在使用的代码。
PDFView *pdfView = [[PDFView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:pdfView];
pdfView.translatesAutoresizingMaskIntoConstraints = NO;
UILayoutGuide * guide = self.view.safeAreaLayoutGuide;
[pdfView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES;
[pdfView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES;
[pdfView.topAnchor constraintEqualToAnchor:guide.topAnchor].active = YES;
[pdfView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor].active = YES;
pdfView.autoScales = YES;
pdfView.displayDirection = kPDFDisplayDirectionVertical;
pdfView.displaysRTL = YES;
pdfView.displayMode = kPDFDisplaySinglePageContinuous;
[pdfView setDisplaysPageBreaks:YES];
[pdfView setDisplayBox:kPDFDisplayBoxTrimBox];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"sample" withExtension:@"pdf"];
PDFDocument * document = [[PDFDocument alloc] initWithURL:url];
pdfView.document = document;
[pdfView.document allowsPrinting];
PDFThumbnailView *thumbnailView = [[PDFThumbnailView alloc]init];
thumbnailView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:thumbnailView];
[thumbnailView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES;
[thumbnailView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES;
[thumbnailView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor constant:10].active = YES;
[thumbnailView.heightAnchor constraintEqualToConstant:120].active = YES;
thumbnailView.thumbnailSize = CGSizeMake(100, 60);
thumbnailView.layoutMode = PDFThumbnailLayoutModeHorizontal;
thumbnailView.PDFView = pdfView;
pdfView.delegate = self;
pdfView.document.delegate = self;
pdfView.displaysAsBook = YES;
【问题讨论】:
标签: ios objective-c objective-c-category objective-c-2.0