473,440 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,440 software developers and data experts.

varbinary(max) to pdf in vb.net

Hello,

I wanted code to convert the varbinry to pdf and save it on Clients machine.
Can anyone help me ??
Oct 7 '09 #1
4 20213
Plater
7,872 Expert 4TB
Well varbinary should return a byte array. Assuming it was populated correctly, you can save the byte array as a file and give it a .pdf extension.
Oct 7 '09 #2
ssnaik84
149 100+
check iTextSharp Library tutorial.
you just have to send binary data to PdfWriter object and set some properties.
Oct 8 '09 #3
ssnaik84
149 100+
wait.. If you are developing web application, you dont need even that.
you just have to
Expand|Select|Wrap|Line Numbers
  1. Response.ContentType = "application/pdf"
Oct 8 '09 #4
First of all Thanks both of you.
I got the solution.Actually my senario was ,I had stored the pdf in SQL SEVER 2005 as varbinary(max) type and I wanted to retriew the pdf back.
Solution for this is as below :
In web we can use Response Content type as said by ssnaik .I have found the following solution.

in vb6
----------
Private Sub ByteArrayToPDFConverter_Click()

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mstream As ADODB.Stream

Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=test;Initial Catalog=test;User Id=_test;Password=test"

Set rs = New ADODB.Recordset
rs.Open "Select document from tbltest where id = 13", cn, adOpenKeyset, adLockOptimistic
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields("document").Value
mstream.SaveToFile "c:\ByteTopdf.pdf", adSaveCreateOverWrite


rs.Close
cn.Close
--------------------------------------------------------------------------------
in c# for web application
--------
while (reader.Read())
{
bFileData = (byte[])reader["doc"];
Response.BufferOutput = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=" + file.Name);
//Response.AddHeader("content-disposition", "attachment;filename=Test.pdf");
Response.BinaryWrite(bFileData);
Response.Flush();
Response.End();
}

and using Filestream
--------------------------------
bFileData = (byte[])reader["doc"];

using (FileStream stream = File.Open("C:\\file.pdf", FileMode.Create))
{
stream.Write(bFileData, 0, bFileData.Length);
}
-----------------
in vb.net
------------------
Private Sub SqlBlob2File(ByVal DocName As String)

Dim cn As New SqlConnection(My.Settings.DocStoreConnectionString .ToString())
Dim cmd As New SqlCommand("Select DocData From Documents WHERE DocName = @DocName", cn)

cmd.Parameters.AddWithValue("@DocName", DocName)

cn.Open()

Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read() Then
Dim fs As IO.FileStream = New IO.FileStream(IO.Path.Combine(Me.FolderBrowserDial og1.SelectedPath, DocName), IO.FileMode.Create)
Dim b() As Byte = dr.Item("DocData")
fs.Write(b, 0, b.Length)
fs.Close()
End If
End Using 'dr

cn.Close()

Best Regards
Sona
Oct 8 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bill Nguyen | last post by:
I need sample code to insert binary file (mappoint map file) into a varbinary column using VB.NET. Please help! Thanks Bill
5
by: =?Utf-8?B?ZHZhcm1h?= | last post by:
Hi I am executing a Sql Server SP from my C# app One of the parameters is of type varbinary. Since the content length of this parameter is variable I cannot set it to a pre-defined length. What...
1
by: Karch | last post by:
I am doing some experimenting with serialization (for use with Service Broker) and I am having a problem converting from a .NET DateTime (in the client application) to a SqlDbType.VarBinary (as...
7
by: gsauns | last post by:
Not sure if this is belongs here, or maybe in SQL... I have a SQL Server 2005 database where I store a varbinary(MAX) field. In my Web form, I allow the user to upload a photo to the database....
2
by: tindersticks | last post by:
Hi Can someone please post the simplest script that will allow an asp page read and write to/from m a MS SQL varbinary(max) field. ie image or doc/pdf etc is converted to relevant format and...
1
by: Gilad | last post by:
Hi I moved to SQL Server 2005 (from 2000) and noticed there is a better variable to deal with binary arrays. I hava a table that hold 9 columns of images (BLOB). each array has a different size...
4
by: Martin Horst | last post by:
Hi, I've got an application which is written in .Net 1.1. When I try to write a varbinary(max) field using the SqlCommand and SqlParameter classes I got an exception like this: "The...
1
by: quartrj | last post by:
For number of security reasons I can't use the Openrowset - Bulk option does any know of another way to load files into this data type.
1
by: quintonmartin | last post by:
Here's my problem. I have a client application that uses a web service for data access. I can read/update many records in many tables, however, I am not getting what I expect for a varbinary(max)...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.