使用C#将byte []转换为Pdf

时间:2015-04-16 02:56:33

标签: c# pdf pdf-generation bytearray

如何将byte [](源文件为word)值写入pdf。

以下是我正在使用的代码。

FtpWebRequest reqFTP;

strPath="ftp://1.1.1.1/Docs/word.doc";
strFileName="output.doc";
FileStream outputStream = new FileStream("C:/folder/" + Session.SessionID + "/" + strFileName, FileMode.Create);


reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strPath));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;


reqFTP.Credentials = new NetworkCredential(strUname, strPassword);
reqFTP.Proxy = null;

FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();

Stream ftpStream = response.GetResponseStream();


strExt = strFileName.Split('.');



long cl = response.ContentLength;
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
    outputStream.Write(buffer, 0, readCount);
    readCount = ftpStream.Read(buffer, 0, bufferSize);
}

ftpStream.Close();
outputStream.Close();
response.Close();

byte []源来自FtpWebRequest.GetResponseStream()源是word文件。如何将byte []写入pdf文件。

我已尝试过此链接Byte[] to Pdf中提到的方式,但是当我尝试打开它显示的pdf时(Adobe阅读器无法打开。因为它不是受支持的文件类型,或者因为文件已被删除damanged(例如,它是作为电子邮件附件发送的,并没有被正确解码)。)

谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用第三方组件进行操作。喜欢Aspose.Words。它可以简单地为你做这项工作。

相关问题