Print paper size and content inset

前端 未结 1 1009
慢半拍i
慢半拍i 2020-12-15 14:39

I\'m using following code to print HTML content containing text and images.

if (![UIPrintInteractionController isPrintingAvailable]) {
    UIAlertView *alert         


        
相关标签:
1条回答
  • 2020-12-15 15:15
    1. To specifically select A4 paper size, I implemented the printInteractionController:choosePaper: method of the <UIPrintInteractionControllerDelegate> protocol, and returned an A4 paper size if supported by the printer (test with [UIPrintPaper bestPaperForPageSize:withPapersFromArray:]. Note that portrait/landscape orientation is not set here, but by the UIPrintInfo property orientation.

    2. The property htmlFormatter.contentInsets only sets the inset for the content as a whole, before it's been split across pages by the page renderer. I was able to set a 1cm per-page margin by adding blank headers and footers via a UIPrintPageRenderer, and then adding a 1cm margin to the left and right of the HTML print formatter:

      UIPrintPageRenderer *renderer = [[UIPrintPageRenderer alloc] init];
      renderer.headerHeight = 30.0f;
      renderer.footerHeight = 30.0f;
      pic.printPageRenderer = renderer;
      [renderer release];
      
      UIMarkupTextPrintFormatter *htmlFormatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText: htmlString];
      htmlFormatter.startPage = 0;
      htmlFormatter.contentInsets = UIEdgeInsetsMake(0.0f, 30.0f, 0.0f, 30.0f);
      [renderer addPrintFormatter: htmlFormatter startingAtPageAtIndex: 0];
      [htmlFormatter release];
      
    3. Can't help with this one sorry.

    0 讨论(0)
提交回复
热议问题