Как конвертировать System.Drawing.Image класс в PDF файл на C# и .NET
Полный код
using System;
using System.IO;
using System.Drawing;
namespace Sample
{
class Test
{
static void Main(string[] args)
{
// Convert Image class to PDF file
SautinSoft.PdfVision v = new SautinSoft.PdfVision();
//v.Serial = "XXXXXXXXXXXXXXX";
//specify converting options
v.PageStyle.PageSize.Auto();
//v.PageStyle.PageMarginLeft.Inch(1);
//v.ImageStyle.Heightmm(150);
//v.ImageStyle.WidthInch(10);
// Create object of Image class from file
System.Drawing.Image image = Image.FromFile(@"..\..\image-jpeg.jpg");
FileInfo outFile = new FileInfo(@"Result.pdf");
byte[] imgBytes = null;
using (MemoryStream ms = new System.IO.MemoryStream())
{
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
imgBytes = ms.ToArray();
}
// Convert image stream to PDF file
int ret = v.ConvertImageStreamToPDFFile(imgBytes, outFile.FullName);
if (ret == 0)
{
// Open the resulting PDF document in a default PDF Viewer.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName) { UseShellExecute = true });
}
}
}
}
Imports System
Imports System.IO
Imports System.Drawing
Namespace Sample
Friend Class Test
Shared Sub Main(ByVal args() As String)
' Convert Image class to PDF file
Dim v As New SautinSoft.PdfVision()
'v.Serial = "XXXXXXXXXXXXXXX"
'specify converting options
v.PageStyle.PageSize.Auto()
'v.PageStyle.PageMarginLeft.Inch(1);
'v.ImageStyle.Heightmm(150);
'v.ImageStyle.WidthInch(10);
' Create object of Image class from file
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile("..\..\image-jpeg.jpg")
Dim outFile As New FileInfo("Result.pdf")
Dim imgBytes() As Byte = Nothing
Using ms As MemoryStream = New System.IO.MemoryStream()
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
imgBytes = ms.ToArray()
End Using
' Convert image stream to PDF file
Dim ret As Integer = v.ConvertImageStreamToPDFFile(imgBytes, outFile.FullName)
If ret = 0 Then
' Open the resulting PDF document in a default PDF Viewer.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile.FullName) With {.UseShellExecute = True})
End If
End Sub
End Class
End Namespace
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: