1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Swift5 PDFKit 読み込み 表示 保存 UIPrintInteractionController印刷とUIActivityViewController印刷の話 ?

Last updated at Posted at 2020-04-16

前回はAppleの「iOSにおける 描画と印刷のガイド」で印刷の話 ? でしたが、今回は私が知らなかったPDFKitで複数ページのPDFファイルを扱います ?

目的 ?

反省 ? 当初の目的を達成することはできましたが ? 沢山の意味不明の警告が出ます ? 私だけでしょうか ? 実機でも出ます、何度も警告潰しを勉強しましたが未解決なんですよね ? まっ、これからも研究します

  • Webに国税庁の「法人事業概況説明書」みたいな以下のURL(クリックしても正常にページは表示しません)が「https://www.nta.go.jp/law/tsutatsu/kobetsu/hojin/010705/pdf/180401_02.pdf」 のように直接PDFファイルを指定しているWebサイトのPDFを読み込んで表示する挙動を解説しています、注意 ? 国税庁のそのURLはhttpsなんですが実際に使用しているPDFはApplの「iOSにおける 描画と印刷のガイド」なんですが ? ApplのサイトのURLは直接pdfファイルを指定してないので わざわざAppleのそのPDFを私のレンタルサーバから読み込んでいるのでURLがhttpなんですよね ? なのでhttpの場合はinfo.plistの設定が必要になりますが? 後ほど解説があります
  • アプリ作成時にバンドルしたPDFファイルを読み込んで表示する
  • アプリ内のDocument内に保存されたPDFファイルを読み込んで表示する

次の目的 ? 印刷の方法 ?

  • UIPrintInteractionControllerで印刷する 3種類
    pic印刷WebURL()はWebURLのPDFファイルを印刷します
    pic印刷BundleURL()はバンドルのPDFファイルを印刷します
    pic印刷fromDocuments()はドキュメントフォルダ内のPDFファイルを印刷します

  • UIActivityViewControllerで印刷する 4種類
    avc印刷WebURL()
    avc印刷BundleNSData()
    avc印刷BundleNSURL()はNSURL形式
    avc印刷fromDocuments()

印刷する内容の説明・UIPrintInteractionController編 ?

  • WebURLを読み込んで印刷する
  • バンドルPDFを読み込んで印刷する
  • document内にあるPDFを読み込んで印刷する

印刷する内容の説明・UIActivityViewController編 ?

  • WebURLを読み込んで印刷する
  • NSData読み込んで印刷する
  • NSURL読み込んで印刷する
  • document内にあるPDFを読み込んで印刷する

制作条件・以下の条件で新規にプロジェクトでSingle View APPで名前はご自由でUser InterfaceはStoryboardを指定して作成してください

  • Xcode 11.4
  • iOS 13.4
  • Storyboardには何も設定していません

挙動

指定通りに新規プロジェクトの作成ができたら「ViewController.swift」を差し替えるだけです、挙動はViewにpdfファイルが表示して直ぐに「override func viewDidAppear」で呼ばれる印刷の7つの関数の中の一番最初が呼ばれて印刷のプレビューが出ますが印刷プレビューは表示しませんがバグではありません、そのようにしていますが以下の設定で解決いたします、また、「override func viewDidLoad()」の後半でドキュメントフォルダーへ読み込んだPDFファイルを保存しているので、わざわざ新たにドキュメントフォルダーへ保存は必要ありませんが「pic印刷BundleURL()」を使用する場合は以下のエラーが出るので

バンドルしてない場合のエラー.
2020-04-16 09:42:14.508201+0900 PrintPDFKit[1337:104771] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /Users/papassan/Desktop/PrintPDFKit/PrintPDFKit/ViewController.swift, line 104

その場合は わざわざpdfファイルをプロジェクトにバンドル追加が必要です、設置場所はViewController.swiftと同じディレクトリが適切と思います

info.plistでキーの追加変更

これで作成したらViewController.swiftを差し替えるだけでOKなんですが ? 最初は下記の警告が出るように設定しています、httpとhttpsの違いでinfo.plistに設定が必要です

info.plistで変更の理由の警告

2020-04-16 07:31:38.521128+0900 PrintPDF[1080:40729] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

ソースコードの「func pic印刷BundleURL()」を参照してinfo.plistでキーの追加変更してください、また、急いでる方は差し替えて使ってみて ? また、実際の複数PDFは「iOSにおける 描画と印刷のガイド」を利用しています

ViewController.swift

ViewController.swiftを入れ替えるだけなんですが ? 上記のinfo.plistでキーの追加と変更をしないと印刷のプレビューで「Loading Preview」の状態で読み込みクルクルマークのままになりますが、その様に設計してあります、また、プリントをキャンセルするとViewには「iOSにおける 描画と印刷のガイド」は閲覧できます、使い方は「ゆっくりの人に解説します」で解説しています

ViewController.swift

//
//  ViewController.swift
//  PrintPDFKit
//
//  Created by 福田 敏一 on 2020/04/16.
//  Copyright © 2020 株式会社パパスサン. All rights reserved.
//

import UIKit
import PDFKit

class ViewController: UIViewController, UIPrintInteractionControllerDelegate,UIPopoverPresentationControllerDelegate {
    
    var pageSize = CGSize(width: 210 / 25.4 * 72, height: 297 / 25.4 * 72)
    
    //@IBOutlet weak var pdfView: PDFView!//未使用
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let pdfView = PDFView(frame: self.view.frame)
        
        // Web上のPDFの場合
        let pdfURL = URL(string: "http://papassan.starfree.jp/iOSPrintGuide.pdf")!
        // ローカルのPDFの場合
        //let pdfURL = URL(fileURLWithPath: Bundle.main.path(forResource: "iOSPrintGuide", ofType: "pdf")!)
        //背景色
        pdfView.backgroundColor = .blue
        /// PDFの拡大率を調整する
        pdfView.autoScales = true
        // 表示モード
        //pdfView.displayMode = .singlePageContinuous
        //pdfView.displayDirection = .vertical//.horizontal
        //pdfView.displaysAsBook = true
        //pdfView.usePageViewController(false, withViewOptions: [UIPageViewController.OptionsKey.interPageSpacing: 100])//trueでページ画面、100はページの間隔
        //pdfView.displaysPageBreaks = true
        //pdfView.pageBreakMargins = UIEdgeInsets(top: 10.0, left: 40.0, bottom: 10.0, right: 0.0)
        //pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        
        let document = PDFDocument(url: pdfURL)
        pdfView.document = document
        
        if let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
             let path = url.appendingPathComponent("iOSPrintGuide.pdf")
            document!.write(to: path)//保存しています
print("47通過・path -> \(path)")
        }
        self.view.addSubview(pdfView)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
print("54・通過・viewDidAppear・")
//2020/4/12・Picとは? UIPrintInteractionControllerでの印刷です、以下に5つの関数呼び出しがあります、それぞれの目的が実行されます、使用の際は1つだけ利用してください
//WebURLとは? WebサイトにあるPDFファイルのURL
        pic印刷WebURL()//利用可能の1番目の関数
//以下の1つの関数を利用する場合はお好みの複数ページのPDFファイルをバンドルしてください、バンドル場所はViewController.swifと同じディレクトリにセットしてください
//BundleURLとは? 作成のアプリにバンドルPDFファイルを利用するということです
        //pic印刷BundleURL()//利用可能の2番目の関数
        
        //pic印刷fromDocuments()//利用可能の3番目の関数
//以下のpopとは? UIActivityViewControllerでの印刷です
        //avc印刷WebURL()//利用可能の4番目の関数
//以下の2つの関数を利用する場合はお好みの複数ページのPDFファイルをバンドルしてください、バンドル場所はViewController.swifと同じディレクトリにセットしてください
        //avc印刷BundleNSData()//利用可能の5番目の関数
        //avc印刷BundleNSURL()//利用可能の6番目の関数
        //avc印刷fromDocuments()//利用可能の7番目の関数
    }

    func pic印刷WebURL() {
        
//印刷オプションのプレビューでクルクル読み込みが進まない場合は? 「PrintPDF[2312:163234] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.」
//2020/4/8・参照のURLの最初がhttp://の場合、安全性が低下するので読み込みまないと言うので? Info.plistの設定で「App Transport Security Settings」 > 「Allow Arbitrary Loads」 の値を 「YES」 に指定すれば印刷プレビューに内容が表示します
        // Web上のPDFの場合
        let pdfURL = URL(string: "http://papassan.starfree.jp/iOSPrintGuide.pdf")!
        
        let pic = UIPrintInteractionController.shared
        pic.delegate = self

        let printInfo = UIPrintInfo(dictionary:nil)
        printInfo.outputType = UIPrintInfo.OutputType.general
        printInfo.jobName = "Printing an image"
        printInfo.duplex = UIPrintInfo.Duplex.none
        printInfo.orientation = UIPrintInfo.Orientation.portrait

        pic.printPageRenderer = nil
        pic.printingItems = nil
        pic.printingItem = pdfURL

        pic.printInfo = printInfo
//'showsPageRange' was deprecated in iOS 10.0: Pages can be removed from the print preview, so page range is always shown.
        //printController.showsPageRange = true
        pic.showsNumberOfCopies = true

        pic.present(animated: true, completionHandler: nil)
    }
    
    func pic印刷BundleURL() {
//2020/4/12・エラーが出たら? 指定PDFファイルをバンドルしてください 「PrintPDF[2399:180975] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /Users/papassan/Desktop/PrintPDF/PrintPDF/ViewController.swift, line 82」
        // ローカルのBundlePDFの場合
        let pdfURL = URL(fileURLWithPath: Bundle.main.path(forResource: "iOSPrintGuide", ofType: "pdf")!)
print("103通過・pdfURL -> \(pdfURL)")
        let pic = UIPrintInteractionController.shared
        pic.delegate = self

        let printInfo = UIPrintInfo(dictionary:nil)
        printInfo.outputType = UIPrintInfo.OutputType.general
        printInfo.jobName = "Printing an image"
        printInfo.duplex = UIPrintInfo.Duplex.none
        printInfo.orientation = UIPrintInfo.Orientation.portrait
        
        pic.printPageRenderer = nil
        pic.printingItems = nil
        pic.printingItem = pdfURL

        pic.printInfo = printInfo
//'showsPageRange' was deprecated in iOS 10.0: Pages can be removed from the print preview, so page range is always shown.
        //printController.showsPageRange = true
        pic.showsNumberOfCopies = true

        pic.present(animated: true, completionHandler: nil)
    }
    
    func pic印刷fromDocuments() {
        let userDocumentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "/iOSPrintGuide" + ".pdf"
print("127通過・userDocumentsPath -> \(userDocumentsPath)")
        let pdfURL = URL(fileURLWithPath: userDocumentsPath)
print("129通過・pdfURL -> \(pdfURL)")
        
        let pic = UIPrintInteractionController.shared
        pic.delegate = self

        let printInfo = UIPrintInfo(dictionary:nil)
        printInfo.outputType = UIPrintInfo.OutputType.general
        printInfo.jobName = "Printing an image"
        printInfo.duplex = UIPrintInfo.Duplex.none
        printInfo.orientation = UIPrintInfo.Orientation.portrait
        
        pic.printPageRenderer = nil
        pic.printingItems = nil
        pic.printingItem = pdfURL

        pic.printInfo = printInfo
//'showsPageRange' was deprecated in iOS 10.0: Pages can be removed from the print preview, so page range is always shown.
        //printController.showsPageRange = true
        pic.showsNumberOfCopies = true

        pic.present(animated: true, completionHandler: nil)
                    
    }
    
    func avc印刷WebURL() {
        // URLのPDFの場合
        let pdfUrlString: URL = URL(string: "http://papassan.starfree.jp/iOSPrintGuide.pdf")!
//print("185通過・pdfUrlString -> \(type(of: pdfUrlString))")
print("157通過・pdfURL -> \(pdfUrlString)")
        //印刷はここから
        let shareText = "Apple - Apple iPhone X"
        let shareWebsite = NSURL(string: "https://www.apple.com/jp/iphone-x/")!
        let shareImage = NSData(contentsOf: pdfUrlString)
        
        var activityItems = [] as [Any]
        activityItems = [shareText, shareWebsite] as [Any]
        activityItems.append(shareImage as Any)
        
        let avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
        
        if UIDevice.current.userInterfaceIdiom == .pad {
//表示先の View・以下がないとiPadだとクラッシュします
        avc.popoverPresentationController?.sourceView = self.view
//表示場所
        let screenSize = UIScreen.main.bounds
        avc.popoverPresentationController?.sourceRect = CGRect(x: screenSize.size.width/4, y: screenSize.size.height/2, width: 0, height: 0)
            
            present(avc, animated: true, completion: nil)
            print("iPadです・印刷物はフチなしで印刷されます")
        } else {
            present(avc, animated: true, completion: nil)
            print("iPhoneです・印刷物はフチなしで印刷されます")
        }
    }
    
    func avc印刷BundleNSData() {
        // Load Sample.pdf file from app bundle.
        //let fileBundleURL = Bundle.main.url(forResource: "iOSPrintGuide", withExtension: "pdf")!//タイプURL・file:///Users/papassan/....
        let fileBundleURL = URL(fileURLWithPath: Bundle.main.path(forResource: "iOSPrintGuide", ofType: "pdf")!)//タイプURL・file:///Users/papassan/....
print("188通過・fileBundleURL -> \(fileBundleURL)")
        
        //印刷はここから
        let shareText = "Apple - Apple iPhone X"
        let shareWebsite = NSURL(string: "https://www.apple.com/jp/iphone-x/")!
        let shareImage = NSData(contentsOfFile: fileBundleURL.path)
print("194通過・shareImage -> \(type(of: shareImage))")
        var activityItems = [] as [Any]
        activityItems = [shareText, shareWebsite] as [Any]
        activityItems.append(shareImage as Any)
        
        let avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
        
        if UIDevice.current.userInterfaceIdiom == .pad {
//表示先の View・以下がないとiPadだとクラッシュします
            avc.popoverPresentationController?.sourceView = self.view
//表示場所
            let screenSize = UIScreen.main.bounds
            avc.popoverPresentationController?.sourceRect = CGRect(x: screenSize.size.width/4, y: screenSize.size.height/2, width: 0, height: 0)
            
            present(avc, animated: true, completion: nil)
            print("iPadです・印刷物はフチなしで印刷されます")
        } else {
            present(avc, animated: true, completion: nil)
            print("iPhoneです・印刷物はフチなしで印刷されます")
        }
    }
    
    func avc印刷BundleNSURL() {
            // Load Sample.pdf file from app bundle.
            let fileBundleURL = Bundle.main.url(forResource: "iOSPrintGuide", withExtension: "pdf")!//タイプURLfile:///Users/papassan/....
//2020/4/12・上記と下記は同じ物
            //let fileBundleURL = URL(fileURLWithPath: Bundle.main.path(forResource: "iOSPrintGuide", ofType: "pdf")!)//タイプURL・file:///Users/papassan/....
print("221通過・fileBundleURL -> \(fileBundleURL)")
            
        //印刷はここから
        let shareText = "Apple - Apple iPhone X"
        let shareWebsite = NSURL(string: "https://www.apple.com/jp/iphone-x/")!
        let shareImage = NSURL(fileURLWithPath: fileBundleURL.path)
print("227通過・shareImage -> \(type(of: shareImage))")
        var activityItems = [] as [Any]
        activityItems = [shareText, shareWebsite] as [Any]
        activityItems.append(shareImage as Any)
        
        let avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
            
        if UIDevice.current.userInterfaceIdiom == .pad {
//表示先の View・以下がないとiPadだとクラッシュします
            avc.popoverPresentationController?.sourceView = self.view
            avc.isModalInPresentation = true
//表示場所
            let screenSize = UIScreen.main.bounds
            avc.popoverPresentationController?.sourceRect = CGRect(x: screenSize.size.width/4, y: screenSize.size.height/2, width: 0, height: 0)
            // This line remove the arrow of the popover to show in iPad
            //avc.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros
            
            present(avc, animated: true, completion: nil)
            print("iPadです・印刷物はフチなしで印刷されます")
            } else {
                present(avc, animated: true, completion: nil)
                print("iPhoneです・印刷物はフチなしで印刷されます")
            }
        }
    
    func avc印刷fromDocuments() {
        let userDocumentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "/iOSPrintGuide" + ".pdf"
print("254通過・userDocumentsPath -> \(userDocumentsPath)")
        let pdfURL = URL(fileURLWithPath: userDocumentsPath)
print("258通過・pdfURL -> \(pdfURL)")
                
        //印刷はここから
        let shareText = "Apple - Apple iPhone X"
        let shareWebsite = NSURL(string: "https://www.apple.com/jp/iphone-x/")!
        let shareImage = NSData(contentsOfFile: pdfURL.path)
        
        var activityItems = [] as [Any]
        activityItems = [shareText, shareWebsite] as [Any]
        activityItems.append(shareImage as Any)
        
        let avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
        
        if UIDevice.current.userInterfaceIdiom == .pad {
//表示先の View・以下がないとiPadだとクラッシュします
            avc.popoverPresentationController?.sourceView = self.view
//表示場所
            let screenSize = UIScreen.main.bounds
            avc.popoverPresentationController?.sourceRect = CGRect(x: screenSize.size.width/4, y: screenSize.size.height/2, width: 0, height: 0)
            
            present(avc, animated: true, completion: nil)
            print("iPadです・印刷物はフチなしで印刷されます")
        } else {
            present(avc, animated: true, completion: nil)
            print("iPhoneです・印刷物はフチなしで印刷されます")
        }
    }
    
    func printInteractionController( _ printInteractionController: UIPrintInteractionController, choosePaper paperList: [UIPrintPaper]) -> UIPrintPaper {
        
            for i in 0..<paperList.count {
                let paper: UIPrintPaper = paperList[i]
print("paperListのビクセル is \(paper.paperSize.width),\(paper.paperSize.height)")
            }
            //ピクセル
print("\npaperSizeピクセル -> \(pageSize)")
            let bestPaper = UIPrintPaper.bestPaper(forPageSize: pageSize, withPapersFrom: paperList)
            //mmで用紙サイズと印刷可能範囲を表示
print("paperSizeミリ -> \(bestPaper.paperSize.width / 72.0 * 25.4), \(bestPaper.paperSize.height / 72.0 * 25.4)")
print("bestPaper -> \(bestPaper.printableRect.origin.x / 72.0 * 25.4), \(bestPaper.printableRect.origin.y / 72.0 * 25.4), \(bestPaper.printableRect.size.width / 72.0 * 25.4), \(bestPaper.printableRect.size.height / 72.0 * 25.4)\n")
        return bestPaper
    }
}

ゆっくりの人に解説します

このコードはstoryboardに何かの ? viewとかもボタンとかも設定していません、起動すると「override func viewDidLoad()内で読み込んだ複数ページのPDFが表示して「override func viewDidAppear(_ animated: Bool)」内の「pic印刷WebURL()」が呼ばれて印刷の準備に入ります、それでお終です ? で、「override func viewDidAppear(_ animated: Bool)」内に7種類の関数でそれぞれの印刷を表現していますね ? で、その7種類の関数から使用したい関数の前の//を削除して実行してください、関数は1つだけの利用が良いでしょうが複数の関数を使用しても一番最後の関数が評価されるので利用しない関数は//で封鎖してください

印刷は ? そのままでは複数ページの全部が印刷されてしまいます

印刷の際は少数ページの何かの自前のPDFファイルを読み込ませて印刷テストしてください

警告の嵐の解説 ?

何故か ? 沢山の警告が出るんですよね ? アプリの実行には影響は無いですが ? 私の意見

最初は ? 意味は? 「CIDToGIDMapエントリがないか、無効です」ですが ? 意味不明です

最初の警告.
missing or invalid CIDToGIDMap entry.

その次は ? これはWebを検索すると「このハングは、Xcodeで例外ブレークポイントが有効になっていて、例外が発生したために発生しました。 [UIPrintPageRenderer drawPageAtIndex:inRect:]の実装内で例外が発生していたようです。」っと解説されていますが ? 意味不明です

その次の警告.
2020-04-16 08:13:37.919588+0900 PrintPDF[1115:56426] [Unknown process name] Failed to load /System/Library/PrivateFrameworks/CorePDF.framework/Versions/A/CorePDF

次は沢山の警告が出ますが意味不明です

次は沢山の警告.
.notdef: no mapping.

ここまでは印刷用の関数が呼ばれる前に出ますね ?

override func viewDidAppear以後に出る警告は ? 検討しましたが意味不明で未解決の状態です

viewDidAppear以後の警告.
2020-04-16 08:38:00.595346+0900 PrintPDF[1162:69497] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x60000065ad50 UIView:0x7f8f8ad27160.width == UILabel:0x7f8f8ad24150'Page 1'.width + 28   (active)>",
    "<NSLayoutConstraint:0x60000065ada0 H:[UIImageView:0x7f8f8ac25f70]-(3)-[UILabel:0x7f8f8ad24150'Page 1'](LTR)   (active)>",
    "<NSLayoutConstraint:0x60000065b020 UIImageView:0x7f8f8ac25f70.width == 22   (active)>",
    "<NSLayoutConstraint:0x60000065b340 H:|-(0)-[UIImageView:0x7f8f8ac25f70](LTR)   (active, names: '|':UIView:0x7f8f8ad27160 )>",
    "<NSLayoutConstraint:0x60000065b1b0 UILabel:0x7f8f8ad24150'Page 1'.right == UIView:0x7f8f8ad27160.right   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60000065ada0 H:[UIImageView:0x7f8f8ac25f70]-(3)-[UILabel:0x7f8f8ad24150'Page 1'](LTR)   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
missing or invalid CIDToGIDMap entry.
missing or invalid CIDToGIDMap entry.
2020-04-16 08:38:01.976564+0900 PrintPDF[1162:69497] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600000652da0 UIView:0x7f8f8ac37090.width == UILabel:0x7f8f8ac36e10'Page 1'.width + 28   (active)>",
    "<NSLayoutConstraint:0x600000652e40 H:[UIImageView:0x7f8f8af22450]-(3)-[UILabel:0x7f8f8ac36e10'Page 1'](LTR)   (active)>",
    "<NSLayoutConstraint:0x600000653430 UIImageView:0x7f8f8af22450.width == 22   (active)>",
    "<NSLayoutConstraint:0x600000653520 H:|-(0)-[UIImageView:0x7f8f8af22450](LTR)   (active, names: '|':UIView:0x7f8f8ac37090 )>",
    "<NSLayoutConstraint:0x600000653570 UILabel:0x7f8f8ac36e10'Page 1'.right == UIView:0x7f8f8ac37090.right   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000652e40 H:[UIImageView:0x7f8f8af22450]-(3)-[UILabel:0x7f8f8ac36e10'Page 1'](LTR)   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
missing or invalid CIDToGIDMap entry.
missing or invalid CIDToGIDMap entry.

プリンター設定の「Printer Options」で印刷ページ指定をすると警告が出る

PrinterOptionsの警告.
2020-04-16 10:31:59.339151+0900 PrintPDFKit[1567:139881] [TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x7fcfef072a00; frame = (0 56; 614 632); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x60000022c210>; layer = <CALayer: 0x600000df9560>; contentOffset: {0, 0}; contentSize: {614, 770.5}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <_UIFilteredDataSource: 0x60000024c570>>

私の感想ですが ?

こんなに警告が出るとは ? 夢にも思いませんでした
さて、私にとって印刷は必要な部分なので作成中のアプリで作成した決算書とかの数ページのPDFファイルなどもiPadとかのデバイスから直接印刷できるようになりました
さて、前回の私が作成した「Swift4.2 Appleの「iOSにおける 描画と印刷のガイド」で印刷の話 ?」の私が書いたコードが現在の環境で作動しないので再挑戦したのが今回の複数ページのPDFを作成するきっかけになりました、前回のそれのコードは「UIActivityViewController」を利用した印刷でしたが ? 現在では以下のコードがないとポップアップが出現しません

印刷とかのボップアップが出ない.
//表示場所
            let screenSize = UIScreen.main.bounds
            avc.popoverPresentationController?.sourceRect = CGRect(x: screenSize.size.width/4, y: screenSize.size.height/2, width: 0, height: 0)

また、以前は「UIActivityViewController」を利用した印刷でも「UIPrintInteractionController」のdelegateを設定すれば「func printInteractionController」の「choosePaper paperList」とかでアプリがプリンターにアクセスして印刷可能のpaperListを確認することができていますが今回は「paperListのビクセル is 595.2755905511812,841.8897637795276」の表示数が少ないのですよね ?
以前は以下のように

前回の場合のpaperListの内容.
実行結果
     通過・rect -> (0.0, 0.0, 480.0, 680.0)
     iPadです・印刷物はフチなしで印刷されます

     pageSizeピクセル -> (595.2755905511812, 841.8897637795276)
     paperSizeミリ -> (210.00000000000003, 297.0)
     bestPaper -> (6.35, 6.35, 197.3, 276.53999999999996)

     paperListのビクセル is (252.0, 360.0)
     paperListのビクセル is (255.11811023622047, 581.1023622047244)
     paperListのビクセル is (283.46456692913387, 419.5275590551181)
     paperListのビクセル is (288.0, 432.0)
     paperListのビクセル is (296.98582677165354, 684.0)
     paperListのビクセル is (297.6377952755906, 419.5275590551181)
     paperListのビクセル is (297.6377952755906, 666.1417322834645)
     paperListのビクセル is (311.81102362204723, 623.6220472440945)
     paperListのビクセル is (323.1496062992126, 459.21259842519686)
     paperListのビクセル is (340.15748031496065, 666.1417322834645)
     paperListのビクセル is (360.0, 504.0)
     paperListのビクセル is (360.0, 576.0)
     paperListのビクセル is (362.8346456692913, 515.9055118110236)
     paperListのビクセル is (419.5275590551181, 566.9291338582677)
     paperListのビクセル is (419.5275590551181, 595.2755905511812)
     paperListのビクセル is (515.9055118110236, 728.503937007874)
     paperListのビクセル is (595.2755905511812, 841.8897637795276)
     paperListのビクセル is (612.0, 792.0)

     pageSizeピクセル -> (595.2755905511812, 841.8897637795276)
     paperSizeミリ -> (210.00000000000003, 297.0)
     bestPaper -> (0.0, 0.0, 210.00000000000003, 297.0)

それがおかしいと思いますが ? で、今回は「UIActivityViewController」から「UIPrintInteractionController」でdelegateを設定を設定してもpaperListが出ないんですよね ? しかし、1度位はpaperListの内容が表示したこともあるのですよね ? 不思議だっ ?

ここまで

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?