标签: uiprintformatter

打印UIWebView时出现意外的分页符

TLDR:如果您打印UIWebView包含HTML由文本对齐元素含量right/ center,导致文档中就有出乎意料的大底边距页.

我遇到了这个问题,当我无法谷歌任何有类似问题的人时,我感到非常惊讶.我已经提交了雷达与苹果(#20760071),并创建了一个问题ResearchKit的GitHub库,因为这会影响他们ORKHTMLPDFWriter.

AFAIK这也影响到所有使用库UIWebView转换HTMLPDF,我已经测试:

我想知道是否有人能想出一些解决方法.

如何重现:

NSMutableString* html = [NSMutableString string];
[html appendString:@"<html><body>"];
for (int i=0; i<200; i++) {
    [html appendString:@"<div align=\"right\">line</div>"];
}
[html appendString:@"</body></html>"];

UIPrintInteractionController* pc = [UIPrintInteractionController sharedPrintController];

UIPrintInfo* printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGrayscale;

pc.printInfo = printInfo;
pc.showsPaperSelectionForLoadedPapers = YES;

UIWebView* web = [UIWebView new];
[web loadHTMLString:html baseURL:nil];
pc.printFormatter = web.viewPrintFormatter;

[pc presentAnimated:YES completionHandler:^(UIPrintInteractionController …
Run Code Online (Sandbox Code Playgroud)

html pdf-generation uiwebview ios uiprintformatter

14
推荐指数
1
解决办法
1379
查看次数

UIMarkupTextPrintFormatter永远不会渲染base64图像

我在swift 3.0中用html内容创建一个pdf文件:

/**
 *
 */
func exportHtmlContentToPDF(HTMLContent: String, filePath: String) {
    // let webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 694, height: 603));

    // webView.loadHTMLString(HTMLContent, baseURL: nil);

    let pdfPrinter = PDFPrinter();
    let printFormatter = UIMarkupTextPrintFormatter(markupText: HTMLContent);
    // let printFormatter = webView.viewPrintFormatter();

    pdfPrinter.addPrintFormatter(printFormatter, startingAtPageAt: 0);

    let pdfData = self.drawPDFUsingPrintPageRenderer(printPageRenderer: pdfPrinter);

    pdfData?.write(toFile: filePath, atomically: true);
}

/**
 *
 */
func drawPDFUsingPrintPageRenderer(printPageRenderer: UIPrintPageRenderer) -> NSData! {
    let data = NSMutableData();

    UIGraphicsBeginPDFContextToData(data, CGRect.zero, nil);

    printPageRenderer.prepare(forDrawingPages: NSMakeRange(0, printPageRenderer.numberOfPages));

    let bounds = UIGraphicsGetPDFContextBounds();

    for i …
Run Code Online (Sandbox Code Playgroud)

html pdf webview uiprintformatter swift

6
推荐指数
2
解决办法
1270
查看次数

一个UIView的AirPrint内容

我正在尝试通过iPad应用程序设置打印,单击"打印"将打印包含其所有内容的视图.以下是我尝试过的内容(通过网上的几个例子汇总):

// This is the View I want to print
// Just a 200x200 blue square
var testView = UIView(frame: CGRectMake(0, 0, 200, 200))
testView.backgroundColor = UIColor.blueColor()

let printInfo = UIPrintInfo(dictionary:nil)!
printInfo.outputType = UIPrintInfoOutputType.General
printInfo.jobName = "My Print Job"

// Set up print controller
let printController = UIPrintInteractionController.sharedPrintController()
printController!.printInfo = printInfo
// This is where I was thinking the print job got the
// contents to print to the page??
printController?.printFormatter = testView.viewPrintFormatter()

// Do it
printController!.presentFromRect(self.frame, inView: self, animated: …
Run Code Online (Sandbox Code Playgroud)

uiview airprint uiprintformatter swift

5
推荐指数
1
解决办法
3403
查看次数

UIPrintInteractionController无边框打印

A3

我正在使用UIPrintInteractionController使用打印图像概念处理iPhone应用程序.我已经卡在一个点,即边界,每当我尝试使用打印机打印任何图像时,它总是在所有侧面显示不需要的边框.图像应该使用整个纸张尺寸,因为我给出的图像尺寸与纸张宽度和高度相同,但它仍然显示边框.

我没有找到任何方法来删除边框或使纸张内容边框更少.查看iPhone图片在此输入图像描述 在此输入图像描述

您可以在附图中看到 在此输入图像描述,在这个我试图从Mac系统打印图像,它提供边框和边框较少的选项.

我认为应该在UIPrintInteractionController 框架中,但没有找到任何人.

如果有人对此有所了解,请帮助我.

提前致谢.我们将不胜感激

[![A4][4]][4]
Run Code Online (Sandbox Code Playgroud)

A3

objective-c ios uiprintformatter uiprintinteractioncntrler

5
推荐指数
1
解决办法
800
查看次数

打印在WKWebView中显示的PDF文件

我正在尝试从WKWebView打印.网页和图片工作正常.

仅当我打印PDF文件时,页面都是空白的.

这是我用来创建printController的代码:

let printController = UIPrintInteractionController.sharedPrintController()

let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfoOutputType.General
printInfo.jobName = urlField.text!
printInfo.duplex = UIPrintInfoDuplex.LongEdge

let formatter: UIViewPrintFormatter = webView.viewPrintFormatter()
formatter.contentInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

printController.printFormatter = formatter
printController.printInfo = printInfo
printController.showsPageRange = true
printController.showsNumberOfCopies = true

printController.presentFromBarButtonItem(printButton, animated: true, completionHandler: nil)
Run Code Online (Sandbox Code Playgroud)

有人能帮助我走向正确的方向吗?有这个问题的解决方案吗?

pdf uiprintformatter uiprintinteractioncntrler swift wkwebview

4
推荐指数
1
解决办法
4671
查看次数