Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Email attachment - corrupt random pdfs

(0) ShareShare
ReportReport
Posted on by 940

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, 

  • Suggested answer
    Jaakko Y. Profile Picture
    Jaakko Y. 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
    Kamal Khakhkhar 303 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
    Jaakko Y. 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
  • 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
    G_ABC 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
    ShanAbeywicrema 940 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
    Nitin Verma 21,091 Super User 2024 Season 1 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans