windows export pdf

This commit is contained in:
lealife
2017-07-27 20:00:53 +08:00
parent 6ede5c1559
commit 825fda5544
3 changed files with 26 additions and 9 deletions

View File

@ -447,8 +447,12 @@ func (c Note) ExportPdf(noteId string) revel.Result {
binPath := configService.GetGlobalStringConfig("exportPdfBinPath")
// 默认路径
if binPath == "" {
if runtime.GOOS == "windows" {
binPath = `C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe`
} else {
binPath = "/usr/local/bin/wkhtmltopdf"
}
}
url := configService.GetSiteUrl() + "/note/toPdf?noteId=" + noteId + "&appKey=" + appKey
// cc := binPath + " --no-stop-slow-scripts --javascript-delay 10000 \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\""
@ -457,15 +461,28 @@ func (c Note) ExportPdf(noteId string) revel.Result {
// http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf_0.10.0_rc2-doc.html
// wkhtmltopdf参数大全
var cc string
// var cc []string
var ccWindows []string
if note.IsMarkdown {
cc = binPath + " --lowquality --window-status done \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\""
// cc = []string{binPath, "--lowquality", "--window-status", "done", "\"" + url + "\"", "\"" + path + "\""}
ccWindows = []string{"/C", binPath, "--lowquality", "--window-status", "done", url, path}
} else {
cc = binPath + " --lowquality \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\""
// cc = []string{binPath, "--lowquality", "\"" + url + "\"", "\"" + path + "\""}
ccWindows = []string{"/C", binPath, "--lowquality", url, path}
}
cmd := exec.Command("/bin/sh", "-c", cc)
if runtime.GOARCH == "windows" {
cmd = exec.Command("cmd", "/C", cc)
var cmd *exec.Cmd
// fmt.Println("-------1", runtime.GOOS, ccWindows)
if runtime.GOOS == "windows" {
fmt.Println(ccWindows)
// cmd = exec.Command("cmd", ccWindows...)
cmd = exec.Command(ccWindows[1], ccWindows[2:]...)
} else {
fmt.Println(cc)
cmd = exec.Command("/bin/sh", "-c", cc)
}
_, err := cmd.Output()
if err != nil {

View File

@ -12,7 +12,7 @@
<input type="text" class="form-control" placeholder="/usr/local/bin/wkhtmltopdf" name="path" value="{{.str.exportPdfBinPath}}">
Leanote use <a target="_blank" href="http://wkhtmltopdf.org">wkhtmltopdf</a> to export pdf. You should install it on your server.
<br />
Please input the path that wkhtmltopdf installed, e.g. <code>/usr/local/bin/wkhtmltopdf</code>
Please input the path that wkhtmltopdf installed, e.g. <code>/usr/local/bin/wkhtmltopdf</code> on mac os/linux or <code><C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe/code> on windows.
</div>
</div>

View File

@ -4,13 +4,13 @@ cd..
set SCRIPTPATH=%cd%
: top src directory
set path="%SCRIPTPATH%\bin\src\github.com\leanote"
set leanotePath="%SCRIPTPATH%\bin\src\github.com\leanote"
if not exist "%path%" mkdir "%path%"
if not exist "%leanotePath%" mkdir "%leanotePath%"
: create software link
if exist "%path%\leanote" del /Q "%path%\leanote"
mklink /D "%path%\leanote" %SCRIPTPATH%
if exist "%leanotePath%\leanote" del /Q "%leanotePath%\leanote"
mklink /D "%leanotePath%\leanote" %SCRIPTPATH%
: set GOPATH
set GOPATH="%SCRIPTPATH%\bin"