Converts array of image bytes to PDF file

Namespace:  SautinSoft
Assembly:  SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 5.3.6.5

Syntax

      
 C#  Visual Basic 
public int ConvertImageStreamToPDFFile(
	byte[] bImage,
	string outputPdfFile
)
Public Function ConvertImageStreamToPDFFile ( _
	bImage As Byte(), _
	outputPdfFile As String _
) As Integer

Parameters

bImage
array< Byte >[]()[]
Array of image bytes
outputPdfFile
String
Local path to output PDF file

Return Value

0 - converting successfully
1 - can't open input file, check the input path
2 - can't create output file, check the output path
3 - converting failed

Remarks



Examples

CopyHow to convert Image class to PDF file in C#
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 img = Image.FromFile(@"..\..\image1.jpg");
            FileInfo pdfFile = new FileInfo(@"copy.pdf");

            byte[] imgBytes = null;

            using (MemoryStream ms = new System.IO.MemoryStream())
            {
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                imgBytes = ms.ToArray();
            }

            // Convert image stream to PDF file
            int ret = v.ConvertImageStreamToPDFFile(imgBytes, pdfFile.FullName);
            if (ret == 0)
            {
             // Open produced PDF in default PDF Viewer.
             System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile.FullName) { UseShellExecute = true });
            }
        }
    }
}
CopyHow to convert Image class to PDF file in VB.Net
Imports System.IO

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 img As System.Drawing.Image = Image.FromFile("..\..\image1.jpg")
            Dim pdfFile As New FileInfo("copy.pdf")

            Dim imgBytes() As Byte = Nothing

            Using ms As MemoryStream = New System.IO.MemoryStream()
                img.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, pdfFile.FullName)
            If ret = 0 Then
                ' Open produced PDF in default PDF Viewer.
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfFile.FullName) With {.UseShellExecute = True})
            End If
        End Sub
    End Class
End Namespace

See Also