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的转换过程中删除超链接