如何解决权限被拒绝使用Go在Mac中写入文件wkhtmltopdf
我有一些与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 举报,一经查实,本站将立刻删除。