Closed xizaidqm closed 3 years ago
Hi @xizaidqm.
The idea is to inform Go about the location of the wkhtmltox
SDK files prior to building your application, in the same environment.
set CGO_LDFLAGS=-LE:\wkhtmltox\bin
set CGO_CFLAGS=-IE:\wkhtmltox\include
So in your case, one solution would be running the commands above in the terminal of your IDE/editor (I'm not sure what you are using) prior to doing go build main.go
.
Another solution would be to build your application from a Windows cmd
instance. So you would open a cmd
instance in the location you have your project (where you have your main.go
file) and run the commands there:
set CGO_LDFLAGS=-LE:\wkhtmltox\bin
set CGO_CFLAGS=-IE:\wkhtmltox\include
go build main.go
Also, I see you are getting some C
errors when trying to build your application. You might need to install the MinGW toolchain
. Please see https://github.com/adrg/go-wkhtmltopdf/wiki/Install-MinGW-toolchain for that.
Hello @adrg ! Thanks for your quick support!
I followed your advise and install suitable MinGW. Now I can build my program and generate main.exe.
However, when I run main.exe, it seems does not work. When I tried to convert html file to corresponding PDF file, the PDF file is 0KB, and I can not even open it. (content.html is the source file, content.pdf is generated by running main.exe)
My source code is as followed.
In the picture above, "filePath" is the absolute path of content.html, "outputPath" is the absolute path of content.pdf.
How can I solve this problem? Is this my code fault or something else?
Hi @xizaidqm. I think you forgot to do (at least I don't see it in the picture you attached):
converter.Add(object)
You need to add the objects you create to the converter (before doing converter.Run()
) in order for them to be added to the output PDF file.
Let me know if that solves your issue.
Thank you for your kind answer.
I have solved my issues and now I can generate PDF file successfully by running main.exe.
Glad to hear you solved the problem you were having. Please close this issue if everything is sorted out.
Hello
When I followed this instruction to install wkhtmltox in my Windows, some errors occured.
When I tried to use "go build" in cmd, I got the message as follows. It said "package .: no Go files in E:\wkhtmltox". How can I solve this problem?
Although I "go build" failed, I still tried to run my program. Unfortunately, it did not work and gave me some error messages. How can I solve with it?
Please Help me! Thank you!