Bạn có thể thử tập lệnh ruby bằng cách sử dụng đá quý PDFkit (kết thúc tốt đẹp wkhtmltopdf).
Tôi khuyên bạn nên chia nhỏ tệp pdf của bạn thành 50 đến 100 trang, không thích suy nghĩ của 1000 trang pdf trong bộ nhớ ... có thể bị đổ.
Ví dụ kịch bản, concats trang thành một chuỗi html lớn với divs ngắt trang và tiết kiệm sang file:
require 'rubygems'
require 'open-uri'
require 'pdfkit'
PDFKit.configure do |config|
config.wkhtmltopdf = '/path/to/wkhtmltopdf'
end
invoice_numbers = (1..1000) #replace with actual numbers
html = ""
invoice_numbers.each do |n|
html << open("http://example.com/orders/#{n}").read + "<div style='page-break-before:always'></div>"
end
pdf = PDFKit.new(html, :page_size => 'Letter')
pdf.to_file('/path/to/invoices.pdf')
Nguồn
2011-12-19 13:32:23
[PrinceXML] (http://princexml.com/) là trình kết xuất HTML to PDF tuyệt vời. – chesles