web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Email attachment - corrupt random pdfs

(0) ShareShare
ReportReport
Posted on by 948

Hi All, 

I am sending invoices as Pdf. I am using following code. It is sending selected invoices. But if I send 10 invoices 2 or 3 invoices get corrupted. But corrupted pdf can open from FoxitReader, not from Acrobat. 

But if I send only identified corrupted pdf , it works fine. 

Is there any problem with this code?

 if SalesInvoiceHdr.FindFirst() then
  repeat
    clear(outStreamReport);
    clear(inStreamReport);
    clear(RecRef);
    clear(emailMsg);
    SalesInvHdr.Reset();
    SalesInvHdr.SetRange("No.", SalesInvoiceHdr."No.");
    if SalesInvHdr.FindFirst() then
        RecRef.GetTable(SalesInvHdr);
    TempBlob.CreateOutStream(outStreamReport);
    TempBlob.CreateInStream(inStreamReport);
    body := '';
    emailMsg.Create(SalesInvoiceHdr."Sell-to E-Mail", 'Your invoice '   SalesInvHdr."No."   ' has been processed', body, true);
    Report.SaveAs(Report::"Posted Proforma Invoice", '', format::Pdf, outStreamReport, recRef);

    //txtB64 := cnv64.ToBase64(inStreamReport);
    emailMsg.AddAttachment('Sales Invoice '   SalesInvHdr."No."   '.pdf', 'pdf', inStreamReport);
    email.Send(emailMsg);

  until SalesInvoiceHdr.Next() = 0;

Thank you, 

I have the same question (0)
  • Verified answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi,

    Try to use below link for attachment

        emailMsg.AddAttachment('Sales Invoice ' + SalesInvHdr."No." + '.pdf', 'application/pdf', inStreamReport);

  • ShanAbeywicrema Profile Picture
    948 on at

    Hello Nitin,

    Thank you. I was using this. It does not solved the problem. I then I moved to this method. Problem is when I resend same invoice individual it is working. when send selected list, this happens. Again it is only for acrobat reader, it works for other readers.

    When I try pdf repair tool. I got following errors

    rrors:

    3-Heights(TM) PDF repair tool, evaluation license valid until unbounded

    Open file.

    Analyze Objects.

    0x80410301 - E - The object number is missing.

       - Object No.: 3

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 4

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 5

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 6

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 7

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 8

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 9

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 10

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 11

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 12

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 13

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410301 - E - The object number is missing.

       - Object No.: 14

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    0x80410302 - E - The generation number is missing.

       - Object No.: 15

       - File: Sales Invoice INV100552.pdf

    0x00418309 - W - The offset in the xref table is not correct.

       - File: Sales Invoice INV100552.pdf

    Analyze Outlines.

    Analyze Pages.

    0x80410402 - E - The page or page tree node has a missing or invalid "Type" key.

       - Object No.: 8

       - File: Sales Invoice INV100552.pdf

    0x80410113 - E - The file is corrupt and cannot be repaired. Some of the contents can possibly be recovered.

       - File: Sales Invoice INV100552.pdf

    Close file.

  • G_ABC Profile Picture
    2 on at
    Hi, 

    Have you been able to resolve this issue? I am facing the exact same issue.

    KR
  • Community member Profile Picture
    6 on at
    Also having this issue. I am exporting 1-20 invoices as .pdf into a zip file. Some open, some get error 109 but are able to be opened without issue in other reader applications. Any resolution?
     
    Thank you.
  • Jaakko Y. Profile Picture
    4 on at
    Hi,
     
    I would also be interested in hearing about the resolution as we are also facing the same issue. :) 

    Br, Jaakko
  • Suggested answer
    Kamal Khakhkhar Profile Picture
    1,274 on at
    Hii There,
     
    as per your requirement you can go through as per below Video. Follow the steps as per mentioned.
     
    https://youtu.be/niZrNBggpDs?si=ZRjPuqtqEbkUkAG0
     
    IF you found helpfull , Mark it Answered.
     
    Thank You,
    Kamal Khakhkhar
  • Suggested answer
    Jaakko Y. Profile Picture
    4 on at
    Hi,

    In our case, the problem was solved by moving the sending of the emails into a separate function.
     
    For example, in the original problem, move the below code into a separate function:
     
        TempBlob.CreateOutStream(outStreamReport);
        TempBlob.CreateInStream(inStreamReport);
        body := '';
        emailMsg.Create(SalesInvoiceHdr."Sell-to E-Mail", 'Your invoice '   SalesInvHdr."No."   ' has been processed', body, true);
        Report.SaveAs(Report::"Posted Proforma Invoice", '', format::Pdf, outStreamReport, recRef);
    
        //txtB64 := cnv64.ToBase64(inStreamReport);
        emailMsg.AddAttachment('Sales Invoice '   SalesInvHdr."No."   '.pdf', 'pdf', inStreamReport);
        email.Send(emailMsg);
    -Jaakko

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans