PDF file size when saveas via Job Queue results in 100mb file

jordi79
Member Posts: 280
We have developed a report batch job that saveas a PDF file and send it via email. We observe that when set in a job queue, after running for > 2 hours (sending a lot of emails), the email server started rejecting the emails. Upon closer inspection, we found that the PDF attachments increased in size, up to 100MB per pdf file, and the email server rejected these emails due to the size of the pdf file.
When the this batch job is run individually, the pdf file size remains small. But when it is run and processing for > 2 hours, we could see the file size increasing up to 100MB.
Code snippet -->
When I compared the 2 pdf files (100kb vs 100mb) they look identical. When opened as text and compared there are a lot of binary differences. I refuse to believe that this is due to font embedding. There is no way font embedding resulted in a 100k file vs a 100mb file?
p/s This is run on BC Online.
When the this batch job is run individually, the pdf file size remains small. But when it is run and processing for > 2 hours, we could see the file size increasing up to 100MB.
Code snippet -->
d.open('Progress #1##############'); TotalCount := InVendLedgEntry.count; repeat CurrCount += 1; d.update(1, strsubstno('%1 of %2', CurrCount, TotalCount)); Vendor.get(InVendLedgEntry."Vendor No."); if InTestEmailAddr <> '' then EmailAddr := InTestEmailAddr else EmailAddr := Vendor."E-Mail"; TempBlob.CreateOutStream(oStr); VendLedgEntry := InVendLedgEntry; VendLedgEntry.SetRecFilter(); clear(VendorPaymentReceipt); VendorPaymentReceipt.SetTableView(VendLedgEntry); if VendorPaymentReceipt.SaveAs('', ReportFormat::Pdf, oStr) then begin AttachmentName := 'PaymentVoucher' + InVendLedgEntry."Document No."; AttachmentName := FileManagement.GetSafeFileName(AttachmentName) + '.pdf'; TempBlob.CreateInStream(iStr); EmailMsg.create( EmailAddr, strsubstno(InEmailSubject, vendor.name, vendor.Contact, InVendLedgEntry."Document No."), strsubstno(InEmailBody, vendor.name, vendor.Contact, InVendLedgEntry."Document No.")); if InccEmailAddr <> '' then EmailMsg.AddRecipient("Email Recipient Type"::Cc, InccEmailAddr); EmailMsg.SetBodyHTMLFormatted(true); EmailMsg.AddAttachment(AttachmentName, 'pdf', istr); //Email.send(EmailMsg); ClearLastError(); If not TryEmailSend(EmailMsg) then error('Email send failed for %1.\\Last Error was %2.\\Error callstack was %3', InVendLedgEntry.RecordId, GetLastErrorText(), GetLastErrorCallStack); end; until InVendLedgEntry.next = 0;
When I compared the 2 pdf files (100kb vs 100mb) they look identical. When opened as text and compared there are a lot of binary differences. I refuse to believe that this is due to font embedding. There is no way font embedding resulted in a 100k file vs a 100mb file?
p/s This is run on BC Online.
0
Best Answer
-
Notes to take into attention:
1. How many records Vendor Ledger entry comes from parent code. VendorPaymentReceipt report processes all incoming records to one PDF.
2. In all cases clear variables, especially streams.
1
Answers
-
Notes to take into attention:
1. How many records Vendor Ledger entry comes from parent code. VendorPaymentReceipt report processes all incoming records to one PDF.
2. In all cases clear variables, especially streams.
1 -
As the user above mentioned try first doing CLEAR(TempBlob) and CLEAR(EmailMsg) every time the code loop starts. apart from that without debugging it it's hard to say.0
-
after "CLEAR"ing streams and tempblob, i no longer had this issue.
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions