Skip to content

Instantly share code, notes, and snippets.

@hiroyuki-sato
Last active October 8, 2015 09:59
Show Gist options
  • Save hiroyuki-sato/ce48110f34accec1f837 to your computer and use it in GitHub Desktop.
Save hiroyuki-sato/ce48110f34accec1f837 to your computer and use it in GitHub Desktop.
combine.pdf

It is possible to combine mulitple pdf files with dest link?

Combine pdf

require 'combine_pdf'

pdf = CombinePDF.new
pdf << CombinePDF.load("pdf_with_link.pdf") # one way to combine, very fast.
pdf << CombinePDF.load("pdf_no_link.pdf")

pdf.save "combine.pdf"

Generate pdf which has a link.

require "prawn"
require "prawn/measurement_extensions"

pdf = Prawn::Document.new({:page_size => 'A4', :margin => [10.mm,10.mm,10.mm,10.mm]})
pdf.start_new_page
pdf.add_dest("page-2",pdf.dest_fit())
pdf.text_box("Dest place")

pdf.go_to_page(1) 
pdf.text_box("<link anchor=\"page-2\">This is link</link>",
				 { :at => [0,pdf.bounds.height],
					:width  => pdf.bounds.width,
					:height => pdf.bounds.height,
					:valign => :center,
					:align  => :center,
					:size => 14,
					:inline_format => true })

pdf.render_file("pdf_with_link.pdf")

Generate pdf

require "prawn"

Prawn::Document.generate("pdf_no_link.pdf") do
  text "Hello World!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment