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 :
Customer experience | Sales, Customer Insights,...
Answered

Convert Word document attached with note to PDF.

(0) ShareShare
ReportReport
Posted on by 44

HI, 

I need your help. I want to convert word document attached with note into PDF and send it to customer. I have retrieved note attachment with invoice entity, but unable to convert it into PDF. 

Entity emailCreated = service.Retrieve("email", SourceEmailID, new ColumnSet(true));
QueryExpression QueryNotes = new QueryExpression("annotation");
QueryNotes.ColumnSet = new ColumnSet(new string[] { "subject", "mimetype", "filename", "documentbody" });
QueryNotes.Criteria = new FilterExpression();
QueryNotes.Criteria.FilterOperator = LogicalOperator.And;
QueryNotes.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, invoiceID.Id));
EntityCollection MimeCollection = service.RetrieveMultiple(QueryNotes);
if (MimeCollection.Entities.Count > 0)
{ //we need to fetch first attachment
Entity NotesAttachment = MimeCollection.Entities.First();
//Create email attachment
Entity EmailAttachment = new Entity("activitymimeattachment");
if (NotesAttachment.Contains("subject"))
EmailAttachment["subject"] = NotesAttachment.GetAttributeValue<string>("subject");
EmailAttachment["objectid"] = new EntityReference("email", emailCreated.Id);
EmailAttachment["objecttypecode"] = "email";
if (NotesAttachment.Contains("filename"))
EmailAttachment["filename"] = NotesAttachment.GetAttributeValue<string>("filename");
if (NotesAttachment.Contains("documentbody"))
EmailAttachment["body"] = NotesAttachment.GetAttributeValue<string>("documentbody");
if (NotesAttachment.Contains("mimetype"))
EmailAttachment["mimetype"] = NotesAttachment.GetAttributeValue<string>("mimetype");

service.Create(EmailAttachment);
}
// Sending email
SendEmailRequest SendEmail = new SendEmailRequest();
SendEmail.EmailId = emailCreated.Id;
SendEmail.TrackingToken = "";
SendEmail.IssueSend = true;
SendEmailResponse res = (SendEmailResponse)service.Execute(SendEmail);

I have the same question (0)
  • Justinjose Profile Picture
    2,707 on at

    Hi Naeem Khan,

    Is this an external application or a plugin?

    Thanks

    Justin Jose

  • Naeem Khan  Profile Picture
    44 on at

    Hi Justin,

    It is a custom workflow.

    thanks,

  • Justinjose Profile Picture
    2,707 on at

    Hi Naeem Khan,

    are you using any library (References) to convert to pdf? I cant see PDF conversion step in the above code

    Thanks

    Justin Jose

  • Naeem Khan  Profile Picture
    44 on at

    Hi Justin,

    Right now i am using word2pdf library, but i don't know how to utilize it. As you can see code below. I don't how i could use it in my case as i am not loading word file from any path.  If you know any library which can be used, kindly share with me.

     Word2Pdf objWorPdf = new Word2Pdf();

                   string backfolder1 = "D:\\PDFFile";            

                   string strFileName = "Invoice.docx";

                   object FromLocation = backfolder1 + "\\" + strFileName;

                   string FileExtension = Path.GetExtension(strFileName);

                   string ChangeExtension = strFileName.Replace(FileExtension, ".pdf");

                   if (FileExtension == ".doc" || FileExtension == ".docx")

                   {

                       object ToLocation = backfolder1 + "\\" + ChangeExtension;

                       objWorPdf.InputLocation = FromLocation;

                       objWorPdf.OutputLocation = ToLocation;

                       objWorPdf.Word2PdfCOnversion();

                   }

    thanks,

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at

    Hi Naeem Khan,

    I dont think that the Word2Pdf reference will work on custom workflow or plugin.

    You can use Microsoft Flow to convert Word to Pdf. Here is an example -  dynamics365blocks.wordpress.com/.../

    Thanks

    Justin Jose

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Naeem,

    The challenge for us to build a custom workflow to do convert with Word2Pdf is that the library requires a local path to read doc file; 

    However, due to original content of doc note is binary data, we need to save note as local file, or the library could provide a function to convert binary data to PDF directly.

    It's highly recommended to achieve such requirement with Flow, which has following good reasons:

    * low code 

    * less time spent

    * easy to use

    Please take a look for the alternative flow:

    Overview:

    pastedimage1587351164773v1.png

    The process is:

    When a contact is selected(like on-demand workflow) -> find the first note file by contact id ->

    Create a temp file to save doc note in Onedrive -> Convert the temp file to PDF as binary data by "Convert file" action ->

    Send an email to selected contact, populate attachment content with converted PDF binary data ->

    delete the temp file when email is sent successfully

    pastedimage1587351457936v2.png

    Result presentation:

    p1:

    Original doc file

    pastedimage1587351504565v3.png

    p2:

    select a contact who has an attached note:

    pastedimage1587351590991v4.png

    p3:

    Delivered email with converted pdf

    pastedimage1587351657790v5.png

    p4:

    Converted file preview:

    pastedimage1587351712290v6.png

    Regards,

    Clofly

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 96 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans