Skip to content

Instantly share code, notes, and snippets.

@kaz
Created February 15, 2023 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaz/dadd83c9fef06fa48b6054f65b1a8544 to your computer and use it in GitHub Desktop.
Save kaz/dadd83c9fef06fa48b6054f65b1a8544 to your computer and use it in GitHub Desktop.
require "hexapdf"
in1 = HexaPDF::Document.open("aaa.pdf")
in2 = HexaPDF::Document.open("bbb.pdf")
out = HexaPDF::Document.new
[in1.pages.to_a, in2.pages.to_a.reverse].transpose.flatten.each do |page|
out.pages << out.import(page)
end
out.write("xxx.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment