Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. private readonly string ApiKey = "YourApiKey";
  2.  
  3. private async void ConvertionDocx2Pdf(string docFilePath, string filePathPdf)
  4. {
  5. var fileToConvert = docFilePath;
  6. using (var client = new HttpClient())
  7. {
  8. using (var content = new MultipartFormDataContent())
  9. {
  10. StreamContent streamContent;
  11. using (FileStream fs = File.OpenRead(docFilePath))
  12. {
  13. streamContent = new StreamContent(fs);
  14. var fileContent = new ByteArrayContent(streamContent.ReadAsByteArrayAsync().Result);
  15. fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
  16. content.Add(fileContent, "File", Path.GetFileName(docFilePath));
  17. }
  18.  
  19. using (
  20. var message =
  21. await client.PostAsync(string.Format("http://do.convertapi.com/word2pdf?ApiKey={0}",ApiKey), content))
  22. {
  23. var input = await message.Content.ReadAsByteArrayAsync();
  24. var path = Path.Combine(filePathPdf);
  25. File.WriteAllBytes(path, input);
  26. Debug.WriteLine("The conversion was successful! The word file {0} converted to PDF and saved at {1}", fileToConvert, path);
  27. }
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement