Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PDF request summary #6257

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/controllers/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,13 +678,18 @@ def make_request_summary_file(info_request)
tmp_input.write(html_output)
tmp_input.close
tmp_output = Tempfile.new('foihtml2pdf-output')
output = AlaveteliExternalCommand.run(convert_command, tmp_input.path, tmp_output.path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we could make this work by changing the convert_command to preserve the interface here.

# config/general.yml
HTML_TO_PDF_COMMAND: "/usr/local/bin/wkhtmltopdf -q"

If this works then we'll want to update config/general.yml-example so that it gets set like this for everyone, and also note in the changelog that this is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work without additional changes as this would eval to false:

convert_command = AlaveteliConfiguration.html_to_pdf_command
File.exist?(convert_command)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like:

# Default
HTML_TO_PDF_COMMAND: "/usr/local/bin/wkhtmltopdf"

# Optional
HTML_TO_PDF_COMMAND: ["/usr/local/bin/wkhtmltopdf", "-q"]
convert_command = Array(AlaveteliConfiguration.html_to_pdf_command)
cmd = convert_command.shift
File.exist?(cmd)
output = AlaveteliExternalCommand.run(cmd, convert_command, tmp_input.path, tmp_output.path)

output = AlaveteliExternalCommand.run(
convert_command, '-q', tmp_input.path, tmp_output.path
)
if !output.nil?
file_info = { :filename => 'correspondence.pdf',
:data => File.open(tmp_output.path).read }
done = true
else
logger.error("Could not convert info request #{info_request.id} to PDF with command '#{convert_command} #{tmp_input.path} #{tmp_output.path}'")
logger.error(
"Could not convert info request #{info_request.id} to PDF with " \
"command '#{convert_command} #{tmp_input.path} #{tmp_output.path}'"
)
end
tmp_output.close
tmp_input.delete
Expand Down