Closed knight-ni closed 1 year ago
Hi @knight-ni,
Could you share the runnable code snippet and the DOCX file that generated by UniOffice?
Best regards, Alip
const licfile = "dmHC.lic"
func init() {
apiKey, err := file.ReadFile(licfile)
if apiKey == "" {
fmt.Errorf("missing License")
}
err = unipdflicense.SetMeteredKey(apiKey)
if err != nil {
fmt.Printf("ERROR: Failed to set metered key: %v\n", err)
fmt.Printf("Make sure to get a valid key from https://cloud.unidoc.io\n")
fmt.Printf("If you don't have one - Grab one in the Free Tier at https://cloud.unidoc.io\n")
panic(err)
}
// This example requires both for unioffice and unipdf.
err = license.SetMeteredKey(apiKey)
if err != nil {
fmt.Printf("ERROR: Failed to set metered key: %v\n", err)
fmt.Printf("Make sure to get a valid key from https://cloud.unidoc.io\n")
fmt.Printf("If you don't have one - Grab one in the Free Tier at https://cloud.unidoc.io\n")
panic(err)
}
}
func WordToPDF(myhost sftptool.HostInfo, localdir string, detail int) error {
var docxname string
var pdfname string
filter := regexp.MustCompile(`.docx`)
for _, f := range *myhost.FLST {
if filter.FindString(f) != "" {
docxname = hctool.SmartPathJoin(myhost.OS, localdir, f)
doc, err := document.Open(docxname)
if err != nil {
return fmt.Errorf("open Docx File %s Failed", docxname)
}
defer doc.Close()
pdfname = strings.TrimSuffix(docxname, ".docx") + ".pdf"
c := convert.ConvertToPdf(doc)
err = c.WriteToFile(pdfname)
if err != nil {
return fmt.Errorf("write PDF File %s Failed", pdfname)
}
}
}
if detail > 0 {
fmt.Printf(">>>>>> Converting Docx File %s <<<<<<<\n", docxname)
}
return nil
}
and my docx file as attached
[测试用户1_测试业务1_centos_DMSERVER20230530.docx](https://github.com/unidoc/unioffice/files/11595345/1_.1_centos_DMSERVER20230530.docx)
Thank you for sharing the code snippet and file, we will check this issue.
Hi @knight-ni,
We released new UniOffice version https://github.com/unidoc/unioffice/releases/tag/v1.26.0 to solve the nil pointer issue.
Hi @sampila ,
after upgrade to v1.26.0, i got another error as followed, anything should i do to fix this ?
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]: github.com/unidoc/unioffice/document/convert.(convertContext).addAbsoluteTable(0xc0009b6c80, 0xc0000a9a40) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.26.0/document/convert/convert.go:47 +0x2379 github.com/unidoc/unioffice/document/convert.(convertContext).addAbsoluteCBCs(0xc0009b6c80, {0xc0005b57d0, 0x1, 0xc000241958?}, {0xc0005b57f8?, 0x1, 0xc00024191b?}) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.26.0/document/convert/convert.go:18 +0x7ed github.com/unidoc/unioffice/document/convert.ConvertToPdfWithOptions(0xc000002000, 0x0) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.26.0/document/convert/convert.go:18 +0xae6 github.com/unidoc/unioffice/document/convert.ConvertToPdf(...) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.26.0/document/convert/convert.go:15 dmHC_Runner/pkg/docx2pdf.WordToPDF({{0xc000352eab, 0xd}, {0xc000352eca, 0xd}, {0xc0001bf630, 0x4c}, {0xc000352eea, 0xe}, 0x16, 0x1474, ...}, ...) E:/BaiduNetdiskWorkspace/work/DM/property/mytools/dmHC_Runner/pkg/docx2pdf/docx2pdf.go:26 +0x205 main.main() E:/BaiduNetdiskWorkspace/work/DM/property/mytools/dmHC_Runner/main.go:91 +0xa10
Process finished with the exit code 2
Hi @knight-ni,
Is it same docx file or different one?
i tried the file last time sended,but seems words missing and misplacement occured 1_.1_centos_DMSERVER20230530.pdf and when i try with this file ,i got that error 测试用户1_测试业务1_centos_DMSERVER20230706.docx
i tried the file last time sended,but seems words missing and misplacement occured 1_.1_centos_DMSERVER20230530.pdf and when i try with this file ,i got that error 测试用户1_测试业务1_centos_DMSERVER20230706.docx
Currently we are working to get the results close to what MS Word to PDF conversion.
Do you still having issue with the nil pointer issue? it would be great if you could share the docx file that having the nil pointer issue.
nil pointer issue no longer occured now, will be close this issue ,thx
Description
after generate docx by unioffice, i tried convert to pdf, but got errror followed, anyone could help?
Actual Behavior
panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=0x10a6f74]
goroutine 1 [running]: github.com/unidoc/unioffice/document/convert.(convertContext).addAbsoluteTable(0xc000bdaf00, 0xc000107d80) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.24.0/document/convert/convert.go:15 +0x1974 github.com/unidoc/unioffice/document/convert.(convertContext).addAbsoluteCBCs(0xc000bdaf00, {0xc0000ec6a8, 0x1, 0xc0004a5958?}, {0xc0000ec6d0?, 0x1, 0xc0004a5958?}) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.24.0/document/convert/convert.go:15 +0x7ed github.com/unidoc/unioffice/document/convert.ConvertToPdfWithOptions(0xc000002300, 0x0) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.24.0/document/convert/convert.go:18 +0xae6 github.com/unidoc/unioffice/document/convert.ConvertToPdf(...) E:/testddir/gopath/pkg/mod/github.com/unidoc/unioffice@v1.24.0/document/convert/convert.go:15 dmHC_Runner/pkg/docx2pdf.WordToPDF({{0xc0000201ab, 0xd}, {0xc0000202aa, 0xd}, {0xc0001983c0, 0x47}, {0xc0000202ca, 0xe}, 0x16, 0x1474, ...}, ...) E:/BaiduNetdiskWorkspace/work/DM/property/mytools/dmHC_Runner/pkg/docx2pdf/docx2pdf.go:42 +0x205 main.main() E:/BaiduNetdiskWorkspace/work/DM/property/mytools/dmHC_Runner/main.go:91 +0xa10
Process finished with the exit code 2
Please include a reproducible code snippet or document attachment that demonstrates the issue.