我的网络应用程序是用 Flask 编写的。我想将 jinja 模板(HTML 格式)转换为 PDF 文件。我使用 pythonanywhere.com 作为我的应用程序的主机。
我已经使用 Flask 使用在开发环境 fedora31 上运行的 pdfkit、wkhtmltopdf、jinja2 成功生成了动态 PDF。当尝试在 pythonanywhere 环境中安装 pdfkit 时,我收到消息权限被拒绝。
对于 weasyprint,还需要安装库;这也是 pythonanywhere.com 的限制。
xhtml2pdf 的情况也是如此,无法在 pythonanywhere.com 安装
总结:pdfkit、weasyprint、xhtml2pdf 目前不是可行的替代方案,但需要在 pythonanywhere.com 安装这些库
pythonanywhere.com 安装新库有此限制。
我的问题是:
知道我的 Flask 应用程序需要 pythonanywhere.com 提供的环境才能运行,我必须采取哪些可行的替代方案将 jinja 模板转换为 PDF 格式?
任何解决这种情况的指导将不胜感激。谢谢。
我正在使用 PDFKIT 在 pdf 上画一条线。我覆盖触摸开始,移动等如下记录我在pdfView的documentView上的触摸如下:
override func touchesMoved(_ touches: Set<UITouch>,
with event: UIEvent?) {
// 6
swiped = true
if let touch = touches.first {
let currentPoint = touch.location(in: pdfView.documentView)
drawLineFrom(fromPoint: lastPoint, toPoint: currentPoint)
addAnnotation(fromPoint: lastPoint, toPoint: currentPoint)
// 7
lastPoint = currentPoint
}
}
Run Code Online (Sandbox Code Playgroud)
但是,正如您从下面的图片中看到的(黑线是我触摸屏幕的位置,红线是绘制注释的位置)。触摸坐标系是屏幕左上角的 (0,0),而 pdf 是从屏幕左下角 (0,0) 注释的。
我的添加注解功能如下:
func addAnnotation(fromPoint: CGPoint, toPoint: CGPoint) {
let page = pdfView.document?.page(at: 0)
let bounds = CGRect(x: 0, y: 0, width: 600, height: 600)
let line = PDFAnnotation(bounds: bounds, forType: …Run Code Online (Sandbox Code Playgroud) 我正在尝试PDFView,并希望突出显示搜索到的单词。我在这里关注这个小教程(请参阅搜索段落)。
我正在为我的PDF找到匹配项,但是当我设置时pdfView.highlightedSelections = searchedItems什么也没发生。
这是我的代码(VC扩展了PDFDocumentDelegate)
var document: PDFDocument!
var searchedItems: [PDFSelection] = []
override func viewDidLoad() {
super.viewDidLoad()
let url = Bundle.main.url(forResource: "test3", withExtension: "pdf")
document = PDFDocument(url: url!)
pdfView.document = document
pdfView.document?.delegate = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
pdfView.document?.findString("Product", withOptions: .caseInsensitive)
}
func documentDidEndDocumentFind(_ notification: Notification) {
pdfView.highlightedSelections = nil
pdfView.highlightedSelections = searchedItems
}
func documentDidFindMatch(_ notification: Notification) {
if let selection = notification.userInfo?.first?.value as? PDFSelection {
selection.color = …Run Code Online (Sandbox Code Playgroud) 我正在使用PDFKit在PDF文件上绘制一些墨迹注释.但我无法改变线条的宽度.我以为这样做:
let path = UIBezierPath()
path.lineWidth = 20 // important line
path.move(to: originPoint)
path.addLine(...)
annotation.add(path)
Run Code Online (Sandbox Code Playgroud)
因为在Core Graphics中绘制时修改Bezier路径的lineWidth是可行的.但是在这里,它没有改变任何东西,那么如何改变注释的线宽?
当我尝试使用pdfkit显示pdf文件时,应用程序崩溃。这是简单的示例?:
import UIKit
import PDFKit
class ViewController: UIViewController {
@IBOutlet weak var pdfView: PDFView!
override func viewDidLoad() {
super.viewDidLoad()
if let path = Bundle.main.path(forResource: "file", ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfView.displayMode = .singlePageContinuous
pdfView.autoScales = true
// pdfView.displayDirection = .horizontal
pdfView.document = pdfDocument
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这会因“未捕获的异常'CALayerInvalidGeometry'而崩溃,原因:'CALayer位置包含NaN:[nan nan]'”:
2019-03-26 21:09:47.837837+0400 pdfKitTest[3163:93151] libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.
2019-03-26 21:09:47.927078+0400 pdfKitTest[3163:93151] *** Terminating app due to uncaught …Run Code Online (Sandbox Code Playgroud) 我使用 swift 和 PDFKit 成功地将突出显示注释添加到 pdf 中,但我无法弄清楚如何让用户再次删除突出显示。
用户可以正常选择文本,然后从 UIMenu 中选择“突出显示”或“删除突出显示”。
为了在选择文本时自定义 pdfView,我更改了显示的菜单 - 首先删除默认操作:
extension PDFView {
override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
然后在 viewDidLoad() 中我设置了自定义 UIMenuItems:
let menuItem1 = UIMenuItem(title: "Highlight", action: #selector(highlightSelection(_:)))
let menuItem2 = UIMenuItem(title: "Remove highlight", action: #selector(removeHighlightSelection(_:)))
UIMenuController.shared.menuItems = [menuItem1, menuItem2]
Run Code Online (Sandbox Code Playgroud)
选择突出显示时:
@objc func highlightSelection(_ sender: UIMenuItem) {
let selections = pdfViewer.currentSelection?.selectionsByLine()
guard let page = selections?.first?.pages.first else { return }
selections?.forEach({ selection in
let …Run Code Online (Sandbox Code Playgroud) 无法在ios 10中创建水平滚动PDF视图.这在iOS 11中是否可行?使用PDFKit - PDFView?
pdfkit ×7
swift ×6
ios ×4
annotations ×3
pdfview ×2
flask ×1
highlight ×1
ios11 ×1
objective-c ×1
pdf ×1
python-3.x ×1
touch ×1
xcode10.2 ×1