mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-28 04:18:48 +01:00
🔥 PDF export supports setting footer template https://github.com/siyuan-note/siyuan/issues/7478
Use frontend instead of backend impl
This commit is contained in:
parent
cd0fb32d38
commit
d544fec54e
2 changed files with 0 additions and 100 deletions
|
|
@ -29,7 +29,6 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
|
|
@ -41,7 +40,6 @@ import (
|
|||
"github.com/88250/lute/render"
|
||||
"github.com/88250/pdfcpu/pkg/api"
|
||||
"github.com/88250/pdfcpu/pkg/pdfcpu"
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/emirpasic/gods/stacks/linkedliststack"
|
||||
"github.com/imroc/req/v3"
|
||||
|
|
@ -715,7 +713,6 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) {
|
|||
|
||||
processPDFBookmarks(pdfCtx, headings)
|
||||
processPDFLinkEmbedAssets(pdfCtx, assetDests, removeAssets)
|
||||
processPDFFooter(pdfCtx)
|
||||
|
||||
pdfcpu.VersionStr = "SiYuan v" + util.Ver
|
||||
if writeErr := api.WriteContextFile(pdfCtx, p); nil != writeErr {
|
||||
|
|
@ -975,50 +972,6 @@ func processPDFLinkEmbedAssets(pdfCtx *pdfcpu.Context, assetDests []string, remo
|
|||
}
|
||||
}
|
||||
|
||||
func processPDFFooter(pdfCtx *pdfcpu.Context) {
|
||||
templateContent := strings.TrimSpace(Conf.Export.PDFFooter)
|
||||
if "" == templateContent {
|
||||
return
|
||||
}
|
||||
|
||||
footerTpl, err := template.New("").Funcs(sprig.TxtFuncMap()).Parse(templateContent)
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse pdf footer template failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
buf.Grow(4096)
|
||||
err = footerTpl.Execute(buf, nil)
|
||||
if nil != err {
|
||||
logging.LogErrorf("render pdf footer template failed: %s", err)
|
||||
return
|
||||
}
|
||||
footer := buf.String()
|
||||
|
||||
fontName := util.InstallPDFFonts()
|
||||
|
||||
pos := "bc"
|
||||
desc := fmt.Sprintf("font:%s, points:8, sc:1 abs, pos:%s, off:10 10, fillc: 0.5 0.5 0.5, rot:0", fontName, pos)
|
||||
footer = strings.ReplaceAll(footer, "%pages", strconv.Itoa(pdfCtx.PageCount))
|
||||
m := map[int]*pdfcpu.Watermark{}
|
||||
for i := 1; i <= pdfCtx.PageCount; i++ {
|
||||
text := strings.ReplaceAll(footer, "%page", strconv.Itoa(i))
|
||||
wm, watermarkErr := api.TextWatermark(text, desc, true, false, pdfcpu.POINTS)
|
||||
if nil != watermarkErr {
|
||||
logging.LogErrorf("add pdf footer failed: %s", watermarkErr)
|
||||
return
|
||||
}
|
||||
|
||||
m[i] = wm
|
||||
}
|
||||
|
||||
if watermarkErr := pdfCtx.AddWatermarksMap(m); nil != watermarkErr {
|
||||
logging.LogErrorf("add pdf footer failed: %s", watermarkErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func ExportStdMarkdown(id string) string {
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue