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

我的目标是搜索一个字符串,然后转到它。我有实现它所需的这三行代码。我只知道我实现这一目标的思维过程遗漏了一些东西。我不知道如何使用.findstring。我读到它返回一个 PDFSelections 数组。但我不确定如何使用.setCurrentSelectionPDFSelection 数组来使用它。
let found = document.findString(selection, withOptions: .caseInsensitive)
let stringSelection = page?.selection(for: NSRange(location:10, length:5))
pdfView.setCurrentSelection(stringSelection, animate: true)
Run Code Online (Sandbox Code Playgroud) 使用 PDFKit,我在我的应用程序中创建了一个 pdf 文档。我可以成功地在预览中显示它,并在预览控制器中使用以下代码向用户展示共享操作:
@objc func shareAction(_ sender: UIBarButtonItem)
{
if let data = documentData
{
let vc = UIActivityViewController(activityItems: [data], applicationActivities: [])
present(vc, animated: true, completion: nil
}
}
Run Code Online (Sandbox Code Playgroud)
documentData包含创建的 pdf 文档。
当用户选择“保存到文件”时,文档将获得默认名称“PDF Document.pdf”,用户可以更改该名称。
如何提供不同的默认文件名?
我想在 Swift 中使用苹果 PDFKit 框架更改 pdf 的背景颜色,但它不起作用。创建一些控件(如文本或图像)然后使用它不是问题,但我想更改文档本身的颜色。有没有人有任何想法或解决方案?
let renderer = UIGraphicsPDFRenderer(bounds: pageRect, format: format)
let data = renderer.pdfData { (context) in
context.beginPage()
let attributes = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 12),
NSAttributedString.Key.backgroundColor : UIColor.green
]
let text = "My pdf"
text.draw(in: CGRect(x: 0, y: 0, width: 200, height: 20), withAttributes: attributes)
//?
UIColor.blue.setFill()
UIColor.blue.setStroke()
//?
context.cgContext.setFillColor(cyan: 1.0, magenta: 1.0, yellow: 0.6, black: 1.0, alpha: 1.0)
}
return data
Run Code Online (Sandbox Code Playgroud) 我正在按照本指南创建 PDF,但我不明白必须在 myDrawnContent 函数上编写什么代码:https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf。 html#//apple_ref/doc/uid/TP30001066-CH214-CJBFFHHA
使用本指南,我可以使用以下功能创建 PDF:
-(void) MyCreatePDFFile:(CGRect)pageRect 文件名:(const char *)文件名;
我需要编写 -(void)myDrawContent:(CGContextRef) pdfContext; 代码 我想在顶部设置一个标题,在图像后面设置一个 NSImage 和一个 NSString,我该怎么做?
Addictionaly:为此我找到了这段代码:
NSString * path = @"/Users/admin/Downloads/prueba.pdf";
PDFDocument * pdf = [[PDFDocument alloc]init];
NSImage *image = [self getRepImage];
PDFPage * page = [[PDFPage alloc ] initWithImage:image];
[pdf insertPage:page atIndex: [pdf pageCount]];
[pdf writeToFile:path];
Run Code Online (Sandbox Code Playgroud)
它使用 NSImage 创建一个 pdf,但我如何添加文本?谢谢
ios-pdfkit ×5
swift ×3
ios ×2
apple-pdfkit ×1
cocoa ×1
files-app ×1
objective-c ×1
pdfview ×1
quartz-2d ×1
swift5 ×1