We need to print thousands of invoices that are in this format -
http://example.com/orders/n
where n = thousands of orders
Going through each order and then clicking on "print" is taking us a loooong time. Is there a way to create a multipage pdf from each of those URLs that we can download as one pdf so we can hit "print" once?
You could try a ruby script using the PDFkit gem (wraps wkhtmltopdf).
I would suggest splitting your pdf's into probably 50 to 100 pages each, don't like the thought of a 1000 page pdf in memory... probably fall over.
Example script, concats pages into one big html string with page break divs and saves to 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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With