ソースを参照

pdf加文字水印

yuedefeng 6 年 前
コミット
44fc5e59c4

+ 48 - 0
src/dashoo.cn/backend/api/business/workflow/ActivitiService.go

@@ -385,6 +385,54 @@ func (this *ActivitiService) WordToPdf(addressUrl string) string {
 	return retDocUrl
 }
 
+func (this *ActivitiService) WordToPdfWithWatermark(wartermark, addressUrl string) string {
+	var aposeVM AposeVM
+	aposeVM.AddressUrl = addressUrl
+	aposeVM.Watermark = wartermark
+	fmt.Println("==addressUrl===", addressUrl)
+	jsonParam, err := json.Marshal(aposeVM)
+	if err != nil {
+		fmt.Println(err, "生成json字符串错误")
+	}
+	params := string(jsonParam)
+	//token = Authorization(this.Username, this.Password)
+	retVal := this.Post2("/word-to-pdf-watermark", params, "")
+	if retVal.StatusCode != 200 {
+		return ""
+	}
+	//pdfByte, err := ioutil.ReadAll(retVal.Body)
+	//ioutil.WriteFile("E:\aa.pdf", pdfByte, 777)
+	//模板下载到服务器
+	_dir := utils.Cfg.MustValue("file", "tmplateDir") + "pdf"
+	utils.CreatePath(_dir)
+	_dir += "/tmp_" + strconv.Itoa(int(time.Now().Unix())) + ".pdf"
+	raw := retVal.Body
+	defer raw.Close()
+
+	file, err := os.Create(_dir)
+	defer file.Close()
+	writer := bufio.NewWriter(file)
+	defer writer.Flush()
+	body, err := ioutil.ReadAll(raw)
+	writer.Write(body)
+
+	if err != nil {
+		return ""
+	}
+	var sw *Seaweed
+	var filer []string
+	if _filer := os.Getenv("GOSWFS_FILER_URL"); _filer != "" {
+		filer = []string{_filer}
+	}
+	sw = NewSeaweed("http", utils.Cfg.MustValue("file", "upFileHost"), filer, 2*1024*1024, 5*time.Minute)
+	//_, fID, err := sw.Upload(retVal.Body, "tmp.pdf", int64(len(pdfByte)), "", "")
+	_, _, fID, err := sw.UploadFile(_dir, "", "")
+	retDocUrl := utils.Cfg.MustValue("file", "downFileHost") + "/" + fID
+	os.Remove(_dir)
+	fmt.Println("==retDocUrl==", retDocUrl)
+	return retDocUrl
+}
+
 func (this *ActivitiService) FillWordTemplate(datas map[string]interface{}, templateUrl string, fileName string) string {
 	var wordTempVM WordTemplateVM
 	wordTempVM.Datas = datas

+ 1 - 0
src/dashoo.cn/backend/api/business/workflow/workflow.go

@@ -44,6 +44,7 @@ type ActiHistoricTask struct {
 
 type AposeVM struct {
 	AddressUrl string `json:"addressUrl"`
+	Watermark  string `json:"watermark"`
 }
 
 type WordTemplateVM struct {

+ 21 - 0
src/dashoo.cn/backend/api/controllers/oilsupplier/supplierdataentry.go

@@ -5,6 +5,7 @@ import (
 	"dashoo.cn/backend/api/business/workflow"
 	. "dashoo.cn/backend/api/controllers"
 	"dashoo.cn/utils"
+	"encoding/json"
 	"reflect"
 	"strconv"
 )
@@ -35,6 +36,11 @@ type DataEntryCallback struct {
 	DocUrl string `json:"DocUrl"`
 }
 
+type PdfRequest struct {
+	PdfUrl     string `json:"pdfUrl"`
+	Watermark  string `json:"watermark"`
+}
+
 func StructToMapDemo(obj interface{}) map[string]interface{} {
 	obj1 := reflect.TypeOf(obj)
 	obj2 := reflect.ValueOf(obj)
@@ -341,3 +347,18 @@ func (this *SupplierDataEntryController) WordToPdf() {
 	this.Data["json"] = pdfUrl
 	this.ServeJSON()
 }
+
+// @Title post
+// @Description word to pdf
+// @Success 200 {string} pdfurl
+// @router /word-to-pdf-watermark [post]
+func (this *SupplierDataEntryController) WordToPdfWithWatermark() {
+	var pdfRequest PdfRequest
+	var jsonBlob = this.Ctx.Input.RequestBody
+	json.Unmarshal(jsonBlob, &pdfRequest)
+
+	svcActiviti := workflow.GetActivitiService(utils.DBE)
+	pdfUrl := svcActiviti.WordToPdfWithWatermark(pdfRequest.Watermark, pdfRequest.PdfUrl)
+	this.Data["json"] = pdfUrl
+	this.ServeJSON()
+}

+ 12 - 4
src/dashoo.cn/frontend_web/src/pages/select/companyselect/index.vue

@@ -916,16 +916,24 @@ export default {
               const myDomain = window.location.host
               // location.href = 'http://' + myDomain + '/' + docurl
               pdfurl = 'http://' + myDomain + '/' + docurl
-              this.$axios.post('supplierdataentry/word-to-pdf?pdfurl=' + pdfurl, {})
+              let requestParams = {
+                pdfUrl: pdfurl,
+                watermark: val.SupplierName
+              }
+              this.$axios.post('supplierdataentry/word-to-pdf-watermark', requestParams)
                 .then(function (res) {
-                  window.location.href = 'http://' + res.data
+                  window.open('http://' + res.data)
                 })
             } else {
               // location.href = 'http://' + docurl
               pdfurl = 'http://' + docurl
-              this.$axios.post('supplierdataentry/word-to-pdf?pdfurl=' + pdfurl, {})
+              let requestParams = {
+                pdfUrl: pdfurl,
+                watermark: val.SupplierName
+              }
+              this.$axios.post('supplierdataentry/word-to-pdf-watermark', requestParams)
                 .then(function (res) {
-                  window.location.href = 'http://' + res.data
+                  window.open('http://' + res.data)
                 })
             }
           }