ConvertApi NuGet软件包错误:无法安装软件包“ ConvertApi 2.7.0”

时间:2019-07-09 13:29:24

标签: convertapi

我正在添加ConvertApi nuget包以将PDF转换为Doc文件, 但是要低于错误

无法安装软件包“ ConvertApi 2.7.0”。您正在尝试将此软件包安装到以'.NETFramework,Version = v4.6.1'为目标的项目中,但是该软件包不包含任何与该框架兼容的程序集引用或内容文件。

注意: 您也可以建议其他一些API来完成上述任务。

1 个答案:

答案 0 :(得分:0)

ConvertApi 2.7.0 NuGet软件包是.NET Core 2版本库,可以安装在.NET 4.7 or higher上。但是,您可以使用普通的C#实现来调用ConvertAPI REST API,下面的示例使用WebClient发送MS Word文件以转换为PDF文档。

using System;
using System.Net;
using System.IO;

class MainClass {
  public static void Main (string[] args) {
            const string fileToConvert = "test.docx";
            const string fileToSave = "test.pdf";           
            const string Secret="";

            if (string.IsNullOrEmpty(Secret))
              Console.WriteLine("The secret is missing, get one for free at https://www.convertapi.com/a");
            else
              try
              {
                  Console.WriteLine("Please wait, converting!");
                  using (var client = new WebClient())
                  {
                      client.Headers.Add("accept", "application/octet-stream");
                      var resultFile = client.UploadFile(new Uri("http://v2.convertapi.com/convert/docx/to/pdf?Secret=" + Secret), fileToConvert); 
                      File.WriteAllBytes(fileToSave, resultFile );
                      Console.WriteLine("File converted successfully");
                  }
              }
              catch (WebException e)
              {
                  Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
                  Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
                  Console.WriteLine("Body : {0}", new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
              }
  }
}
相关问题