Skip to content

[BUG]Highlighted Text/Forms/Links not exported #576

@TheGoderGuy

Description

@TheGoderGuy

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:

  1. Add highlight to template
  2. Use code to generate
  3. ???
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions