标签: apple-pdfkit

PDFKit交换注释内容

可以在PDFKit中更改注释的文本(即contents)FreeText而不删除注释/构建新注释吗?

在以下位置查看时,以下代码段不会更改注释的内容PDFView:

let url = Bundle.main.url(forResource: "Test", withExtension: "pdf")!
let document = PDFDocument(url: url)!

for index in 0..<document.pageCount {
    let page: PDFPage = document.page(at: index)!
    let annotations = page.annotations
    for annotation in annotations {
        annotation.contents = "[REPLACED]"
    }
}
mainPDFView.document = document
Run Code Online (Sandbox Code Playgroud)

这有效 - 但需要替换注释(因此必须复制注释的所有其他细节):

let url = Bundle.main.url(forResource: "Test", withExtension: "pdf")!
let document = PDFDocument(url: url)!

for index in 0..<document.pageCount {
    let page: PDFPage = document.page(at: index)!
    let annotations = page.annotations
    for annotation …
Run Code Online (Sandbox Code Playgroud)

ios swift apple-pdfkit

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

iOS PDFKit 在 PDFView 中调整 pdf 框架

我有一个 PDF,其中包含不同高度的页面,我希望以水平分页方式显示,一次一页,页面之间没有间隙,并且每个页面的顶部与视图的顶部对齐。例如:

所需的渲染

我想使用PDFKit's PDFView,特别是因为这些设置可以通过以下方式实现:

let pdfView = PDFView()
pdfView.displayDirection = .horizontal
pdfView.displaysPageBreaks = false
pdfView.usePageViewController(true, withViewOptions: nil)
Run Code Online (Sandbox Code Playgroud)

但是,这会产生以下结果:

实际渲染

这是由于页面的高度不同。每个页面在 中垂直居中PDFView,如果页面的高度大于视图的高度(例如第 2 页),则按比例缩放以适应。

为了尝试解决第一个问题,垂直偏移,我尝试了几件事。首先,这是毛,我知道这是错的,检查视图层次结构,并找到个人视图(已命名的类的观点后PDFTextInputView,页面呈现内我已经试过调整其框架的)origin.y0时最外面的滚动视图(另一个私人视图)滚动。这是因为每当下一页或上一页滚动到视图中时,页面都会呈现在视图的顶部。但是,一旦用户捏住以放大该页面,其框架会自动跳回居中。除了依赖私有视图层次结构之外,这种方法是行不通的。

为了尝试解决“高页面问题”(第 2 页),我尝试在出现新页面时调整 PDFView 的比例因子。遗憾的是,.PDFViewPageChanged通知仅滚动视图结束减速才会触发,因此页面在滚动时会缩小,然后当我调整比例因子时,它会跳转以适应屏幕的宽度。然后我转向.PDFViewVisiblePagesChanged在下一页/上一页出现时确实会触发的.PDFViewPageChanged.

我尝试过的其他事情:

  • 调整transform文档视图
  • 截取捏合手势并调整文档视图的中心
  • 创建我自己的页面控制器并每页渲染一个 PDF 页面(不使用pdfView.usePageViewController

有没有人对我如何实现我所追求的有任何想法?

ios swift ios-pdfkit apple-pdfkit

6
推荐指数
1
解决办法
1524
查看次数

自定义 UIMenuItem 不适用于 PDFKit 的 PDFView

我正在尝试UIMenuItem为我的PDFView

这是我在示例 Xcode 项目中所做的

#import <PDFKit/PDFKit.h>
#import <objc/runtime.h>

#import "ViewController.h"

@interface ViewController ()

@property(nonatomic) PDFDocument *document;
@property(nonatomic) PDFView *pdfView;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.

  NSURL *pdfPath = [[NSBundle mainBundle] URLForResource:@"pdf" withExtension:@"pdf"];

  _document = [[PDFDocument alloc] initWithURL:pdfPath];
  _pdfView = [[PDFView alloc] initWithFrame:CGRectZero];
  _pdfView.document = _document;

  [self.view addSubview:_pdfView];

  _pdfView.translatesAutoresizingMaskIntoConstraints = NO;
  [_pdfView.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES;
  [_pdfView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
  [_pdfView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
  [_pdfView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES; …
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios-pdfkit apple-pdfkit ios13

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

如何去除PDF文档边距

我将 pdfdocument 添加到 PDFView 。但它显示了边缘,也显示了慢跑。如何去掉这个边距。有没有办法将 pdfdocument 设置到左上角位置。

在此输入图像描述

pdfview swift ios-pdfkit apple-pdfkit swift5

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

我可以在iOS 11中通过Storyboard添加PDFView吗?

我正在创建PDF阅读器类型的应用程序,我正在使用PDFKit该应用程序显示PDF文件.

我能够PDFView通过代码添加它的工作正常.

但是有可能我可以PDFView通过storyboardOutlet 添加,而不是通过Outlet我将PDF文件分配给该视图吗?

storyboard ios11 apple-pdfkit

3
推荐指数
1
解决办法
892
查看次数