Is there a way to add custom writer for output? #482
Labels
in analysis
Analyzing if should be implemented
new feature
New feature or request
v2
will be solved in v2
Is your feature request related to a problem? Please describe.
I'm trying to create a workflow to generate PDFs with QR Codes in the AWS Lambda runtime. The data is fetched from DB and gets passed to the maroto for creating grid of QR codes on pages, once the whole thing is ready then only we can get the document to get the raw byte which we can upload to S3. Now, this can get pretty slow if the data volume is larger and for serverless environments this is not a very good case.
The problem with this approach is that if the file content([]byte) is too big, we're not able to upload such big data with S3's PutObject command. we need to use multipart upload for such large payloads. So in lambda function we can't do such big operation where we're constrained with memory, execution time, space limitations.
Can we get a way where we can start the upload from the moment we create the instance of of maroto and attach a writer to it which will be called whenever any data is written to it, so that I can implement a custom writer that can upload this data to S3 bucket without having to load the whole bytes list and then pass this huge list for upload and reduce the temporary file storage on the runtime where the code is being executed.
I've tried the package
go-pdf/gpdf
for generating the pdf file and setting the custom output writer which uploads the file to S3 with multipart uploads. But only problem with that library is that it generates a very larger file due to QR codes in it. I tried to compress the QR codes buffer but did not get the good results with that either. Then I switched to Maroto, which give the QR code generation with it so one dependency less for generating QR codes explicitly and it also generated the pdf file with less size. Maybe I was doing something which I shouldn't be doing in thego-pds/fpdf
package that would have increased the size.If someone knows how to reduce the final size, I would appreciate your help.
Describe the solution you'd like
I want a solution where I can add the target where the bytes are going to get written to. Instead of creating the document by using
m.Generate()
, I want something like this:Maybe if there's something already present in the docs which I have missed, please let me know.
Describe alternatives you've considered
I've tried using the
go-pdf/fpdf
withskip2/go-qrcode
to generate pdf with qr codes in it. the issue with that approach was the size of generated output pdf file, and slower generation as the data got larger.I tried maroto to generate the pdf file for about 98K records and it was running for about 2Hrs and still did not finish writing the file to disk. Is there anything we can do to overcome this issue?
Additional context
N/A
The text was updated successfully, but these errors were encountered: