彩票走势图

使用Aspose.Pdf将MemoryStream转换为PDF

原创|其它|编辑:郝浩|2012-11-15 09:51:20.000|阅读 1344 次

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

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

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

C#

//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();

VB.NET

'Instantiate Pdf instance by calling its empty constructor
Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
'Add a section into the pdf document
Dim sec As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()

' Create a FileStream object to read the imag file
Dim fs As FileStream = File.OpenRead("d:\pdftest\Aspose.jpg")
' Read the image into Byte array
Dim data(fs.Length - 1) As Byte
fs.Read(data, 0, data.Length)

' Create a MemoryStream object from image Byte array
Dim ms As MemoryStream = New MemoryStream(data)
'Create an image object in the section 
Dim imageht As Aspose.Pdf.Generator.Image = 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()
 


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP