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

[Feature Proposal] PDFWriter .save() with specific file path #71

Open
YongSeok-Choi51 opened this issue Oct 13, 2024 · 0 comments
Open

Comments

@YongSeok-Choi51
Copy link

Describe your idea

save modified PDF to specific destination file path without copy of whole PDF buffer

How could this be implemented?

add saveOnFilePath: string variant to SaveOptions interface
and returns Promise<Uint8Array> | Promise<string>

or separate two methods (ex. PDFDocument.save(), PDFDocument.saveToDestFile(filePath:string))

What problem are you trying to solve?

Usage Environment of this Library: AWS Lambda (memorySize: 1024MB)

Problem Scenario

  • The input PDF is approximately 1024MB.
  • A modification is applied to the input PDF (e.g., adding text with drawText).
  • When using PDFDocument.save() to save the modified PDF (which is the input), I encounter an issue.

When I call PDFDocument.save(), an error occurs due to insufficient memory in AWS Lambda, causing the execution to fail. After investigating the issue, I discovered the cause.

PDFDocument.save() ultimately calls PDFWriter.serializeToBuffer(), which copies the entire original PDF buffer.

Whenever the input PDF size exceeds half of the AWS Lambda memory size (1024MB), a memory shortage exception occurs.

To resolve this, I had to increase the memory size to more than 1GB, which incurs additional costs.

Why does this matter to you?

with this problem, i have to pay more infrastructure cost which is critical of business

Would others find this helpful?

Most users who use serverless environment (AWS LAMBDA)

Are you interested in implementing your proposal?

Yes

Why are you submitting a proposal?

Suggestion
I propose adding a function that accepts a file path, rather than copying the modified buffer. This function would return the file path of the saved PDF file.

This solution would alleviate memory constraints in environments like AWS Lambda and help reduce infrastructure costs while maintaining the same functionality.

Additional Notes

No response

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

No branches or pull requests

1 participant