CoreGraphics PDF 记录了一个错误。设置环境变量“CG_PDF_VERBOSE”以了解更多信息

Nud*_*dge 4 ios dart flutter

我正在尝试在我的 Flutter 应用程序中嵌入 iOS PDFKit。以下是我的代码

public class PDFCustomView: NSObject, FlutterPlatformView {

    let frame: CGRect
    let viewId: Int64

    init(_ frame: CGRect,viewId: Int64, args: Any?){
        self.frame = frame
        self.viewId = viewId
    }

    public func view() -> UIView {
        let pdfView = PDFView(frame: frame)
        if let path = Bundle.main.path(forResource: "studenthandbook2018", ofType: "pdf") {
            let url = URL(fileURLWithPath: path)
            if let pdfDocument = PDFDocument(url: url) {
                pdfView.displayMode = .singlePageContinuous
                pdfView.autoScales = true
                pdfView.document = pdfDocument
            }
        }
        return PDFView()
    }

}

public class PdfViewFactory: NSObject, FlutterPlatformViewFactory {
    public func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?)
        -> FlutterPlatformView {
        return PDFCustomView(frame,viewId: viewId,args: args)
    }
}

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

    let viewFactory = PdfViewFactory()
    registrar(forPlugin: "iospdf").register(viewFactory, withId: "PDFIOSView")

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
Run Code Online (Sandbox Code Playgroud)

我还包括

<key>io.flutter.embedded_views_preview</key>
    <true/>
Run Code Online (Sandbox Code Playgroud)

info.plist

PDFView我没有返回,而是尝试返回UISLider,它在我的应用程序中正常工作,但 PDFkit 给出错误提示CoreGraphics PDF has logged an error. Set environment variabe "CG_PDF_VERBOSE" to learn more.

这是 Flutter 错误还是我做错了什么?

den*_*niz 10

第 1 步:如图所示编辑您的方案 在此处输入图片说明

第 2 步:添加一个新的环境变量,如下所示: 在此处输入图片说明

第 3 步:查看 XCode 日志上显示的错误。就我而言,它正在打印

缺少或无效的 CIDToGIDMap 条目。

快速搜索表明我使用的 pdf 文件可能缺少一些嵌入字体。