0

I have made an API that takes the input and generate a serverside pdf a/c to the inputs passed using pdf using html-pdf. Which will be then used by the client.

Now, requirements has changed and I want the starting 4 pages of the pdf to be in portrait mode and all the other pages after the 4th in landscape mode.

But we can only define the orientation for complete pdf.HERE

So now, I tried to make two separate pdf

  1. starting 4 pages with portrait mode.(PDF -1)
  2. rest of the pages with landscape mode.(PDF -2)

But I am not able to find a solution for merging those two separate pdfs(PDF -1 + PDF -2). Is there any way to merge multiple pdf using phantomjs.

And also I have made the complete pdf so I do not want to change the plugin and do the complete work again but, it will be fine if there is some other plugin that can solve my scenario I can use that as the only last option.

Thanks,

Community
  • 1
  • 1
GauRang Omar
  • 761
  • 7
  • 17

2 Answers2

0

PhantomJS is not a PDF editor, it cannot edit or merge PDF. But you can easily merge files from node just launching a specific program for that in a child process and feeding it the two files. For various options of utilities for PDF merging see this answer

Vaviloff
  • 13,291
  • 3
  • 39
  • 45
-1

For merging multiple PDFs, use the pdfkit and node-pdftk packages:

// dataFiles pass this as an array of string of your s3 object
// or buffer strings or paths & outputPath as a destination 

async combinePfds (dataFiles, outputPath){
  try {
    await pdftk.input(dataFiles).output(outputPath);      
  } catch (error) {
    console.log(error)
  }
}

You can find the code here: https://github.com/rauniksingh/async-await-html-pdf---s3

greim
  • 8,519
  • 6
  • 30
  • 33
Raunik Singh
  • 214
  • 1
  • 4