Converts array of image bytes to PDF byte array

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

Syntax

      
 C#  Visual Basic 
public byte[] ConvertImageStreamToPdfStream(
	byte[] bImage
)
Public Function ConvertImageStreamToPdfStream ( _
	bImage As Byte() _
) As Byte()

Parameters

bImage
array< Byte >[]()[]
Array of image bytes

Return Value

PDF document as byte array - in case of converting successfully
null - in case of converting failed

Remarks



Examples

CopyASP.Net - View TIFF as PDF in C#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Result.Text = "";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SautinSoft.PdfVision v  = new SautinSoft.PdfVision();

        byte[] tiffBytes = null;
        byte[] pdfBytes = null;

        if (FileUpload1.FileBytes.Length > 0)
        {
            //get bytes from image
            tiffBytes = FileUpload1.FileBytes;
        }
        else
            Result.Text = "Please select image file at first!";

        //convert image stream to pdf stream
        pdfBytes = v.ConvertImageStreamToPdfStream(tiffBytes);


        //show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            //Response.AddHeader("Content-Disposition:", "attachment; filename=Result.pdf");
            Response.AddHeader("Content-Disposition:", "inline; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }
}
CopyASP.Net - View TIFF as PDF in VB.Net
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Result.Text = ""
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim v As New SautinSoft.PdfVision()

        Dim tiffBytes() As Byte = Nothing
        Dim pdfBytes() As Byte = Nothing

        If FileUpload1.FileBytes.Length > 0 Then
            'get bytes from image
            tiffBytes = FileUpload1.FileBytes
        Else
            Result.Text = "Please select image file at first!"
        End If

        'convert image stream to pdf stream
        pdfBytes = v.ConvertImageStreamToPdfStream(tiffBytes)


        'show PDF
        If pdfBytes IsNot Nothing Then
            Response.Buffer = True
            Response.Clear()
            Response.ContentType = "application/PDF"
            'Response.AddHeader("Content-Disposition:", "attachment; filename=Result.pdf");
            Response.AddHeader("Content-Disposition:", "inline; filename=Result.pdf")
            Response.BinaryWrite(pdfBytes)
            Response.Flush()
            Response.End()
        Else
            Result.Text = "Converting failed!"
        End If
    End Sub
End Class

See Also