Created
May 28, 2019 14:46
-
-
Save fukajun/85472085c3e7f0f8b27a9c718449d144 to your computer and use it in GitHub Desktop.
Convert pdf size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'combine_pdf' | |
#require 'prawn' | |
def crop(page, x1, y1, x2, y2) | |
size = page.page_size | |
x1_new = size[0] - x1 | |
y1_new = size[1] - y1 | |
x2_new = size[2] + x2 | |
y2_new = size[3] + y2 | |
page.mediabox = [x1_new, y1_new, x2_new, y2_new] | |
page.cropbox = [x1_new, y1_new, x2_new, y2_new] | |
end | |
pdf2 = CombinePDF.load('./sample.pdf') | |
puts pdf2.pages[0].page_size | |
pdf2.pages.each do |page| | |
crop(page, 40, 40, 40, 40) | |
end | |
puts pdf2.pages[0].page_size | |
pdf2.save('converted2.pdf') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment