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

Possible to concatenate multiple HTML files into one PDF file? #33

Open
thokari opened this issue Dec 4, 2014 · 14 comments
Open

Possible to concatenate multiple HTML files into one PDF file? #33

thokari opened this issue Dec 4, 2014 · 14 comments

Comments

@thokari
Copy link

thokari commented Dec 4, 2014

Basically just like this: http://explicate.blogspot.de/2011/01/multiple-html-files-to-single-pdf-with.html

@mauvm
Copy link

mauvm commented Feb 10, 2015

+1, since this is standard behaviour of the wkhtmltopdf CLI. A possible solution would be:

wkhtmltopdf({
    '/path/to/file1.html': { pageSpecificOptions: 'here' },
    '/path/to/file2.html': {}
}, { output: 'out.pdf' })

What do you think?

@thokari
Copy link
Author

thokari commented Feb 13, 2015

I'd definitely take it ;)

@mauvm
Copy link

mauvm commented Mar 3, 2015

It hit me that my suggested solution won't work because the order of elements in an object are not guaranteed (http://stackoverflow.com/a/5525820/1453912). So it should be something like this:

wkhtmltopdf([
    { file: '/path/to/file1.html', options: { pageSpecificOptions: 'here' } },
    { file: '/path/to/file2.html', options: {} },
], { output: 'out.pdf' })

@jeroenkruis
Copy link

This would indeed make a great feature.

+1

@knassar
Copy link

knassar commented Oct 13, 2015

PR #53 adds support for this. Also adds a couple of tests using Mocha. Feedback appreciated.

@dennismonsewicz
Copy link

+1 on that PR! I am using that branch currently and it works like a charm!!

@peruzzo
Copy link

peruzzo commented Dec 17, 2015

+1

@IAMtheIAM
Copy link

no update in a year?

@bosslee
Copy link

bosslee commented May 6, 2017

Any updates :)?

@tokra
Copy link

tokra commented Sep 18, 2017

is there any progress here ? thank you

@jamespsterling
Copy link

Looking for the same thing

@Andreew4x4
Copy link

For e.g if u have:
my-html-file-nr-1.html
my-html-file-nr-2.html
....
my-html-file-nr-n.html
You can simply:

wkhtmltopdf my-html-file-nr-* output.pdf

@dobon
Copy link

dobon commented Sep 17, 2018

I have created a pull request to fix this issue: #119

@SubhamSubhasisPatra
Copy link

I was trying to do the same thing in GO it worked ..

package main

import (
	"bytes"
	"log"
	"os"

	"github.com/SebastiaanKlippert/go-wkhtmltopdf"
)

func CustomError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {

	pdfg, err := wkhtmltopdf.NewPDFGenerator()

	CustomError(err)

	pdfg.NoCollate.Set(false)
	pdfg.MarginTop.Set(0)
	pdfg.MarginBottom.Set(0)
	pdfg.MarginLeft.Set(0)
	pdfg.MarginRight.Set(0)

	html1, _ := os.ReadFile("./index.ejs") // or the html as a string
	html2, _ := os.ReadFile("./index.ejs")
	html3, _ := os.ReadFile("./index.ejs")

	arr := []string{string(html1), string(html2), string(html3)}

	buf := new(bytes.Buffer)

	// itterate over the array and add each page to the pdf
	for _, html := range arr {
		buf.WriteString(html)
		buf.WriteString(`<P style="page-break-before: always">`)
	}

	pdfg.AddPage(wkhtmltopdf.NewPageReader(buf))

	err = pdfg.Create()

	CustomError(err)

	err = pdfg.WriteFile("simple.pdf")

	CustomError(err)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests