简体   繁体   English

PDFKit - 如果没有 usePageViewController(),PdfView 将不会是 RTL

[英]PDFKit - PdfView won't be RTL without usePageViewController()

I want to display PDF with horizontal, pages from right to left, page by page continuously, and users pinch one page will make all pages the same scale synchronized.我想水平显示PDF,从右到左,一页一页地连续显示,用户捏一页将使所有页面同步相同的比例。

I wrote the codes as below:我写的代码如下:

        if let pdfDocument = PDFDocument(url: pdfUrl) {
            pdfView.document = pdfDocument
            pdfView.displayMode = .singlePageContinuous
            pdfView.displaysRTL = true
            pdfView.autoScales = true
            pdfView.autoresizesSubviews = true
            pdfView.displayDirection = .horizontal
            pdfView.displaysPageBreaks = true
            pdfView.pageBreakMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
            
            pdfView.maxScaleFactor = 4.0
            pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
        }

But displaysRTL will not work, and default scale will not show whole single page but fit to the PDF page height (page right side will out of screen).但是 displayRTL 不起作用,并且默认比例不会显示整个单页但适合 PDF 页面高度(页面右侧将超出屏幕)。

If I add如果我添加

pdfView.usePageViewController(true)

PDF displayRTL works, and every page will fit screen size by default. PDF displayRTL 有效,默认情况下每个页面都适合屏幕大小。 BUT this will make PDF not displayed page by page, and zoom in scale will not the same with other pages.但这会使 PDF 无法逐页显示,并且放大比例将与其他页面不同。

添加 usePageViewController(true) 后的结果

The left page scale is not the same with current zoom in page on the right side.左侧页面比例与右侧当前放大页面不同。 I need them all the same scale if user pinch a page.如果用户捏住页面,我需要它们都具有相同的比例。

Is there any way to fix this problem?有没有办法解决这个问题?

In addition, every page's top-left corner will display an icon, I don't know what is it mean and how to hide it..另外,每个页面的左上角都会显示一个图标,不知道是什么意思,怎么隐藏。。

I find a way that make it displayRTL manually.我找到了一种让它手动显示RTL的方法。
Don't use usePageViewController(true) , and just reordering the pages from the PDFDocument.不要使用usePageViewController(true) ,而只是从 PDFDocument 重新排序页面。

let doc = PDFDocument()
var getPage = pdfDocument.pageCount - 1
for i in 0..<pdfDocument.pageCount {
    guard let pageRef = pdfDocument.page(at: getPage) else { fatalError() }
    doc.insert(pageRef, at: i)
    getPage -= 1
}
pdfView.document = doc

// Display PDF from last page if Right to Left
if (isPageRTL) {
    pdfView.goToLastPage()
} 

I found PDFView by Apple will get memory leak and crash if PDF is large in iOS 12 and iOS 13 (iOS 14 seems to be fine).我发现如果 PDF 在 iOS 12 和 iOS 13(iOS 14 似乎没问题)中过大,Apple 的 PDFView 会出现内存泄漏和崩溃。 So I have to find other way to display PDF that fit my need.所以我必须找到其他方式来显示符合我需要的 PDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM