diff --git a/app/controllers/NoteController.go b/app/controllers/NoteController.go index 4288cca..1cb434e 100644 --- a/app/controllers/NoteController.go +++ b/app/controllers/NoteController.go @@ -447,7 +447,11 @@ func (c Note) ExportPdf(noteId string) revel.Result { binPath := configService.GetGlobalStringConfig("exportPdfBinPath") // 默认路径 if binPath == "" { - binPath = "/usr/local/bin/wkhtmltopdf" + 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 @@ -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 { diff --git a/app/views/admin/setting/export_pdf.html b/app/views/admin/setting/export_pdf.html index 0a27d13..0686eb3 100644 --- a/app/views/admin/setting/export_pdf.html +++ b/app/views/admin/setting/export_pdf.html @@ -12,7 +12,7 @@ Leanote use wkhtmltopdf to export pdf. You should install it on your server.
- Please input the path that wkhtmltopdf installed, e.g. /usr/local/bin/wkhtmltopdf + Please input the path that wkhtmltopdf installed, e.g. /usr/local/bin/wkhtmltopdf on mac os/linux or on windows. diff --git a/bin/run.bat b/bin/run.bat index cdb3831..4a47499 100644 --- a/bin/run.bat +++ b/bin/run.bat @@ -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"