Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c#环境中是否有免费的库可以不使用Microsoft.Office.Interop.Word将文档转换为pdf_C#_Pdf_Itext - Fatal编程技术网

在c#环境中是否有免费的库可以不使用Microsoft.Office.Interop.Word将文档转换为pdf

在c#环境中是否有免费的库可以不使用Microsoft.Office.Interop.Word将文档转换为pdf,c#,pdf,itext,C#,Pdf,Itext,我遇到了一个关于如何使用c#而不使用Microsoft.Office.Interop.Word将文档转换为pdf的问题。我尝试过一些第三方解决方案,比如spire.Doc,但它们不是免费的,而且我在nuget中找到了DocX_Doc,但似乎没有关于它的教程。有人知道这个问题的免费解决方案,或者关于DocX_Doc的任何说明吗。非常感谢。 对于DocX库,这里是一个如何从word转换为PDF的示例“免费” 您也可以检查此DLL 我使用SautinSoft.UseOffice来实现这一点,它简单易用

我遇到了一个关于如何使用c#而不使用Microsoft.Office.Interop.Word将文档转换为pdf的问题。我尝试过一些第三方解决方案,比如spire.Doc,但它们不是免费的,而且我在nuget中找到了DocX_Doc,但似乎没有关于它的教程。有人知道这个问题的免费解决方案,或者关于DocX_Doc的任何说明吗。非常感谢。

  • 对于DocX库,这里是一个如何从word转换为PDF的示例“免费”

  • 您也可以检查此DLL

  • 我使用SautinSoft.UseOffice来实现这一点,它简单易用,但成本约为350美元。以下是完整教程的链接:

“非免费”
  • 对于DocX库,这里是一个如何从word转换为PDF的示例“免费”

  • 您也可以检查此DLL

  • 我使用SautinSoft.UseOffice来实现这一点,它简单易用,但成本约为350美元。以下是完整教程的链接:


“非免费”

您可以使用apache 2.0下的libreOffice is Free许可证 我已经测试过了,它工作得很好,只是你需要下载soffice.exe文件来转换成pdf,你也可以将docx转换成图像和其他类型

下面是我测试的示例代码:

    static string getLibreOfficePath()
    {
        switch (Environment.OSVersion.Platform)
        {
            case PlatformID.Unix:
                return "/usr/bin/soffice";
            case PlatformID.Win32NT:
                string binaryDirectory = 
          System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                return @"C:\Program Files\LibreOffice\program\soffice.exe";
            default:
                throw new PlatformNotSupportedException("Your OS is not supported");
        }
    }

    static void Main(string[] args)
    {
        string libreOfficePath = getLibreOfficePath();

        ProcessStartInfo procStartInfo = new ProcessStartInfo(libreOfficePath, 
        string.Format("--convert-to pdf C:\\test.docx")); //test.docx => input path
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;
        procStartInfo.CreateNoWindow = true;
        procStartInfo.WorkingDirectory = Environment.CurrentDirectory;

        Process process = new Process() { StartInfo = procStartInfo, };
        process.Start();
        process.WaitForExit();

        // Check for failed exit code.
        if (process.ExitCode != 0)
        {
            throw new LibreOfficeFailedException(process.ExitCode);
        }
    }
我希望这对你有帮助。
谢谢。

您可以使用apache 2.0下的libreOffice是免费许可证 我已经测试过了,它工作得很好,只是你需要下载soffice.exe文件来转换成pdf,你也可以将docx转换成图像和其他类型

下面是我测试的示例代码:

    static string getLibreOfficePath()
    {
        switch (Environment.OSVersion.Platform)
        {
            case PlatformID.Unix:
                return "/usr/bin/soffice";
            case PlatformID.Win32NT:
                string binaryDirectory = 
          System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                return @"C:\Program Files\LibreOffice\program\soffice.exe";
            default:
                throw new PlatformNotSupportedException("Your OS is not supported");
        }
    }

    static void Main(string[] args)
    {
        string libreOfficePath = getLibreOfficePath();

        ProcessStartInfo procStartInfo = new ProcessStartInfo(libreOfficePath, 
        string.Format("--convert-to pdf C:\\test.docx")); //test.docx => input path
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;
        procStartInfo.CreateNoWindow = true;
        procStartInfo.WorkingDirectory = Environment.CurrentDirectory;

        Process process = new Process() { StartInfo = procStartInfo, };
        process.Start();
        process.WaitForExit();

        // Check for failed exit code.
        if (process.ExitCode != 0)
        {
            throw new LibreOfficeFailedException(process.ExitCode);
        }
    }
我希望这对你有帮助。
谢谢。

我看到的问题是要一个图书馆(这超出了SO的范围)。此外,我对C#中的pdf有一些经验,我相信没有一个像样的免费库可以做到这一点(ofc的“像样”取决于文档中实际包含的内容)。我看到的问题是需要一个库(这超出了SO的范围)。另外,我对C#中的pdf也有一些经验,我相信没有一个像样的免费库可以做到这一点(ofc的“像样”取决于文档中的实际内容)。您引用的链接使用Interop:DocX似乎无法转换为pdf,只有付费版本才支持创建PDF文件…从外观上看,DocX对于PDF转换不是免费的it@AltF4当时它是免费的:)可惜我错过了这个机会,你知道现在有其他免费的吗?你引用的链接使用Interop:DocX似乎无法转换为PDF,只有付费版本才支持创建PDF文件…从外观上看,DocX对于PDF转换不是免费的it@AltF4当时它是免费的:)可惜我错过了这个机会,你知道现在有什么可以免费的选择吗?