-
Notifications
You must be signed in to change notification settings - Fork 277
Description
Description
Any highlighted Elements in docx won't be exported on PDF convert.
Seems like the highlighted text already disappears after template filling just before converting
Expected Behavior
Highlighted text from templates should be exported to pdf
Actual Behavior
Steps to reproduce the behavior:
- Add highlight to template
- Use code to generate
- ???
- PDF without highlight
Attachments
`package main
import (
"fmt"
"log"
"os"
cfg "github.com/ardanlabs/conf/v3"
"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/document"
"github.com/unidoc/unioffice/document/convert"
pdflicense "github.com/unidoc/unipdf/v3/common/license"
)
type config struct {
UniofficeLicenseKey string conf:"flag:license,env:LICENSE_KEY"
UniofficeCustomerName string conf:"flag:name,env:CUSTOMER_NAME"
UniofficeApiKey string conf:"flag:key,env:API_KEY"
}
func main() {
var conf config
txt, err := cfg.Parse("", &conf)
if err == cfg.ErrHelpWanted {
fmt.Println(txt)
os.Exit(0)
}
if err != nil {
fmt.Println(err)
fmt.Println(txt)
os.Exit(1)
}
switch {
case conf.UniofficeApiKey != "":
if err := license.SetMeteredKey(conf.UniofficeApiKey); err != nil {
fmt.Println(err, "set unioffice api key")
os.Exit(1)
}
if err := pdflicense.SetMeteredKey(conf.UniofficeApiKey); err != nil {
fmt.Println(err, "set unipdf api key")
os.Exit(1)
}
case conf.UniofficeLicenseKey != "":
if conf.UniofficeCustomerName == "" {
fmt.Println("customer name required for license key")
os.Exit(1)
}
if err := license.SetLicenseKey(conf.UniofficeLicenseKey, conf.UniofficeCustomerName); err != nil {
fmt.Println(err, "set unioffice license key")
os.Exit(1)
}
if err := pdflicense.SetLicenseKey(conf.UniofficeLicenseKey, conf.UniofficeCustomerName); err != nil {
fmt.Println(err, "set unipdf license key")
os.Exit(1)
}
default:
fmt.Println("neither api or license key provided")
os.Exit(1)
}
doc, err := document.Open("crash-test-dummy.docx")
if err != nil {
log.Fatal(err)
}
defer doc.Close()
// doc has to be copied so the eventually added images of barcodes are also exported to the PDF
renewedDoc, err := doc.Copy()
if err != nil {
log.Fatal(err)
}
temporaryDocxFile, err := os.CreateTemp(".", "*.docx")
if err != nil {
log.Fatal(err)
}
defer os.Remove(temporaryDocxFile.Name())
defer temporaryDocxFile.Close()
err = renewedDoc.SaveToFile(temporaryDocxFile.Name())
if err != nil {
log.Fatal(err)
}
defer renewedDoc.Close()
completed, err := document.Open(temporaryDocxFile.Name())
if err != nil {
log.Fatal(err)
}
defer completed.Close()
convert.RegisterFontsFromDirectory("ttf")
pdfDoc := convert.ConvertToPdf(completed)
err = pdfDoc.WriteToFile("crash-test-dummy.pdf")
if err != nil {
log.Fatal(err)
}
}`
unidoc_export.pdf
3rdparty_export.pdf
Attached are a rightly filled pdf and the unidoc pdf.
This bug hits all kinds of things possible in word: Text, Tables, forms like checkboxes, Radio Buttons etc.
Verison:
github.com/unidoc/unioffice v1.39.0
github.com/unidoc/unipdf/v3 v3.65.0