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 :
Microsoft Dynamics CRM (Archived)

I have base64string of word document and want to convert it into base64string of PDF

(0) ShareShare
ReportReport
Posted on by 4,102

I have base64string of word document and want to convert it into base64string of PDF.

How can I do this?

Main goal: I have word document attached in notes. I want to convert it into pdf and attach in email using code.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Yadnyesh,

    Please try the below code:

    Step 1 is converting from your base64 string to a byte array:

    byte[] bytes = Convert.FromBase64String(base64BinaryStr);

    Step 2 is saving the byte array to disk:

    System.IO.FileStream stream = 
        new FileStream(@"C:\file.pdf", FileMode.CreateNew);
    System.IO.BinaryWriter writer = 
        new BinaryWriter(stream);
    writer.Write(bytes, 0, bytes.Length);
    writer.Close();

    And attach the converted pdf to the mail as an attachment.

    Note:
    If step 2 is not suitable for you.

    Please use memory stream to convert word to pdf without saving in local machine.

    Regards
    Dhandapani

    Please mark the answer as Verified, If it helps you
  • Yadnyesh Kuvalekar Profile Picture
    4,102 on at

    Thank you for your response. Step 2 is not suitable for me. Can you let me know how can I use memory stream to convert Word doc into PDF? Also, it will be the code in plugin.

  • Suggested answer
    Community Member Profile Picture
    on at

    Try this below code :

    //Read the document file using SemoryStream.

    byte[] filecontent= convert.frombase64string("your doucment body");

    MemoryStream memorystream= new MemoryStream (filecontent);
    memorystream.position=0;

    //Optional - use it based on your requirement
    using var reader=StreamReader(memorystream,Encoding.ASCII))
    {
    string line;
    line = reader.ReadLine();
    }

    then you can convert that content into PDF.

    Regards,

    Dhandapani

    Please mark the answer as verified, if it helps you

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans