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

jordi79jordi79 Member Posts: 278
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 --> 

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.

Answers

  • lubostlubost Member Posts: 629
    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.

Sign In or Register to comment.