简体   繁体   English

使用phantomjs合并PDF

[英]Merging PDFs with phantomjs

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 . 我已经制作了一个API,该API接受输入并使用html-pdf生成使用pdf传递的输入的服务器端pdf a / c。 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. 现在,需求已发生变化,我希望pdf的前4页以纵向模式显示,而其他所有4页之后的页面以横向模式显示。

But we can only define the orientation for complete pdf. 但是我们只能定义完整pdf的方向。 HERE 这里

So now, I tried to make two separate pdf 所以现在,我尝试制作两个单独的pdf

  1. starting 4 pages with portrait mode.(PDF -1) 以纵向模式开始4页。(PDF -1)
  2. rest of the pages with landscape mode.(PDF -2) 其余页面为横向模式。(PDF -2)

But I am not able to find a solution for merging those two separate pdfs(PDF -1 + PDF -2). 但是我找不到合并这两个单独的pdf(PDF -1 + PDF -2)的解决方案。 Is there any way to merge multiple pdf using phantomjs. 有没有办法使用phantomjs合并多个pdf。

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. 而且我已经制作了完整的pdf文件,所以我不想更改插件并再次完成完整的工作,但是,如果还有其他一些插件可以解决我的情况,那我也可以用它作为唯一的最后选择。

Thanks, 谢谢,

PhantomJS is not a PDF editor, it cannot edit or merge PDF. PhantomJS不是PDF编辑器,它不能编辑或合并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 有关PDF合并实用程序的各种选项,请参见此答案

For merging multiple PDFs, use the pdfkit and node-pdftk packages: 要合并多个PDF,请使用pdfkitnode-pdftk软件包:

// 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 您可以在这里找到代码: https : //github.com/rauniksingh/async-await-html-pdf---s3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM