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

[BUG] File left open after call to unihtml.NewDocument #9

Closed
radnams opened this issue Mar 6, 2023 · 3 comments
Closed

[BUG] File left open after call to unihtml.NewDocument #9

radnams opened this issue Mar 6, 2023 · 3 comments

Comments

@radnams
Copy link

radnams commented Mar 6, 2023

Description

Im writing HTML to a temporary local file then loading that via unihtml.NewDocument() but after successfully creating a PDF from that HTML file and leaving that function, I'm unable to delete that temporary file straight away via os.Remove(). It's only after some time that the file lock is released (perhaps when GC cleans up?) that I can then delete the file.

Expected Behavior

I would like to be able to delete the file that is used by unihtml.NewDocument() after I'm done using it or a way to explictly Close() the unihtml.Document() returned from it

Actual Behavior

Steps to reproduce the behavior:
This is the code I'm running to generate the PDF from the HTML file.

func createPdfFromHtml(htmlPath string) ([]byte, error) {

        // Load the html document from disk
	htmlDocument, err := unihtml.NewDocument(htmlPath)
	if err != nil {
		return nil, fmt.Errorf("html document error: %v\n", err)
	}

	// Make a new pdf creator
	c := creator.New()

	// Draw the html document
	if err = c.Draw(htmlDocument); err != nil {
		return nil, fmt.Errorf("draw error: %v\n", err)
	}

	// Write creator output to memory and return the bytes
	// rather than write to disk
	var b bytes.Buffer
	buf := bufio.NewWriter(&b)

	err = c.Write(buf)
	if err != nil {
		return nil, fmt.Errorf("write error: %v\n", err)
	}

	return b.Bytes(), nil
}

Following a call to this I attempt to delete the HTML file via os.Remove(htmlPath) but it can fail with:-

The process cannot access the file because it is being used by another process.

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

@sampila
Copy link
Collaborator

sampila commented Jun 21, 2024

Hi @radnams,

We are tried but unable to reproduce the issue, could you share code snippet to reproduce this issue for further investigation?

Best,
Alip

@ahall
Copy link

ahall commented Aug 13, 2024

Closing until we get a reproducable case.

@ahall ahall closed this as completed Aug 13, 2024
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

3 participants