Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

how to convert PDF from BLOB, and the same pdf needs to attached in document attachment for sales invoice

Posted on by 100

Hello Folks,

Greetings for the Day!

First of all thanks in Advance!

I need your help to get solution for converting a PDF file from a Base64 code and the same file I need to attach in posted sales invoice.

I have done the customization for store base64 code in a BLOB field, from where I need to convert it into PDF and the same need to attach in Document Attachment table.

during my investigation I got to know that we have Media type field in document attachment table for which I tried to use Base64 code conversion with BASE64 Convert codeunit with function FromBase64, which was not working out or might be I am missing something, I have used the TempBlob codeunit for doing the same, but the thing is somehow the PDF is loosing the format converted, becasue after attachment when I am getting open the same by downloading PDF file is giving error "Could not load the file format.

Could anyone help me in this regards. basically I wants to know is it possible to convert the Base64 into PDF and the same can be attach in Media type field.

any help will be appreciated. Thanks!

Below is code while attaching the file

procedure ConvertBase64toPDF(VAR RecpostedSalesInvoice: Record "Sales Invoice Header")
    var
        CUBase64Convert: Codeunit "Base64 Convert";
        CUtempBlob: Codeunit "Temp Blob";
        TempOStream: OutStream;
        TempInstream: InStream;
        recref: RecordRef;
        RecDocAttached: Record "Document Attachment";
        FileName: text;
        InvoiceData: Record "EInvoice Data"; //this is my custom table with Blob value
    begin
        IF invoiceData.Get(RecpostedSalesInvoice."No.") then BEGIN
            invoiceData.CalcFields(invoiceData.Blob);
            if InvoiceData.Blob.HasValue then begin
                CUTempBlob.CreateOutStream(TempOStream);
                CUTempBlob.FromRecord(invoiceData, invoiceData.FieldNo(Blob));
                CUtempBlob.CreateInStream(TempInstream);
                RecRef.GetTable(RecpostedSalesInvoice);
                FileName := StrSubstNo('E-Invoice_%1.PDF', RecpostedSalesInvoice."No.");
                if FileName <> '' then
                    RecDocAttached.SaveAttachmentFromStream(TempinStream, RecRef, FileName);
            end;
        end;
    end;
  • Netjacker2097 Profile Picture
    Netjacker2097 261 on at
    how to convert PDF from BLOB, and the same pdf needs to attached in document attachment for sales invoice
    Hi,
     
    just guessing here, try adding the after: if FileName <> '' then
     
                    RecDocAttached.INIT;
                    RecDocAttached."Table ID" := RecpostedSalesInvoice."Table ID";
                    RecDocAttached."No." := RecpostedSalesInvoice."No.";
                    RecDocAttached."File Name" := FileName;
                    RecDocAttached."Media Type" := 'application/pdf'; // Set the appropriate media type
                    RecDocAttached."Attachment" := TempInstream.Blob;
                    RecDocAttached."File Size" := LENGTH(TempInstream.Blob);
                    RecDocAttached."Date/Time" := CURRENTDATETIME;
                    RecDocAttached.INSERT;
     
    give it a try.
     
    Regards,
    M
  • Community member Profile Picture
    Community member 12 on at
    how to convert PDF from BLOB, and the same pdf needs to attached in document attachment for sales invoice
    Navigating the intricacies of converting a PDF from a BLOB for sales invoices led me to seek solutions. Thankfully, I found assistance at https://pdfflex.com/pptx-to-pdf, simplifying my pptx-to-pdf needs. Integrating the converted file seamlessly into document attachments streamlines the sales process, offering efficiency and precision. Grateful for this resource that eases the complexities of document management.

     
  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: how to convert PDF from BLOB, and the same pdf needs to attached in document attachment for sales invoice

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,908 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans