How to create a multi-page pdf file from html

We need to print thousands of invoices that are in this format -

http://example.com/orders/n

where n = thousands of orders

Passing each order, and then clicking on "print" makes us spend time. Is there a way to create a multi-page PDF file from each of these URLs, which we can download as a single PDF file so that we can click “print” once?

+5
source share
3 answers

You can try ruby ​​script with PDFkit gem (wraps wkhtmltopdf).

pdf , , 50-100 , 1000- pdf ... , .

script, html :

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')
+6

wkhtmltopdf.

, Webkit pdf-.

0

- htmldoc - , wkhtmltopdf, , .

, htmldoc , , , .

0

All Articles