【问题标题】:ConvertApi NuGet Package Error: Could not install package 'ConvertApi 2.7.0'ConvertApi NuGet 包错误:无法安装包“ConvertApi 2.7.0”
【发布时间】:2019-07-09 13:29:24
【问题描述】:

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

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

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

【问题讨论】:

  • 您需要在.NET 4.7 中运行.NET Core 2 版本库。
  • 那么您能否分享对我可以在我的 .net 4.6 项目中使用的库的引用。我猜它在 Nuget 包中不可用。

标签: convertapi


【解决方案1】:

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());
              }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-24
    • 2019-04-15
    • 2014-02-15
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多