Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.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# 如何在C语言中将word文档的字节数组转换为pdf文档的字节数组#_C#_Pdf_Stream_Crystal Reports 2010 - Fatal编程技术网

C# 如何在C语言中将word文档的字节数组转换为pdf文档的字节数组#

C# 如何在C语言中将word文档的字节数组转换为pdf文档的字节数组#,c#,pdf,stream,crystal-reports-2010,C#,Pdf,Stream,Crystal Reports 2010,我有一个从crystal report导出的字节序列,如下所示(Word格式) Stream stream = cryRpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.WordForWindows); 我想将该流转换为PDF流,以存储在sql server数据库的varbinary列中 文档中有条形码,我无法在导出为pdf时将其嵌入。但是导出到word很有效,所以我想尝试从word到PDF 有人能帮我获取这个PDF字节[]

我有一个从crystal report导出的字节序列,如下所示(Word格式)

 Stream stream = cryRpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.WordForWindows);
我想将该流转换为PDF流,以存储在sql server数据库的varbinary列中

文档中有条形码,我无法在导出为pdf时将其嵌入。但是导出到word很有效,所以我想尝试从word到PDF
有人能帮我获取这个PDF字节[]吗?

您可以使用。将其添加到应用程序后,您可以将字节数组刷新为临时文件,然后使用Interop.Word打开临时文件,使用它,保存结果并将结果读回字节数组

下面是一个示例代码段,它可以做到这一点:

// byte[] fileBytes = getFileBytesFromDB();
var tmpFile = Path.GetTempFileName();
File.WriteAllBytes(tmpFile, fileBytes);

Application app = new word.Application();
Document doc = app.Documents.Open(filePath);

// Save DOCX into a PDF
var pdfPath = "path-to-pdf-file.pdf";
doc.SaveAs2(pdfPath, word.WdSaveFormat.wdFormatPDF);

doc.Close();
app.Quit(); // VERY IMPORTANT: do this to close the MS Word instance
byte[] pdfFileBytes = File.ReadAllBytes(pdfPath);
File.Delete(tmpFile);

有关该主题的更多信息,您也可以在我的博客上找到。

您是否正在寻找:嗨,科拉克,不,我想通过编程实现,将word byte[]转换为pdf byte[]您必须将word文档转换为pdf文档(使用一些高级库),然后您可以读取此pdf文档/文件的字节。@CoDeGiRl,您可以通过将字节[]写入文件并使用Corak链接到的问题的答案来实现这一点。在不涉及Word本身的情况下将Word文档转换为PDF文档是非常重要的(简单地说)。DrKotch,当你说“必须将Word文档转换为PDF文档”时,你是指磁盘上的物理PDF文件吗?