我正在尝试使用以下python代码将元数据写入pdf文件:
from Foundation import *
from Quartz import *
url = NSURL.fileURLWithPath_("test.pdf")
pdfdoc = PDFDocument.alloc().initWithURL_(url)
assert pdfdoc, "failed to create document"
print "reading pdf file"
attrs = {}
attrs[PDFDocumentTitleAttribute] = "THIS IS THE TITLE"
attrs[PDFDocumentAuthorAttribute] = "A. Author and B. Author"
PDFDocumentTitleAttribute = "test"
pdfdoc.setDocumentAttributes_(attrs)
pdfdoc.writeToFile_("mynewfile.pdf")
print "pdf made"
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常(安慰没有错误),但是当我检查文件的元数据时,它如下:
PdfID0:
242b7e252f1d3fdd89b35751b3f72d3
PdfID1:
242b7e252f1d3fdd89b35751b3f72d3
NumberOfPages: 4
Run Code Online (Sandbox Code Playgroud)
原始文件具有以下元数据:
InfoKey: Creator
InfoValue: PScript5.dll Version 5.2.2
InfoKey: Title
InfoValue: Microsoft Word - PROGRESS ON THE GABION HOUSE Compressed.doc
InfoKey: Producer
InfoValue: GPL Ghostscript …Run Code Online (Sandbox Code Playgroud) 如果有人有兴趣将PDF文件保存在PDFKit中间件gem所显示的文件系统中,那么这里是......
callmiddleware.rb文件的方法.在覆盖中只需替换此行:
body = PDFKit.new(translate_paths(body, env), @options).to_pdf
Run Code Online (Sandbox Code Playgroud)
同
pdf = PDFKit.new(translate_paths(body, env), @options)
file = pdf.to_file('Your/file/name/path')
Mymodel.my_method() #You can write your method here to use that file
body = pdf.to_pdf #Here you can change the response body
Run Code Online (Sandbox Code Playgroud)如果您不想提供pdf响应,还可以覆盖response-body和content-type.如果您有任何进一步的查询,请继续.
这个过程真的很有帮助,因为当你在视图文件中使用大量的JavaScript时,render_to_string方法将无法工作,即它不会渲染繁重的JavaScript.
pdfkit gem成功安装在我的机器上.然后我跑gem install wkhtmltopdf-binary,输出了
Successfully installed wkhtmltopdf-binary-0.9.9.1
1 gem installed
Installing ri documentation for wkhtmltopdf-binary-0.9.9.1...
unable to convert "\xC0" from ASCII-8BIT to UTF-8 for bin/wkhtmltopdf_linux_386, skipping
unable to convert "\xA3" from ASCII-8BIT to UTF-8 for bin/wkhtmltopdf_linux_x64, skipping
unable to convert "\xCE" from ASCII-8BIT to UTF-8 for bin/wkhtmltopdf_darwin_386, skipping
Installing RDoc documentation for wkhtmltopdf-binary-0.9.9.1...
unable to convert "\xC0" from ASCII-8BIT to UTF-8 for bin/wkhtmltopdf_linux_386, skipping
unable to convert "\xA3" from ASCII-8BIT to UTF-8 for bin/wkhtmltopdf_linux_x64, skipping
unable to convert …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pdfkit将显示图像从facebook cdn转换为pdf的html页面.我使用rails 4.2,pdfkit 0.6.2和wkhtmltopdf-binary 0.9.9.3.
# Gemfile
gem 'pdfkit'
gem 'wkhtmltopdf-binary'
# controller
def generate_pdf
@booklet = Booklet.find params[:id]
@cover = Image.last
@images = @booklet.images.sort_by(&:uploaded_at)
respond_to do |format|
format.html
format.pdf do
html = render_to_string(layout: true , action: "generate_pdf.html.haml")
kit = PDFKit.new(html, page_size: 'A4', orientation: 'Landscape')
`sass vendor/assets/stylesheets/bootstrap.scss tmp/bootstrap.css`
`sass vendor/assets/stylesheets/custom.scss tmp/custom.css`
kit.stylesheets << "#{Rails.root}/tmp/bootstrap.css"
kit.stylesheets << "#{Rails.root}/tmp/custom.css"
pdf = kit.to_pdf
send_data pdf, filename: 'booklet.pdf', type: 'application/pdf'
end
end
end
# application.scss
@import 'bootstrap';
@import 'custom';
# config/application.rb
require 'pdfkit'
config.middleware.use …Run Code Online (Sandbox Code Playgroud) html文件看起来像
<div class="contact">
Phone: +00-0000000<br/>
E-mail: <a href="mailto:zsameem@gmail.com" >zsameem@gmail.com</a>
Github: <a href="https://www.github.com/zsameem">www.github.com/zsameem</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
gennerating pdf的代码很简单:
import pdfkit
pdfkit.from_file('mypage.html', 'mypdf.pdf;')
Run Code Online (Sandbox Code Playgroud) 在我的mac应用程序pdfkit中使用pdf reader.while滚动鼠标滚动页面改变怎么可以避免.pdfview的显示模式是kPDFDisplaySinglePage.No需要工作滚动请帮帮我
我正在尝试使用pdfkit将网页转换为PDF,但它显示以下错误
Traceback (most recent call last):
File "<ipython-input-39-33289a2ef087>", line 1, in <module>
runfile('H:/Python/Practice/pdf_read_write.py', wdir='H:/Python/Practice')
File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "H:/Python/Practice/pdf_read_write.py", line 10, in <module>
config = pdfkit.configuration(wkhtmltopdf="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")
File "C:\Program Files\Anaconda3\lib\site-packages\pdfkit\api.py", line 83, in configuration
return Configuration(**kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: No wkhtmltopdf executable found: "C:\Program Files\wkhtmltopdin\wkhtmltopdf.exe"
If this file exists please check that this process can …Run Code Online (Sandbox Code Playgroud) 我无法将我的.SVG文件转换为.PDF。我将.SVG代码嵌入html并尝试从字符串中加载pdf。除了嵌入的图像,其他所有内容都显示良好。他们根本不露面。这是图像的svg的示例...
<image xlink:href="data:image.png;base64, '...'" height="45", width="70", y="10", x="10" />
Run Code Online (Sandbox Code Playgroud)
其中的“ ...”用正确的base64字符串填充。我也亲自检查过base64代码。任何关于可能出问题的想法将不胜感激!
我使用 node.js 请求从 URL 获取 JPEG。然后我将图像转换为 base64 缓冲区并将其写入 pdf 文档:
request({ url: url, encoding: null }, function (error, response, body) {
if (!error && response.statusCode == 200) {
var img = new Buffer(body, 'base64');
pdf.image(img, 0, 0);
callback(error, body);
}
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
events.js:160
throw er; // Unhandled 'error' event
^
Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:156:17)
at PDFDocument.Readable.push (_stream_readable.js:134:10)
at PDFDocument._write (/Users/assafshamia/Freebird/node/utils/report_generator/node_modules/pdfkit/js/document.js:156:12)
at PDFReference.finalize (/Users/assafshamia/Freebird/node/utils/report_generator/node_modules/pdfkit/js/reference.js:81:21)
at PDFReference.finalize (/Users/assafshamia/Freebird/node/utils/report_generator/node_modules/pdfkit/js/reference.js:10:59)
at PDFReference.end (/Users/assafshamia/Freebird/node/utils/report_generator/node_modules/pdfkit/js/reference.js:74:21)
at JPEG.embed (/Users/assafshamia/Freebird/node/utils/report_generator/node_modules/pdfkit/js/image/jpeg.js:68:16)
at PDFDocument.image (/Users/assafshamia/Freebird/node/utils/report_generator/node_modules/pdfkit/js/mixins/images.js:34:15)
at addImage …Run Code Online (Sandbox Code Playgroud) 我有一个 PDF 套件,我想将文件保存为 A4 大小
这是我的代码
let newPagetxt = PDFPage(image:image!)
let apdf = PDFDocument()
apdf.insert(newPagetxt!, at:index)
apdf.documentAttributes!["Title"] = sampleFilenameTitle
apdf.documentAttributes!["Author"] = sampleFilenameAuthre
apdf.write(to: destination)
Run Code Online (Sandbox Code Playgroud)
如何使用一个标准类在 A4 中设置尺寸
pdfkit ×10
pdf ×3
python ×3
cocoa ×2
ios ×2
wkhtmltopdf ×2
html ×1
html-to-pdf ×1
ios11 ×1
javascript ×1
macos ×1
node-pdfkit ×1
node.js ×1
pyobjc ×1
python-3.x ×1
ruby ×1
svg ×1
swift ×1
swift4 ×1