1

API of docverter is mentioned in curl format as shown below

curl \
  http://c.docverter.com/convert \
  -F from=html \
  -F to=pdf \
  -F input_files[]=@<(echo hello)

API states that input_files[] value should be a multipart/form-data file upload but in my AngularJS application, I am dynamically generating a report (at a specific route) which means it is not an html file which can be uploaded using file upload control.

My question may be bit vague because by looking at the docverter API, I am not able to know what code goes on client and what goes on server.

Overall I am looking for a solution which converts the generated HTML (along with stylesheet) to PDF file and this PDF file is then downloaded to the browser.

On the server side, I am using Node.js. Appreciate if you can provide clarity on how this conversion happens.

Ritesh Jagga
  • 1,387
  • 1
  • 11
  • 23
  • No. Eventually I dropped it and used phantomjs on server side to convert html to pdf. Let me know if you want to know this. – Ritesh Jagga Apr 26 '16 at 06:35
  • 1
    I'm on a mission to get this one handled... and with no go-between server. I'm avoiding the phantomjs method because it's heavy server side and only solves pdf's I need docx and rtf as well. – unsalted Apr 26 '16 at 13:49

1 Answers1

0

Ok here is the server side fix to get the cors issues worked out with docverter.

It's actually very little code to get it up and running.

These changes happen in lib/docverter-server/app.rb

class DocverterServer::App < Sinatra::Base

# added code starts here ==>

before do
  headers 'Access-Control-Allow-Origin' => '*', 
          'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST'] ,
          'Access-Control-Allow-Headers' => 'Content-Type',
          'Content-Disposition'  => 'attachment',
          'Content-Type' => 'application/octet-stream'
end

# <=== added ends starts here

set :show_exceptions, false

To fix errors so they don't just show cors conflicts

[500, {'Content-Type' => 'application/json', 'Access-Control-Allow-Origin' => '*'}, [MultiJson.dump(hash)]]

in lib/docverter-server/error-handler.rb

As for the angular client side => I document that fix with my own stack question here:

uploading text blob as file using $http or $resource with angular.js - mimicking curl style multipart/form upload

Community
  • 1
  • 1
unsalted
  • 355
  • 3
  • 14
  • Thanks for your wonderful efforts. As of now, I am going to stick with phantomjs but would definitely try out your solution in the linked question. I'll be needing docx conversion in the near future. Thanks a lot, I'm marking it as accepted answer as it has given me direction, lots of useful concepts about FormData and Blob and solution. – Ritesh Jagga Apr 27 '16 at 06:37