Giter Site home page Giter Site logo

go-wkhtmltopdf's People

Contributors

arsalankhairani avatar arturwwl avatar hansmi avatar joeke80215 avatar kohkimakimoto avatar mmollick avatar rodaine avatar sebastiaanklippert avatar testwill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-wkhtmltopdf's Issues

Setting Page Header HTML option

Hello,

I am looking through the library for how to set the HeaderHTML Option for a page. I noticed that for globals I can just do something like:

pdf.PageSize.Set(wkhtmltopdf.PageSizeA4)

But what about for something like PageOptions?
HeaderHTML is a stringOption, so what is the best way to set it?

page.Allow.Set(path) maybe not work

html file code like:

<body>
    <header class="clearfix">
      <div id="logo">
        <img src="logo.png">
      </div>
...
</body>

html file and logo.png directory at /Users/xushike/go/src/my_project/example, i have set

page.Allow.Set("/Users/xushike/go/src/my_project/example")
...
pdfg.WriteFile("/Users/xushike/go/src/my_project/example/output.pdf")

and then run go run main.go,i get output.pdf,but there is only text ,no logo.png in it.

Write to buffer

I didn't find any direct way, so here's my question: Is there any good way to directly write to a Writer buffer?

The context is to generate a PDF and directly send it through the http.ResponseWriter.

problems running

Hello,

I have download and tried to compile your basic wrapper for wkhtmltopdf with your code:

package wkhtmltopdf

import (
"fmt"
"log"
)

func ExampleSimple() {

pdfg, err := NewPDFGenerator()
if err != nil {
    log.Fatal(err)
}

pdfg.AddPage(NewPage("https://github.com/SebastiaanKlippert/go-wkhtmltopdf"))
err = pdfg.Create()
if err != nil {
    log.Fatal(err)
}
err = pdfg.WriteFile("./simplesample.pdf")
if err != nil {
    log.Fatal(err)
}
//Or to use the raw PDF data
//pdf := pdfg.Bytes()

but am getting an error:

spartan:~/work/go-wkhtmltopdf$ go build

_/home/lonnie/work/go-wkhtmltopdf

./main.go:4: imported and not used: "fmt"
./main.go:10: undefined: NewPDFGenerator
./main.go:15: undefined: NewPage

Can you please advise on how to fix this?

Thanks,
Lonnie

Multiple pages from memory

Hi, I want to create a multi-page document from [][]byte

My current code is like this, where pages is of [][]byte type

for _, p := range pages {
	if len(p) == 0 {
		return nil, errors.New("blank page encountered")
	}
	page := wkhtmltopdf.NewPageReader(strings.NewReader(string(p)))
	pdfg.AddPage(page)
}

However, it seems that it's only producing one page of content, with the rest of pages being blank. I'm guessing it's something to do with this part inside func (pdfg *PDFGenerator) run() error, where the content of page is only being read once.

for _, page := range pdfg.pages {
	if page.Reader() != nil {
		cmd.Stdin = page.Reader()
		break
	}
}

Do you have any suggestion as how I should modify my code or there might be potential issue in the current code? Thanks a lot and I'm looking forward to your reply!

wkhtmltoimage

I need to convert a html to image. And i notice that the office website of wkhtmltopdf have offered a tool named wkhtmltoimage.. this porject go-wkhtmltopdf seem only support wkhtmltopdf.. Do you have any plans to support wkhtmltoimage?

multiple copies of the pdf are downloading after so many clicks

Greetings,
I have 2 situations.(see also #39 ) ( using node.js )
Here is the first
1: After a few pdfs generated, one at a time, I get multiple copies of the same pdf on subsequent clicks.
I am using sockets for transmission.
Here is some code:

      var wkpdf 				= require('wkhtmltopdf');
      var pdf = wkpdf(data.html, params, function (err, stream){
	    console.log(stream);
	   // you can use message here and only in here

		if(err){
			console.log('ERROR IN WKPDF: ',err);
		} else {
			console.log('STREAM ERROR:',err, stream);
			toArray(stream, function (err, arr) {
				console.log('OUTPUT OF TO ARRAY',err,arr);
				var datas = {};
				datas.buffer = Buffer.concat(arr);
				datas.user = data.user;
				datas.filename = data.filename;
				socket.emit(data.returnEntry, datas);
			});
		}
	});

Thanks for any help I can get and let me know if I need to submit more code.

Unable to generate more than one page while reading different htmls

I am trying to generate a pdf with one page from one html and the second page from another html. But the second page never gets printed. Its comes blank. When I try and create 2 different pdfs then they are created perfectly. Just not in a single one. Can you please share code for such a scenario?

Could not render html in pdf

suppose my instruction is <p>Hi,</p><p><br></p><p><br></p><p><br></p><p><br></p><p><br></p><p><em>My</em> <u>name</u> is <strong>Bijo</strong>.</p>

I want is to get parsed into HTMl and then get printed on pdf

but the output is
Screenshot from 2020-07-17 18-19-54

Please help me out.

Go test fails in MacOs X(High Sierra[10.13.6]:darwin/amd64)

The basic example shown in the readme is failing in MacOs X. So I ran the go test within the project directory. Output of go test:

	json_test.go:31: Want 14090 JSON bytes, have 14096
	json_test.go:36: Want JSON:
		{"GlobalOptions":{"CookieJar":{"Option":"cookie-jar","Value":""},"Copies":{"Option":"copies","IsSet":false,"Value":0},"Dpi":{"Option":"dpi","IsSet":true,"Value":600},"ExtendedHelp":{"Option":"extended-help","Value":false},"Grayscale":{"Option":"grayscale","Value":false},"Help":{"Option":"true","Value":false},"HTMLDoc":{"Option":"htmldoc","Value":false},"ImageDpi":{"Option":"image-dpi","IsSet":false,"Value":0},"ImageQuality":{"Option":"image-quality","IsSet":false,"Value":0},"License":{"Option":"license","Value":false},"Lowquality":{"Option":"lowquality","Value":false},"ManPage":{"Option":"manpage","Value":false},"MarginBottom":{"Option":"margin-bottom","IsSet":true,"Value":40},"MarginLeft":{"Option":"margin-left","IsSet":true,"Value":0},"MarginRight":{"Option":"margin-right","IsSet":false,"Value":0},"MarginTop":{"Option":"margin-top","IsSet":false,"Value":0},"Orientation":{"Option":"orientation","Value":""},"NoCollate":{"Option":"nocollate","Value":false},"PageHeight":{"Option":"page-height","IsSet":false,"Value":0},"PageSize":{"Option":"page-size","Value":"A4"},"PageWidth":{"Option":"page-width","IsSet":false,"Value":0},"NoPdfCompression":{"Option":"no-pdf-compression","Value":false},"Quiet":{"Option":"quiet","Value":false},"ReadArgsFromStdin":{"Option":"read-args-from-stdin","Value":false},"Readme":{"Option":"readme","Value":false},"Title":{"Option":"title","Value":""},"Version":{"Option":"version","Value":false}},"OutlineOptions":{"DumpDefaultTocXsl":{"Option":"dump-default-toc-xsl","Value":false},"DumpOutline":{"Option":"dump-outline","Value":""},"NoOutline":{"Option":"no-outline","Value":false},"OutlineDepth":{"Option":"outline-depth","IsSet":false,"Value":0}},"Cover":{"Input":"https://wkhtmltopdf.org/index.html","Allow":{"Option":"allow","Value":null},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":null},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":""},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":false},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":""},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":true,"Value":0.75}},"TOC":{"Include":true,"Allow":{"Option":"allow","Value":null},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":null},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":""},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":false},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":""},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":false,"Value":0},"DisableDottedLines":{"Option":"disable-dotted-lines","Value":true},"TocHeaderText":{"Option":"toc-header-text","Value":""},"TocLevelIndentation":{"Option":"toc-level-indentation","IsSet":false,"Value":0},"DisableTocLinks":{"Option":"disable-toc-links","Value":false},"TocTextSizeShrink":{"Option":"toc-text-size-shrink","IsSet":false,"Value":0},"XslStyleSheet":{"Option":"xsl-style-sheet","Value":""}},"Pages":[{"PageOptions":{"Allow":{"Option":"allow","Value":["/usr/local/html","/usr/local/images"]},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":{"X-AppKey":"abcdef"}},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":"ignore"},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":true},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":"3840x2160"},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":false,"Value":0},"FooterCenter":{"Option":"footer-center","Value":""},"FooterFontName":{"Option":"footer-font-name","Value":""},"FooterFontSize":{"Option":"footer-font-size","IsSet":false,"Value":0},"FooterHTML":{"Option":"footer-html","Value":""},"FooterLeft":{"Option":"footer-left","Value":""},"FooterLine":{"Option":"footer-line","Value":false},"FooterRight":{"Option":"footer-right","Value":""},"FooterSpacing":{"Option":"footer-spacing","IsSet":false,"Value":0},"HeaderCenter":{"Option":"header-center","Value":""},"HeaderFontName":{"Option":"header-font-name","Value":""},"HeaderFontSize":{"Option":"header-font-size","IsSet":false,"Value":0},"HeaderHTML":{"Option":"header-html","Value":""},"HeaderLeft":{"Option":"header-left","Value":""},"HeaderLine":{"Option":"header-line","Value":false},"HeaderRight":{"Option":"header-right","Value":""},"HeaderSpacing":{"Option":"header-spacing","IsSet":true,"Value":10.01},"Replace":{"Option":"replace","Value":null}},"InputFile":"https://www.google.com","Base64PageData":""},{"PageOptions":{"Allow":{"Option":"allow","Value":null},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":null},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":""},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":false},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":""},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":false,"Value":0},"FooterCenter":{"Option":"footer-center","Value":""},"FooterFontName":{"Option":"footer-font-name","Value":""},"FooterFontSize":{"Option":"footer-font-size","IsSet":false,"Value":0},"FooterHTML":{"Option":"footer-html","Value":""},"FooterLeft":{"Option":"footer-left","Value":""},"FooterLine":{"Option":"footer-line","Value":false},"FooterRight":{"Option":"footer-right","Value":""},"FooterSpacing":{"Option":"footer-spacing","IsSet":false,"Value":0},"HeaderCenter":{"Option":"header-center","Value":""},"HeaderFontName":{"Option":"header-font-name","Value":""},"HeaderFontSize":{"Option":"header-font-size","IsSet":false,"Value":0},"HeaderHTML":{"Option":"header-html","Value":""},"HeaderLeft":{"Option":"header-left","Value":""},"HeaderLine":{"Option":"header-line","Value":false},"HeaderRight":{"Option":"header-right","Value":""},"HeaderSpacing":{"Option":"header-spacing","IsSet":false,"Value":0},"Replace":{"Option":"replace","Value":null}},"InputFile":"-","Base64PageData":"PCFkb2N0eXBlIGh0bWw+PGh0bWw+PGhlYWQ+PHRpdGxlPldLSFRNTFRPUERGIFRFU1Q8L3RpdGxlPjwvaGVhZD48Ym9keT5IRUxMTyBQREY8L2JvZHk+PC9odG1sPg=="}]}
		Have:
		{"GlobalOptions":{"CookieJar":{"Option":"cookie-jar","Value":""},"Copies":{"Option":"copies","IsSet":false,"Value":0},"Dpi":{"Option":"dpi","IsSet":true,"Value":600},"ExtendedHelp":{"Option":"extended-help","Value":false},"Grayscale":{"Option":"grayscale","Value":false},"Help":{"Option":"true","Value":false},"HTMLDoc":{"Option":"htmldoc","Value":false},"ImageDpi":{"Option":"image-dpi","IsSet":false,"Value":0},"ImageQuality":{"Option":"image-quality","IsSet":false,"Value":0},"License":{"Option":"license","Value":false},"Lowquality":{"Option":"lowquality","Value":false},"ManPage":{"Option":"manpage","Value":false},"MarginBottom":{"Option":"margin-bottom","IsSet":true,"Value":40},"MarginLeft":{"Option":"margin-left","IsSet":true,"Value":0},"MarginRight":{"Option":"margin-right","IsSet":false,"Value":0},"MarginTop":{"Option":"margin-top","IsSet":false,"Value":0},"Orientation":{"Option":"orientation","Value":""},"NoCollate":{"Option":"nocollate","Value":false},"PageHeight":{"Option":"page-height","IsSet":false,"Value":0},"PageSize":{"Option":"page-size","Value":"A4"},"PageWidth":{"Option":"page-width","IsSet":false,"Value":0},"NoPdfCompression":{"Option":"no-pdf-compression","Value":false},"Quiet":{"Option":"quiet","Value":false},"ReadArgsFromStdin":{"Option":"read-args-from-stdin","Value":false},"Readme":{"Option":"readme","Value":false},"Title":{"Option":"title","Value":""},"Version":{"Option":"version","Value":false}},"OutlineOptions":{"DumpDefaultTocXsl":{"Option":"dump-default-toc-xsl","Value":false},"DumpOutline":{"Option":"dump-outline","Value":""},"NoOutline":{"Option":"no-outline","Value":false},"OutlineDepth":{"Option":"outline-depth","IsSet":false,"Value":0}},"Cover":{"Input":"https://wkhtmltopdf.org/index.html","Allow":{"Option":"allow","Value":null},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":null},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":""},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":false},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":""},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":true,"Value":0.75}},"TOC":{"Include":true,"Allow":{"Option":"allow","Value":null},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":null},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":""},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":false},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":""},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":false,"Value":0},"DisableDottedLines":{"Option":"disable-dotted-lines","Value":true},"TocHeaderText":{"Option":"toc-header-text","Value":""},"TocLevelIndentation":{"Option":"toc-level-indentation","IsSet":false,"Value":0},"DisableTocLinks":{"Option":"disable-toc-links","Value":false},"TocTextSizeShrink":{"Option":"toc-text-size-shrink","IsSet":false,"Value":0},"XslStyleSheet":{"Option":"xsl-style-sheet","Value":""}},"Pages":[{"PageOptions":{"Allow":{"Option":"allow","Value":["/usr/local/html","/usr/local/images"]},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":{"X-AppKey":"abcdef"}},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":""},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":true},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":"3840x2160"},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":false,"Value":0},"FooterCenter":{"Option":"footer-center","Value":""},"FooterFontName":{"Option":"footer-font-name","Value":""},"FooterFontSize":{"Option":"footer-font-size","IsSet":false,"Value":0},"FooterHTML":{"Option":"footer-html","Value":""},"FooterLeft":{"Option":"footer-left","Value":""},"FooterLine":{"Option":"footer-line","Value":false},"FooterRight":{"Option":"footer-right","Value":""},"FooterSpacing":{"Option":"footer-spacing","IsSet":false,"Value":0},"HeaderCenter":{"Option":"header-center","Value":""},"HeaderFontName":{"Option":"header-font-name","Value":""},"HeaderFontSize":{"Option":"header-font-size","IsSet":false,"Value":0},"HeaderHTML":{"Option":"header-html","Value":""},"HeaderLeft":{"Option":"header-left","Value":""},"HeaderLine":{"Option":"header-line","Value":false},"HeaderRight":{"Option":"header-right","Value":""},"HeaderSpacing":{"Option":"header-spacing","IsSet":true,"Value":10.01},"Replace":{"Option":"replace","Value":null}},"InputFile":"https://www.google.com","Base64PageData":""},{"PageOptions":{"Allow":{"Option":"allow","Value":null},"NoBackground":{"Option":"no-background","Value":false},"CacheDir":{"Option":"cache-dir","Value":""},"CheckboxCheckedSvg":{"Option":"checkbox-checked-svg","Value":""},"CheckboxSvg":{"Option":"checkbox-svg","Value":""},"Cookie":{"Option":"cookie","Value":null},"CustomHeader":{"Option":"custom-header","Value":null},"CustomHeaderPropagation":{"Option":"custom-header-propagation","Value":false},"NoCustomHeaderPropagation":{"Option":"no-custom-header-propagation","Value":false},"DebugJavascript":{"Option":"debug-javascript","Value":false},"DefaultHeader":{"Option":"default-header","Value":false},"Encoding":{"Option":"encoding","Value":""},"DisableExternalLinks":{"Option":"disable-external-links","Value":false},"EnableForms":{"Option":"enable-forms","Value":false},"NoImages":{"Option":"no-images","Value":false},"DisableInternalLinks":{"Option":"disable-internal-links","Value":false},"DisableJavascript":{"Option":"disable-javascript","Value":false},"JavascriptDelay":{"Option":"javascript-delay","IsSet":false,"Value":0},"LoadErrorHandling":{"Option":"load-error-handling","Value":""},"LoadMediaErrorHandling":{"Option":"load-media-error-handling","Value":""},"DisableLocalFileAccess":{"Option":"disable-local-file-access","Value":false},"MinimumFontSize":{"Option":"minimum-font-size","IsSet":false,"Value":0},"ExcludeFromOutline":{"Option":"exclude-from-outline","Value":false},"PageOffset":{"Option":"page-offset","IsSet":false,"Value":0},"Password":{"Option":"password","Value":""},"EnablePlugins":{"Option":"enable-plugins","Value":false},"Post":{"Option":"post","Value":null},"PostFile":{"Option":"post-file","Value":null},"PrintMediaType":{"Option":"print-media-type","Value":false},"Proxy":{"Option":"proxy","Value":""},"RadiobuttonCheckedSvg":{"Option":"radiobutton-checked-svg","Value":""},"RadiobuttonSvg":{"Option":"radiobutton-svg","Value":""},"RunScript":{"Option":"run-script","Value":null},"DisableSmartShrinking":{"Option":"disable-smart-shrinking","Value":false},"NoStopSlowScripts":{"Option":"no-stop-slow-scripts","Value":false},"EnableTocBackLinks":{"Option":"enable-toc-back-links","Value":false},"UserStyleSheet":{"Option":"user-style-sheet","Value":""},"Username":{"Option":"username","Value":""},"ViewportSize":{"Option":"viewport-size","Value":""},"WindowStatus":{"Option":"window-status","Value":""},"Zoom":{"Option":"zoom","IsSet":false,"Value":0},"FooterCenter":{"Option":"footer-center","Value":""},"FooterFontName":{"Option":"footer-font-name","Value":""},"FooterFontSize":{"Option":"footer-font-size","IsSet":false,"Value":0},"FooterHTML":{"Option":"footer-html","Value":""},"FooterLeft":{"Option":"footer-left","Value":""},"FooterLine":{"Option":"footer-line","Value":false},"FooterRight":{"Option":"footer-right","Value":""},"FooterSpacing":{"Option":"footer-spacing","IsSet":false,"Value":0},"HeaderCenter":{"Option":"header-center","Value":""},"HeaderFontName":{"Option":"header-font-name","Value":""},"HeaderFontSize":{"Option":"header-font-size","IsSet":false,"Value":0},"HeaderHTML":{"Option":"header-html","Value":""},"HeaderLeft":{"Option":"header-left","Value":""},"HeaderLine":{"Option":"header-line","Value":false},"HeaderRight":{"Option":"header-right","Value":""},"HeaderSpacing":{"Option":"header-spacing","IsSet":false,"Value":0},"Replace":{"Option":"replace","Value":null}},"InputFile":"-","Base64PageData":"PCFkb2N0eXBlIGh0bWw+PGh0bWw+PGhlYWQ+PHRpdGxlPldLSFRNTFRPUERGIFRFU1Q8L3RpdGxlPjwvaGVhZD48Ym9keT5IRUxMTyBQREY8L2JvZHk+PC9odG1sPg=="}]}
--- FAIL: TestNewPDFGeneratorFromJSON (6.64s)
	json_test.go:54: Want argstring:
		--dpi 600 --margin-bottom 40 --margin-left 0 --page-size A4 cover https://wkhtmltopdf.org/index.html --zoom 0.750 toc --disable-dotted-lines page https://www.google.com --allow /usr/local/html --allow /usr/local/images --custom-header X-AppKey abcdef --disable-smart-shrinking --viewport-size 3840x2160 --header-spacing 10.010 -
		Have:
		--dpi 600 --margin-bottom 40 --margin-left 0 --page-size A4 cover https://wkhtmltopdf.org/index.html --zoom 0.750 toc --disable-dotted-lines page https://www.google.com --allow /usr/local/html --allow /usr/local/images --custom-header X-AppKey abcdef --load-error-handling ignore --disable-smart-shrinking --viewport-size 3840x2160 --header-spacing 10.010 -
--- FAIL: TestArgString (0.00s)
	wkhtmltopdf_test.go:58: Want argstring:
		--dpi 600 --margin-bottom 40 --margin-left 0 --page-size A4 cover https://wkhtmltopdf.org/index.html --zoom 0.750 toc --disable-dotted-lines page https://www.google.com --allow /usr/local/html --allow /usr/local/images --custom-header X-AppKey abcdef --disable-smart-shrinking --viewport-size 3840x2160 --header-spacing 10.010 -
		Have:
		--dpi 600 --margin-bottom 40 --margin-left 0 --page-size A4 cover https://wkhtmltopdf.org/index.html --zoom 0.750 toc --disable-dotted-lines page https://www.google.com --allow /usr/local/html --allow /usr/local/images --custom-header X-AppKey abcdef --load-error-handling ignore --disable-smart-shrinking --viewport-size 3840x2160 --header-spacing 10.010 -
	wkhtmltopdf_test.go:62: Want argstring:
		--dpi 600 --margin-bottom 40 --margin-left 0 --page-size A4 cover https://wkhtmltopdf.org/index.html --zoom 0.750 toc --disable-dotted-lines page https://www.google.com --allow /usr/local/html --allow /usr/local/images --custom-header X-AppKey abcdef --disable-smart-shrinking --viewport-size 3840x2160 --header-spacing 10.010 -
		Have:
		--dpi 600 --margin-bottom 40 --margin-left 0 --page-size A4 cover https://wkhtmltopdf.org/index.html --zoom 0.750 toc --disable-dotted-lines page https://www.google.com --allow /usr/local/html --allow /usr/local/images --custom-header X-AppKey abcdef --load-error-handling ignore --disable-smart-shrinking --viewport-size 3840x2160 --header-spacing 10.010 -
FAIL
exit status 1
FAIL	github.com/SebastiaanKlippert/go-wkhtmltopdf	32.221s

And the generated pdf looks like this:
simplesample.pdf

wkhtmltopdf version :
wkhtmltopdf 0.12.5 (with patched qt)

go version: go1.9.2 darwin/amd64

TOC

As I read the newTestPDFGenerator function it adds TOC to the pdfs generated by it, but I don't see it in any of the pdf's created by running the tests? Am I missing something or is something broken with regards to TOC?

CSS document not found

Hi Sebastiaan,

I noticed you define many class in the sample html5 file but did not find any css file. I am wondering how the html can be styled to fit printing format.

Best
Kun

Image not showing

go-wkhtmltopdf version 1.6.1

OS information
macOS Mojave Version 10.14.6

Description
I want to create simple biodata with HTML file. I try to add floating image (profile picture) at right corner, but the image is not showing

How to reproduce
This is my sample test.html file

<!DOCTYPE html>
<html>
<body style="padding: 50px; text-align: justify;">
    <h1 style="text-align: center;">Biodata</h1>
    <br>
    <div style="float: right; margin-bottom: 30px;">
      <img src="../image/profile_pic.jpeg" height="150px">
    </div>
    <div>
    <strong>Name:</strong> John
    </div>
    <br>
    <strong>Birth date:</strong> 2001-01-01
    <br>
    <br>
    <strong>Birth place:</strong> Unknown
    <br>
    <br>
    <Strong>Sex:</Strong> Male/Female
    <br>
    <br>
    <strong>Height:</strong> 200 cm
    <br>
    <br>
    <strong>Hobby:</strong> Sleeping
    <br>
</body>
</html>

This is the Go code

import (
	"bytes"
	"fmt"
	"html/template"
	"strings"

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

func init() {
	htmlTmp, err := template.ParseFiles("files/html/test.html")
	if err != nil {
		fmt.Println(err)
		return
	}

	buf := new(bytes.Buffer)
	err = htmlTmp.Execute(buf, nil)
	if err != nil {
		fmt.Println(err)
		return
	}

	pdfGen, err := gopdf.NewPDFGenerator()
	if err != nil {
		fmt.Println(err)
		return
	}

	pageReader := gopdf.NewPageReader(strings.NewReader(buf.String()))
	pageReader.PageOptions.EnableLocalFileAccess.Set(true)
	pdfGen.AddPage(pageReader)
	if err := pdfGen.Create(); err != nil {
		fmt.Println(err)
		return
	}

	if err := pdfGen.WriteFile("files/generated/test.pdf"); err != nil {
		fmt.Println(err)
		return
	}
}

This is what it looks like when I run the code
test8.pdf

I already use the option to enable local file access, but the image is still not showing. Instead, there is a block at where the image should be showing

Expected behavior
I try to use wkhtmltopdf from command line to see the differences

wkhtmltopdf --enable-local-file-access files/html/test.html files/generated/test.pdf

This is the result
test7.pdf

It shows the image where I want them to be

set footer doesn't work

        // ...
	page := wkhtmltopdf.NewPageReader(strings.NewReader(tpl.String()))
	page.FooterRight.Set("[page]")
	page.FooterFontSize.Set(10)
	pdf.AddPage(page)
	
	errors := pdf.Create()
        // ...

Can't figure out what I'm missing to add footer in my page. Any clue ? The only page generated is OK but there is no footer at all

Add multiple pages make blank pages

Hi, I try with your library add pages in loop, but still I get only first page and other are blank only footer are there and what I check in debugger pages are correctly added to pages slice in library but generate wrong output, could you help me ?

my code:

// loop
for _, pageData := range *dataForPages {
patient := Patient{}.NewV0(*pageData, 39)
buf := parseAndGetHtml(patient, brand) // return bytes.Buffer which return correct bytes
page := setupAndGetPage(&buf)
pdfg.AddPage(page)
}
// prepare page 
func setupAndGetPage(buf *bytes.Buffer) (*wkhtmltopdf.PageReader) {
	page := wkhtmltopdf.NewPageReader(bytes.NewReader(buf.Bytes()))
	page.FooterFontName.Set("helvetica")
	page.FooterFontSize.Set(8)
	page.HeaderFontName.Set("helvetica")
	page.HeaderFontSize.Set(10)
	page.FooterRight.Set("[page]/[topage]")
	page.Zoom.Set(1.25)
	page.PrintMediaType.Set(true)

	return page
}

// make template
func parseAndGetHtml(patient *Patient, brand string) (bytes.Buffer) {
	tpl := template.Must(template.ParseGlob(fmt.Sprintf("pdfTemplates/%s/*.gohtml", brand)))

	buf := bytes.Buffer{}
	err := tpl.ExecuteTemplate(&buf, "index.gohtml", patient)
	if err != nil {
		log.Fatal(err)
	}

	return buf
}

Get output information

Calling wkhtmltopdf at a terminal gives output like the following,

Loading pages (1/6) Counting pages (2/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done

Is there a way to get this out of the go package?

Mocking wkhtmltopdf

Hi,

I would like to mock wkhtmltopdf for unit tests, and for that I need to mock the following functions:

AddPage(p pdf.page) error
Create() error
WriteFile(filename string) error

As you can see, page is not exported, meaning I simply can't create a mock structure. It is also a problem with documentation.

Right now the only solution I am finding would be to have another level of abstraction with PageReader. Or did I miss something?

why not use $GOPATH/pkg or $GOPATH/bin

As for looking up the binary executable path:

go-wkhtmltopdf finds the path to wkhtmltopdf by

first looking in the current dir
looking in the PATH and PATHEXT environment dirs
using the WKHTMLTOPDF_PATH environment dir

why not also look in $GOPATH/bin , $GOROOT/bin ?

when this lib is included as a dependency using go modules, can it automatically install itself as a binary?

Update docs to show how to retrieve internal buffer

I don't want to write the PDF to a file - instead I need to attach the PDF to an email. In the docs, it shows:

       // Create PDF document in internal buffer
	err = pdfg.Create()
	if err != nil {
		log.Fatal(err)
	}


	err = pdfg.WriteFile(pdfFile)  // unnecessary WriteFile method
	if err != nil {
		return err
	}

look, people know how to write files, given buffers etc. We don't need helper methods for that. Can you update your docs to show how to retrieve the internal buffer? Thanks for accepting criticism.

wkhtmltopdf seems to limit the size of the input when using Socket.io

Here is my second issue: ( using node.js )
I have a pdf data of size 178578 or >
I am console.logging params and once it does that the script dies silently.
other, smaller data outputs the pdf just fine, if not too many copies sometimes (see issue #38 )

        var wkpdf 				= require('wkhtmltopdf');

	socket.on('make-pdf',function(data){
		console.log('DATA 2',data.html.length);//DATA 2 178578

		var params = {
			pageSize: 'letter' ,
			footerRight: data.footerRight || 'Page [page] of [toPage]',
			footerLine: data.footerLine || true,
			headerSpacing: data.headerSpacing || 2,
			marginTop: data.marginTop || '3cm',
			marginBottom: data.marginBottom || '1cm',
			marginLeft: data.marginLeft || '1.25cm',
			marginRight: data.marginRight || '1.25cm',
			headerLine: data.headerLine || true,
			outline: data.outline || true,
			outlineDepth: data.outlineDepth || 4,
			javascriptDelay: 500,
			username: data.user,
			enableForms: data.enableForms || true,
			orientation: data.orientation || 'Portait',
		}
		console.log('params', params);

		var pdf = wkpdf(data.html, params, function (err, stream){
		    console.log(stream);//never gets here with this Data length
			if(err){
				console.log('ERROR IN WKPDF: ',err);
			} else {
				console.log('STREAM ERROR:',err, stream);
				toArray(stream, function (err, arr) {
					console.log('OUTPUT OF TO ARRAY',err,arr);
					var datas = {};
					datas.buffer = Buffer.concat(arr);
					datas.user = data.user;
					datas.filename = data.filename;
					socket.emit(data.returnEntry, datas);
				});
			}
		});
	});

The index.js file is expecting an exit here:

  child.on('exit', function(code) {
	  console.log('CODE:', code);// large input not making it here
    if (code !== 0) {
      stderrMessages.push('wkhtmltopdf exited with code ' + code);
      handleError(stderrMessages);
    } else if (callback) {
		console.log('test');
      callback(null, stream); // stream is child.stdout
    }
  });

EDIT: is there somewhere I need to call 'exit' from within the call to wkpdf in order for large files to work?

EDIT 2: just discovered debug:

[node-wkhtmltopdf] [debug] ] Page 35 of 75
[node-wkhtmltopdf] [debug] [============================>
[node-wkhtmltopdf] [debug] ] Page 36 of 75
it's dying right here.

Can someone possibly help on this, too? Thanks!

Tests didn't work on linux

wkhtmltopdf not found in every test

/usr/local/go/bin/go tool test2json -t /tmp/___ExampleNewPDFGenerator_in_github_com_SebastiaanKlippert_go_wkhtmltopdf -test.v -test.run ^ExampleNewPDFGenerator$ #gosetup
=== RUN   ExampleNewPDFGenerator
2018/10/09 10:33:38 wkhtmltopdf not found

Process finished with exit code 1

GAE problem

What do I do if I use Google App Engine?
The binary file wkthmltopdf is too big to upload. They have a maximum of 32MB, but the binary files is almost 40MB.

Regarding ViewportSize

When using wkhtmltopdf directly I can set the --viewport-size like so:

./wkhtmltopdf --viewport-size 1920x1080 -L 0 -R 0 -T 0 -B 0 http://www.google.com sample.pdf

I can use the format 1920x1080, but not with go-wkhtmltopdf, because it expect uint, I was able to achieve the required result for now by using

page.ViewportSize.Set(1920)

but I think this will come up in the future and it needs to be fixed.

Thanks @SebastiaanKlippert, you package has proven to be quit useful, we are using it now in IDMC http://www.internal-displacement.org, you can list us if you would like to.

Setting footer parameters

Hi,
thank you for this wrapper. :)
On the CLI, I use these parameters:

--footer-right [page]  --footer-font-size 9

How could I set them with go-wkhtmltopdf?

Network Error: ContentNotFoundError

I was trying to generate a PDF file from the HTML. However, when I tried to compile code, it exit with the following error:

2020/02/18 12:50:13 libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Loading page (1/2)
Warning: Failed to load file:///tmp/styles.css (ignore)
Printing pages (2/2)
Done
Exit with code 1 due to network error: ContentNotFoundError
exit status 1

I have included my CSS file in the header in the same directory where the HTML file is.

The code stops at Create() function of PDFGenerator structure.
Have anyone faced this issue? How can I specify my stylesheet?

How can I add header and footer in every page

I have used header-html and footer-html tag but facing a issue
Screenshot from 2020-07-06 15-32-30 Whole header and hooter is not coming. only some part of from below is only getting printed.
page := wkhtmltopdf.NewPageReader(bytes.NewReader(htmlCode))
page.DisableExternalLinks.Set(false)
page.FooterFontSize.Set(7)
page.FooterRight.Set("[page]")
page.HeaderHTML.Set("/usr/local/bin/header.html")
page.FooterHTML.Set("/usr/local/bin/footer.html")
This is the code I am using.

Intermittent blank output

wkhtmltopdf version(s) affected: 0.12.5

OS information
Both Mac OSX and Alpine Docker.

Description
I have a large (ish), html template and some Javascript. But I can also recreate this problem using plain-text. The problem I'm seeing is, on the first attempt at converting a html string into a PDF, it works as expected. However, on the second or third time, instead of generating my 9 page PDF. It generates 3 or 4 completely blank pages.

When I output the html in the above scenario, it's correct. It seems to be during the PDF generation process. I first observed this when running in an Alpine Linux container, however I am now seeing this on my laptop also.

How to reproduce

  1. Set-up a go file using go-wkhtmltopdf.
  2. Use the function below:
func generatePDF(pdfg *pdf.PDFGenerator, html []byte) ([]byte, error) {
	pdfg.PageSize.Set(pdf.PageSizeA4)
	pdfg.MarginTop.Set(0)
	pdfg.MarginLeft.Set(0)
	pdfg.MarginRight.Set(0)
	pdfg.Dpi.Set(300)
	page := pdf.NewPageReader(bytes.NewReader(html))
	page.JavascriptDelay.Set(500)
	pdfg.AddPage(page)
	if err := pdfg.Create(); err != nil {
		return nil, err
	}
	return pdfg.Bytes(), nil
}

Use the following Docker image to replicate the exact environment:

# build stage
FROM golang:alpine AS build-env

RUN apk add --no-cache gcc git cmake musl-dev
RUN mkdir -p /usr/go/src/github.com/EwanValentine/report-service
RUN go get -u golang.org/x/vgo

WORKDIR /usr/go/src/github.com/EwanValentine/report-service

ADD . .
ADD templates templates

RUN vgo install && vgo build -o svc

# final stage
FROM surnet/alpine-wkhtmltopdf:3.7-0.12.5-full

COPY --from=build-env /usr/go/src/github.com/EwanValentine/report-service/ /app/

WORKDIR /app

ENTRYPOINT ./svc

I can re-produce this using just plain-text, and without any html.

Expected behavior

I'd expect content to render into the document.

question : Insert png ?

I red documentation and I'm unable to find how to insert a png into my pdf. Basically I create a barcode and I save it as png file under a path like public/barcode/765456789.png.
For now I tried something like <img src="/public/barcode/765456789.png" alt="myImage"> .
@SebastiaanKlippert: is there a way to add an image in a more concise and efficient way ?

Warning: Blocked access to file

I'm trying to generate a PDF using .Create() , and the default options using NewPDFGenerator() , and running into this below issue:

Warning: Blocked access to file <omitted directory>/pdf.css
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol \"about\" is unknown\n[============================================>               
]

The same codeblock works on a different machine. Am I missing any options? I checked the generator's Cover.pageOptions which has DisableLocalFileAccess set to false.

"wkhtmltopdf not found" error

The error only happens in linux environment, where as it has no problems running on the latest mac os (mojave). Snippet below:

`package main

import (
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
"log"
)

func main() {
page := wkhtmltopdf.NewPage("https://godoc.org/github.com/SebastiaanKlippert/go-wkhtmltopdf")
pdfg, err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
log.Fatal("error:",err.Error())
}

pdfg.AddPage(page)
if err = pdfg.Create(); err != nil {
log.Fatal("say what? ",err)
}

if err = pdfg.WriteFile("test.pdf"); err != nil {
log.Fatal(err.Error())
}
fmt.Println("Done")
}`

Linux go env:
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"

Macos go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"

css file not rendering While converting html to pdf

HI @SebastiaanKlippert

My current Work

--> it is working fine

var StudenthtmlStr string = "<html>  <head>
        <style>
        h1 {color:red;}
        p {color:blue;}
        </style>
        </head>
       <body background="{{image1}}">
       <h1>This is an html from pdf to test color<h1>
        </html>"

My expectation

Instead of writing the css in the variable i have to link my external *.css file

var StudenthtmlStr string = "<html>  <head>
        <style>
  <link rel "stylesheeet" href="mycssfile.css">  //Not working in our Plugin      
    </style>
        </head>
       <body background="{{image1}}">
       <h1>This is an html from pdf to test color<h1>
        </html>"

go install does not install binary in expected location :(

I run this:

$ cd $GOPATH/src/github.com/SebastiaanKlippert/go-wkhtmltopdf 
$ go install

but no new binary is created in $GOPATH/bin

so what's the deal here?
also go get github.com/SebastiaanKlippert/go-wkhtmltopdf does not create the binary either :(

Question: How to load a local svg file.

I want to load the local svg and output it as pdf.
But I failed it.
I want to tell me how

<img src="/public/images/sample.svg>
result ↓↓↓
Exit with code 1 due to network error: ContentNotFoundError

Generate pdf from html using header, body and footer provided in string.

We are given with header, body and footer in string variables. Using this, we have to generate pdf in which header and footer remains constant but body dynamically varies according to the data.
Currently, this feature is not available.

Example:
header:= "Header"
body:= "Body"
footer:= "Footer"

fund generatePDF(header, body, footer string){}

Sending the PDF to a real printer

Curious if you got the chain so that that after the pdf is generated you could also bring up the system print dialog to print the file ?

Header giving extra space

There is a extra space in the header. I tried setting top margin. for example if I set top margin as 50 then header can appear in only 50 mm space. If header is more than 50 then It is not getting displayed. And when I don't give margin then we can put our header of as much length we need but It gives extra space above it. How can I reduce that space.
Screenshot from 2020-07-08 20-39-30
And after adding Footer the page number is getting overlapped. How can we solve this.
Please help me out

Footer Page number getting overlapped incase of Footer Html being added

//page.FooterCenter.Set("[page]")
//page.FooterHTML.Set("file:///home/tolexo/Desktop/footer.html")
The following code overlaps the footer page number with html footer, I want to show the page numbers as well along with the html footer:

    var pdfg *wkhtmltopdf.PDFGenerator
wkhtmltopdf.SetPath("/usr/local/bin/wkhtmltopdf")
page := wkhtmltopdf.NewPageReader(bytes.NewReader(htmlCode))
page.FooterHTML.Set("file://footer.html")
page.FooterCenter.Set("[page]")

if pdfg, err = wkhtmltopdf.NewPDFGenerator(); err != nil {
	return
}
pdfg.AddPage(page)
pdfg.Dpi.Set(80)

if err = pdfg.Create(); err != nil {
	fmt.Println("Did I reach here 2")
	return
}
err = pdfg.WriteFile(fileDestination + "abcd.pdf")
return

}

image

image

wkhtmltopdf path is missing

I have installed wkhtmltopdf successfully.
if I run

$which wkhtmltopdf // /usr/local/bin/wkhtmltopdf

And I have also set $WKHTMLTOPDF_PATH variable

Here is my simple code which tries to create pdf. It shows me error fork/exec : no such file or directory

const html = `<!doctype html><html><head><title>Hello world!!</title></head><body>Life is awesome</body></html>`
	// Client code
	pdf.SetPath("/usr/local/bin/wkhtmltopdf")
	pdfg := pdf.NewPDFPreparer()
	fmt.Println("PATH IS:", pdf.GetPath())
	// PATH IS: /usr/local/bin/wkhtmltopdf
	pdfg.AddPage(pdf.NewPageReader(strings.NewReader(html)))
	pdfg.Dpi.Set(600)

	err := pdfg.Create()
	if err != nil {
		log.Fatal(err)
	}

the css attr style="page-break-after:always" did not work when i convert html to pdf

<div style="page-break-after:always">first page</div>
<div style="page-break-after:always">sec page</div>
<div style="page-break-after:always">th page</div>

the html file like this , i drag this file to google chrome,then right click,choose print,all is well and good,but i use wkhtmltopdf to generate pdf ,it did not work properly

Segmentation fault

I get a signal: segmentation fault when running on elasticbeanstalk go.

Go 1 running on 64bit   Amazon Linux/2.14.2

When I run the same command using directly the wkhtmltopdf command, everything works ... This is happening with 0.12.5 and 0.12.4.

This is happening on a single url only (see the example below).

And when I run this example on my machine (archlinux) it's working perfectly ...

package main

import (
        "fmt"
        . "github.com/SebastiaanKlippert/go-wkhtmltopdf"
        "log"
        "os"
)


func main() {

        // Create new PDF generator
        pdfg, err := NewPDFGenerator()
        if err != nil {
                log.Fatal(err)
        }

        // Set global options
        pdfg.Dpi.Set(300)
        pdfg.Grayscale.Set(true)

        // Create a new input page from an URL
        page := NewPage("https://app.teetsh.com/print/annee-scolaire/637c0b0b-669e-45c2-bb69-af1f74a6ecd3/ecole/ef9667c6-c70e-4d7b-a337-301b97de67b5/cahier-journal/day/2020/02/20?font=roboto\u0026tz=Pacific/Guadalcanal\u0026size=11\u0026br
eakinsideavoid=false\u0026displaylength=true\u0026displaytags=true\u0026displaymaterialssum=true\u0026displaybilan=false")

        // Set options for this page
        page.FooterRight.Set("[page]")

        pdfg.SetStderr(os.Stdout)

        page.FooterFontSize.Set(10)
        page.NoStopSlowScripts.Set(true)
        page.WindowStatus.Set("wkhtmltopdf.ready")
        page.Zoom.Set(0.95)

        // Add to document
        pdfg.AddPage(page)

        // Create PDF document in internal buffer
        err = pdfg.Create()
        if err != nil {
                log.Fatal(err)
        }

        // Write buffer contents to file on disk
        err = pdfg.WriteFile("./simplesample.pdf")
        if err != nil {
                log.Fatal(err)
        }

        fmt.Println("Done")
        // Output: Done
}

I really don't get why I get a different behavior between running wkhtmltopdf from the command line and running it using this go wrapper ...

QXcbConnection: Could not connect to display

As already opened here => Bug, I retrieve this error message trying to generate a PDF from a "working" HTML.
I am not able to adapt that because I am not using wkhtmltopdf as pure command, but obviously using this library.
Is it possible to adapt this with xvfb command?

Not sure if it finds wkhtmltopdf

Hi,

I tried all the path instructions including copying wkhtmltopdf to the directory where the Go program resides, but the program always generate a pdf of size 366kb, which doesn't open, and exit with no error.

Could you please help. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.