title: Error converting .docx with HTML to PDF using Graph API
body: <p>I am trying to convert MS Word (.docx) file to PDF format using Graph API. The file is stored in SharePoint Office 365. I am using below code which works.</p>
  <pre><code>var httpClient = await CreateAuthorizedHttpClient();
  string path = $&quot;{GraphEndpoint}sites/{SiteId}/drive/items/&quot;;
  string requestUrl = $&quot;{path}{fileId}/content?format={targetFormat}&quot;;
  var response = await httpClient.GetAsync(requestUrl);
  </code></pre>
  <p>However, when we try to convert .docx file which contains HTML added using below code converting fails.</p>
  <pre><code>string altChunkId = &quot;myId123&quot;;
  //Create an alternative format import part on the MainDocumentPart
  AlternativeFormatImportPart altformatImportPart = wordDoc.MainDocumentPart
      .AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, altChunkId);
  using (MemoryStream htmlMemoryStream = new MemoryStream(Encoding.UTF8.GetBytes($&quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;{value}&lt;/body&gt;&lt;/html&gt;&quot;)))
  {
      //Add the HTML data into the alternative format import part
      altformatImportPart.FeedData(htmlMemoryStream);
      //create a new altChunk and link it to the id of the AlternativeFormatImportPart
      AltChunk altChunk = new AltChunk();
      altChunk.Id = altChunkId;
      //p.InsertAfterSelf(altChunk);
      documentBody.Append(altChunk);
      break;
  }
  </code></pre>
  <p>I get 406 Not Acceptable error when we try to convert the file using Graph API. Also I see that the file is not editable in browser and open in compatibility mode. If I try to open the document in edit mode I get error:</p>
  <blockquote>
  <p>Sorry this document can't be opened because it contains objects that
  word doesn't support</p>
  </blockquote>
  <p>I tried removing the HTML part of the document and pasted that in another document and tried converting that document to PDF which worked. When I saw the XML of the document I saw Word App converted that HTML to word compatible XML tags.</p>
  <p><strong>Question 1:</strong> How can I convert the HTML to word compatible tags? So I can convert the document to PDF.</p>
  <p>Also if I try to Download as PDF, the file is converted to PDF without any issue.</p>
  <p><a href="https://i.stack.imgur.com/T3o0A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T3o0A.png" alt="Download as PDF" /></a></p>
  <p>This option is using below API call:</p>
  <blockquote>
  <p><a href="https://word-view.officeapps.live.com/wv/WordViewer/request.pdf?WOPIsrc=%7BSiteURL%7D%2F%5Fvti%5Fbin%2Fwopi%2Eashx%2Ffiles%2F%7BID%7D&amp;access_token=&amp;access_token_ttl=&amp;z=256&amp;type=downloadpdf" rel="nofollow noreferrer">https://word-view.officeapps.live.com/wv/WordViewer/request.pdf?WOPIsrc={SiteURL}%2F%5Fvti%5Fbin%2Fwopi%2Eashx%2Ffiles%2F{ID}&amp;access_token=&amp;access_token_ttl=&amp;z=256&amp;type=downloadpdf</a></p>
  </blockquote>
  <p><strong>Question 2:</strong> Is there a way I can use this API to convert .docx file to PDF? I saw the access token's audience value is &quot;wopi/{TenantName}@{TenantID}&quot;. If I get the correct access token I think I will be able to use the above API.</p>