web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Suggested answer
    Jaakko Y. Profile Picture
    4 on at
    Email attachment - corrupt random pdfs
    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
  • Suggested answer
    Kamal Khakhkhar Profile Picture
    1,202 on at
    Email attachment - corrupt random pdfs
    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
  • Jaakko Y. Profile Picture
    4 on at
    Email attachment - corrupt random pdfs
    Hi,
     
    I would also be interested in hearing about the resolution as we are also facing the same issue. :) 

    Br, Jaakko
  • Community member Profile Picture
    6 on at
    Email attachment - corrupt random pdfs
    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.
  • G_ABC Profile Picture
    2 on at
    Email attachment - corrupt random pdfs
    Hi, 

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

    KR
  • ShanAbeywicrema Profile Picture
    948 on at
    RE: Email attachment - corrupt random pdfs

    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.

  • Verified answer
    Nitin Verma Profile Picture
    21,666 Moderator on at
    RE: Email attachment - corrupt random pdfs

    Hi,

    Try to use below link for attachment

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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 3,878

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,390

#3
Sumit Singh Profile Picture

Sumit Singh 2,884

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans