问题描述
我有一些与wkhtmltopdf驱动程序权限相关的奇怪异常。我在Mac OS上。
我在仓库中有下一个代码:https://github.com/PumpkinSeed/htmltopdf
当我尝试运行测试用例时:
package htmltopdf
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExample1(t *testing.T) {
err := Example("examples/invoice-template-1/invoice.html","./invoice1.pdf")
assert.NoError(t,err)
}
func TestExample2(t *testing.T) {
err := Example("examples/invoice-template-2/invoice.html","./invoice2.pdf")
assert.NoError(t,err)
}
我遇到了问题:
=== RUN TestExample1
htmltopdf_test.go:12:
Error Trace: htmltopdf_test.go:12
Error: Received unexpected error:
fork/exec /Users/rpantoja/Desktop: permission denied
Test: TestExample1
--- FAIL: TestExample1 (0.00s)
=== RUN TestExample2
htmltopdf_test.go:18:
Error Trace: htmltopdf_test.go:18
Error: Received unexpected error:
fork/exec /Users/rpantoja/Desktop: permission denied
Test: TestExample2
这是我的htmltopdf.go文件的外观:
package htmltopdf
import (
"bytes"
"io/IoUtil"
"github.com/SebastiaanKlippert/go-wkhtmltopdf"
)
const path = "/Users/rpantoja/Desktop"
func Example(file string,pdfFile string) error {
html,err := IoUtil.ReadFile(file)
if err != nil {
return err
}
wkhtmltopdf.SetPath(path)
pdfg,err := wkhtmltopdf.NewPDFGenerator()
if err != nil {
return err
}
page := wkhtmltopdf.NewPageReader(bytes.NewReader(html))
page.NoBackground.Set(true)
page.disableExternalLinks.Set(false)
pdfg.AddPage(page)
pdfg.Dpi.Set(350)
pdfg.MarginBottom.Set(0)
pdfg.MarginTop.Set(0)
pdfg.MarginLeft.Set(0)
pdfg.MarginRight.Set(0)
err = pdfg.Create()
if err != nil {
return err
}
err = pdfg.WriteFile(pdfFile)
if err != nil {
return err
}
return nil
}
似乎我缺少什么,是否缺少任何配置,任何想法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)