Invalid pdf format:pdf head signature is not found

Hi, i'm testing then Aspose Pdf.kit to evaluate the purchase of a license.

I have an aplication that uses pdf files and stores it in a SQL server table, I use a filestream to retrieve the documents from the database but I can't open it with the Aspose pdf kit. Can you give some tips to solve this problem??

Thanks!!!!

Here is the code I'm using for test:

Dim Archivo As Byte()

Dim Informes As DataSet

Dim Comando As SqlCommand

Dim Reader As SqlDataAdapter

comando = New SqlCommand()

Comando.Connection = Me.Conexion

Comando.CommandType = CommandType.Text

Comando.CommandText = "select * from blob where codigoacta = 1"

Reader = New SqlDataAdapter(Comando)

Informes = New DataSet

Reader.Fill(Informes)

ReDim Archivo(CType(Informes.Tables(0).Rows(0)("documento"), Byte()).Length)

Archivo = CType(Informes.Tables(0).Rows(0)("documento"), Byte())

Dim oFileStream As System.IO.FileStream

oFileStream = New System.IO.FileStream("test.pdf", System.IO.FileMode.Create, IO.FileAccess.ReadWrite)

oFileStream.Write(Archivo, 0, Archivo.Length)

Dim fileInfo As PdfFileInfo = New PdfFileInfo(oFileStream) (the error is here)

Dim height As Single = fileInfo.GetPageHeight(1)

Dim width As Single = fileInfo.GetPageWidth(1)

Dim rotation As Integer = fileInfo.GetPageRotation(1)

oFileStream.Close()

Hi Hector,

Thank you very much for considering Aspose.

The code you have provided is to read the contents from the PDF; the problem might be with the code which writes the contents to the database. Please share the code which performs the first function i.e. writing code to the database. So, we could see how that part is being done at your end. Also, please share the PDF file you’re having problem with. In addition to that, I would also request you to mention the detailed error description for this exception.

We’re sorry for the inconvenience.
Regards,

Hi, here is the code to write the file to the DB, it works fine, I can open it from my application, the error occurs when I try to open with the aspose.

Thanks.

Dim File As HttpPostedFile
Dim pp As New SAO_dat.ABMTablas
Dim Largo As Integer
Dim Archivo As Byte()
Dim Conexion As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand

File = txtFile.PostedFile
Largo = File.ContentLength
ReDim Archivo(Largo)
File.InputStream.Read(Archivo, 0, Largo)


Conexion = New SqlClient.SqlConnection
Conexion.ConnectionString = oDBA.getConexionString()
Conexion.Open()


cmd = New SqlClient.SqlCommand("Insert into blob values(2,@Content)", Conexion)
cmd.CommandType = CommandType.Text
cmd.Parameters.Add(New SqlClient.SqlParameter("@Content", Archivo))
cmd.ExecuteNonQuery()
Conexion.Close()

Hi Hector,

I have investigated the issue at my end in detail and found that if you add the following line of code before reading the file stream into the PdfFileInfo object, you should be able to read the properties:


oFileStream.Seek(0, SeekOrigin.Begin)



I hope this helps. If you have any other questions, or find some issues please do let us know.
Regards,

It works!!!

I will continue testing

Thanks for you support.

Regards.