Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private readonly string ApiKey = "YourApiKey";
- private async void ConvertionDocx2Pdf(string docFilePath, string filePathPdf)
- {
- var fileToConvert = docFilePath;
- using (var client = new HttpClient())
- {
- using (var content = new MultipartFormDataContent())
- {
- StreamContent streamContent;
- using (FileStream fs = File.OpenRead(docFilePath))
- {
- streamContent = new StreamContent(fs);
- var fileContent = new ByteArrayContent(streamContent.ReadAsByteArrayAsync().Result);
- fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
- content.Add(fileContent, "File", Path.GetFileName(docFilePath));
- }
- using (
- var message =
- await client.PostAsync(string.Format("http://do.convertapi.com/word2pdf?ApiKey={0}",ApiKey), content))
- {
- var input = await message.Content.ReadAsByteArrayAsync();
- var path = Path.Combine(filePathPdf);
- File.WriteAllBytes(path, input);
- Debug.WriteLine("The conversion was successful! The word file {0} converted to PDF and saved at {1}", fileToConvert, path);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement