Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nil pointer when convert docx to pdf #488

Closed
knight-ni opened this issue May 30, 2023 · 9 comments
Closed

nil pointer when convert docx to pdf #488

knight-ni opened this issue May 30, 2023 · 9 comments

Comments

@knight-ni
Copy link

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.

@sampila
Copy link
Collaborator

sampila commented May 30, 2023

Hi @knight-ni,

Could you share the runnable code snippet and the DOCX file that generated by UniOffice?

Best regards,
Alip

@knight-ni
Copy link
Author

#my code seems like this

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)

@sampila
Copy link
Collaborator

sampila commented May 30, 2023

Thank you for sharing the code snippet and file, we will check this issue.

@sampila
Copy link
Collaborator

sampila commented Jul 4, 2023

Hi @knight-ni,

We released new UniOffice version https://github.com/unidoc/unioffice/releases/tag/v1.26.0 to solve the nil pointer issue.

@knight-ni
Copy link
Author

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

@sampila
Copy link
Collaborator

sampila commented Jul 6, 2023

Hi @knight-ni,

Is it same docx file or different one?

@knight-ni
Copy link
Author

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

@sampila
Copy link
Collaborator

sampila commented Jul 6, 2023

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.

@knight-ni
Copy link
Author

nil pointer issue no longer occured now, will be close this issue ,thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants