Closed Ethaan closed 8 years ago
@Ethaan PDFMerge takes file paths, not file buffers. PDFtk is an external resource used to merge the pdf files, and thus cannot accept buffers/objects. One would have to store the files locally temporarily first. Either this can be done in your code, or you're free to make a pull request addressing this issue.
@wubzz right now im doing something like this.
urlToFile: (files) ->
check(files, Array)
# array of files ready to be merged
filesResponse = []
# Keep track of each job in an array
futures = _.map(files, (file) ->
tempFile = null;
# Set up a future for the current job
future = new Future()
# A callback so the job can signal completion
onComplete = future.resolver()
file_url = file.fileUrl
options = {
host: url.parse(file_url).host,
port: 80,
path: url.parse(file_url).pathname
}
file_name = url.parse(file_url).pathname.split('/').pop()
tempFile = fs.createWriteStream(TEMP_FOLDER + file_name)
http.get options, (res) ->
res.on('data', (data) ->
tempFile.write data
).on 'end', ->
tempFile.end()
console.log file_name + ' downloaded to ' + TEMP_FOLDER
onComplete null, filesResponse.push tempFile.path
future
)
Future.wait futures
filesResponse
This code get the WEB URLs and create a write stream and store it on a temp folder.
Then i just call PDFMerge
with the array of temp paths and its working cool now (or atleast its returning the buffer, i need to convert that buffer to a PDF).
This is my use case.
I have an array of
pdf URLs
and im usingfs.createWriteStream
+http.get
to generate files on the backend.I get this working and im passing an array of objects to the
PDFMerge
likepdfMerge = new PDFMerge(pdfs)
But im getting an error of
Object [object Object] has no method 'replace'
, here is the full error.Question, im doing this in the correct way?