The left, right, and flip do not work with .gif files: Exception: #<Errno::ENOENT: No such file or directory @ unlink_internal - /tmp/ICLA_YuriGor_1.gif20181030-11199-4le8w9-rotated.pdf>
Craig > Begin forwarded message: > > From: ru...@apache.org > Subject: [whimsy] branch master updated: switch from convert and pdftk to: > Date: October 28, 2018 at 3:00:07 PM PDT > To: "comm...@whimsical.apache.org" <comm...@whimsical.apache.org> > Reply-To: dev@whimsical.apache.org > > This is an automated email from the ASF dual-hosted git repository. > > rubys pushed a commit to branch master > in repository https://gitbox.apache.org/repos/asf/whimsy.git > > > The following commit(s) were added to refs/heads/master by this push: > new bbc038b switch from convert and pdftk to: > bbc038b is described below > > commit bbc038b6664bbc4a68ede8597df50f03cfc107cd > Author: Sam Ruby <ru...@intertwingly.net> > AuthorDate: Sun Oct 28 17:55:56 2018 -0400 > > switch from convert and pdftk to: > > - pdf90 > - pdf180 > - pdf270 > - pdfseparate > - pdfunite > --- > www/secretary/workbench/models/attachment.rb | 2 +- > www/secretary/workbench/views/actions/burst.json.rb | 6 +++--- > www/secretary/workbench/views/actions/drop.json.rb | 3 +-- > .../workbench/views/actions/rotate-attachment.json.rb | 18 ++++++++++-------- > 4 files changed, 15 insertions(+), 14 deletions(-) > > diff --git a/www/secretary/workbench/models/attachment.rb > b/www/secretary/workbench/models/attachment.rb > index 08dffbf..edeea31 100644 > --- a/www/secretary/workbench/models/attachment.rb > +++ b/www/secretary/workbench/models/attachment.rb > @@ -61,7 +61,7 @@ class Attachment > > if IMAGE_TYPES.include? ext or content_type.start_with? 'image/' > pdf = SafeTempFile.new([safe_name, '.pdf']) > - system 'convert', file.path, pdf.path > + system 'img2pdf', '--output', pdf.path, file.path > file.unlink > return pdf > end > diff --git a/www/secretary/workbench/views/actions/burst.json.rb > b/www/secretary/workbench/views/actions/burst.json.rb > index 817c475..0a6143d 100644 > --- a/www/secretary/workbench/views/actions/burst.json.rb > +++ b/www/secretary/workbench/views/actions/burst.json.rb > @@ -10,10 +10,10 @@ begin > source = message.find(@selected).as_pdf > > Dir.mktmpdir do |dir| > - Kernel.system 'pdftk', source.path, 'burst', 'output', > - "#{dir}/page_%06d.pdf" > + Kernel.system 'pdfseparate', source.path, "#{dir}/page_%d.pdf" > > - pages = Dir["#{dir}/*.pdf"].sort.map {|name| name.untaint} > + pages = Dir["#{dir}/*.pdf"].map {|name| name.untaint} > + sort_by {|name| name[/d+/].to_i} > > format = @selected.sub(/\.\w+$/, '') + > "-%0#{pages.length.to_s.length}d.pdf" > diff --git a/www/secretary/workbench/views/actions/drop.json.rb > b/www/secretary/workbench/views/actions/drop.json.rb > index b9f67e3..d227043 100644 > --- a/www/secretary/workbench/views/actions/drop.json.rb > +++ b/www/secretary/workbench/views/actions/drop.json.rb > @@ -10,8 +10,7 @@ begin > > output = SafeTempFile.new('output') # N.B. this is created as binary > > - Kernel.system 'pdftk', target.path, source.path, 'cat', 'output', > - output.path > + Kernel.system 'pdfunite', target.path, source.path, output.path > > name = @target.sub(/\.\w+$/, '') + '.pdf' > > diff --git a/www/secretary/workbench/views/actions/rotate-attachment.json.rb > b/www/secretary/workbench/views/actions/rotate-attachment.json.rb > index cbf831d..3c0ae26 100644 > --- a/www/secretary/workbench/views/actions/rotate-attachment.json.rb > +++ b/www/secretary/workbench/views/actions/rotate-attachment.json.rb > @@ -7,21 +7,23 @@ message = Mailbox.find(@message) > begin > selected = message.find(@selected).as_pdf > > - direction = 'Right' if @direction.include? 'right' > - direction = 'Left' if @direction.include? 'left' > - direction = 'Down' if @direction.include? 'flip' > + tool = 'pdf270' if @direction.include? 'right' > + tool = 'pdf90' if @direction.include? 'left' > + tool = 'pdf180' if @direction.include? 'flip' > > - output = SafeTempFile.new('output') > + Dir.chdir File.dirname(selected.path) do > + Kernel.system tool, '--quiet', '--suffix', 'rotated', selected.path > + end > > - Kernel.system 'pdftk', selected.path, 'cat', "1-end#{direction}", 'output', > - output.path > + output = selected.path.sub(/\.pdf$/, '-rotated.pdf') > + puts output > > # If output file is empty, then the command failed > raise "Failed to rotate #{@selected}" unless File.size? output > > name = @selected.sub(/\.\w+$/, '') + '.pdf' > > - message.update_attachment @selected, content: output.read, name: name, > + message.update_attachment @selected, content: IO.binread(output), name: > name, > mime: 'application/pdf' > > rescue > @@ -29,7 +31,7 @@ rescue > raise > ensure > selected.unlink if selected > - output.unlink if output > + File.unlink output if output > end > > {attachments: message.attachments, selected: name} > Craig L Russell Secretary, Apache Software Foundation c...@apache.org <mailto:c...@apache.org> http://db.apache.org/jdo <http://db.apache.org/jdo>