原創|其它|編輯:郝浩|2012-11-15 09:51:20.000|閱讀 1389 次
概述: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@fc6vip.cn
文章轉載自:慧都控件網