使用Aspose.Pdf将MemoryStream转换为PDF

Aspose.Pdf可以将不同来源的图像转换为Pdf格式。这些图像包括硬盘特定位置的图像,MemoryStream图像或来源于网络上的图像。

//Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Add a section into the pdf document
Aspose.Pdf.Generator.Section sec = pdf1.Sections.Add();

// Create a FileStream object to read the imag file
FileStream fs = File.OpenRead(@"d:\pdftest\Aspose.jpg");
// Read the image into Byte array
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);

// Create a MemoryStream object from image Byte array
MemoryStream ms = new MemoryStream(data);
//Create an image object in the section
Aspose.Pdf.Generator.Image imageht = new Aspose.Pdf.Generator.Image(sec);
//Set the type of image using ImageFileType enumeration
imageht.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

// Specify the image source as MemoryStream
imageht.ImageInfo.ImageStream = ms;
//Add image object into the Paragraphs collection of the section
sec.Paragraphs.Add(imageht);

//Save the Pdf
pdf1.Save("d:/pdftest/Image_From_MemoryStream.pdf");
// Close the MemoryStream Object
ms.Close();

地址:http://my.oschina.net/u/876556/blog/100621
Aspose.Pdf是一个PDF文档创建组件,用户无需使用Adobe Acrobat 即可读写和操作PDF文件。分享Aspose.Pdf使用教程:

使用Aspose.Pdf处理现有的水印

使用Aspose.PDF更改PDF文件的内容

使用Aspose.Pdf在PDF文件中调整文本

使用Aspose.Pdf处理XML文档生成PDF文件

使用Aspose.Pdf将MemoryStream转换为PDF

使用Aspose.Pdf在HTML到PDF的转换过程中删除超链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值