标签: pdfkit

使用pyobjc将元数据写入pdf

我正在尝试使用以下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)

python pdf cocoa pyobjc pdfkit

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

保存PDFKit中间件显示的PDF文件

如果有人有兴趣将PDF文件保存在PDFKit中间件gem所显示的文件系统中,那么这里是......

  1. 覆盖callmiddleware.rb文件的方法.
  2. 在覆盖中只需替换此行:

    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.

ruby ruby-on-rails pdfkit

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

Ruby On Rails:PdfKit运行时错误

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 wkhtmltopdf ruby-on-rails-3 ruby-on-rails-3.1

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

未应用PDFkit*.css样式表

我正在尝试使用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)

pdfkit ruby-on-rails-4

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

使用python pdfkit生成的pdf文件没有可点击的链接?

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)

html pdfkit html-to-pdf

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

如何禁用pdf视图(PDFKIT)内部滚动?

在我的mac应用程序pdfkit中使用pdf reader.while滚动鼠标滚动页面改变怎么可以避免.pdfview的显示模式是kPDFDisplaySinglePage.No需要工作滚动请帮帮我

pdf macos cocoa pdfkit ios

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

Pdfkit OSError:找不到wkhtmltopdf可执行文件

我正在尝试使用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)

python pdfkit wkhtmltopdf python-3.x

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

在不丢失图像的情况下无法使用Python中的PDFKit将SVG转换为PDF

我无法将我的.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代码。任何关于可能出问题的想法将不胜感激!

python pdf svg pdfkit

6
推荐指数
0
解决办法
293
查看次数

如何将图像从 URL 写入 PDFkit?

我使用 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)

javascript pdfkit node.js node-pdfkit

5
推荐指数
2
解决办法
6939
查看次数

PDFKIT IOS 11 A4 大小以保存 Swift

我有一个 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 ios swift swift4 ios11

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