Skip to main content

Notifications

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

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: I have base64string of word document and want to convert it into base64string of PDF

    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

  • Yadnyesh Kuvalekar Profile Picture
    4,102 on at
    RE: I have base64string of word document and want to convert it into base64string of PDF

    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
    RE: I have base64string of word document and want to convert it into base64string of PDF

    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

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans