Hi-
I'm new to working with FileTables and am wondering if the following code (which saves annotations to a PDF file in the FileTable with changes that are made through the PDF control) makes sense. My save results are mixed while using the PDF control, depending
upon the PDF file that is loaded. If a save is successful, the PDF control will load the PDF file with the annoatations, but the PDF file will not open in Adobe Acrobat (file corruption error is reported).
When using the provided PDFTron sample PDF control project with a file loaded from the file system, no errors are reported when saving annotations to the PDF file, and the changes can be viewed using Adobe Acrobat.
I'm wondering whether my code is generally appropriate, or if I'm going about this all wrong.
'Create a connection to the database Dim ConStr As String ConStr = MyAppConnString Dim con As New SqlConnection(ConStr) con.Open() Dim sqlCommand As New SqlCommand() ' Set Command text to stored procedure name With sqlCommand sqlCommand.Parameters.Clear() .CommandText = "RetrieveDocument" ' Set the command type to Stored procedure .CommandType = CommandType.StoredProcedure ' Add parameter/s to the command. Depends on the Stored procedure .Parameters.Add("@SelectedNode", SqlDbType.NVarChar, 128).Value = myTag 'add the conection to the command .Connection = con End With Dim filePath As String = CStr(sqlCommand.ExecuteScalar()) 'Obtain a Transaction Context Dim transaction As SqlTransaction = con.BeginTransaction("ItemTran") sqlCommand.Transaction = transaction ' Set Command text to stored procedure name With sqlCommand sqlCommand.Parameters.Clear() .CommandText = "tContext" ' Set the command type to Stored procedure .CommandType = CommandType.StoredProcedure .Connection = con End With Dim txContext As Byte() = CType(sqlCommand.ExecuteScalar(), Byte()) 'Open and read file using SqlFileStream Class Dim sqlFileStream As New SqlTypes.SqlFileStream(filePath, txContext, FileAccess.ReadWrite) Dim buffer As Byte() = New Byte(CInt(sqlFileStream.Length)) {} 'Bind the image data to an image control Dim ms As MemoryStream = New MemoryStream(buffer) _pdfdoc.Lock() Try _pdfdoc.Save(ms, SDF.SDFDoc.SaveOptions.e_incremental) Catch ex As Exception MessageBox.Show(ex.ToString(), "Error during the Save") End Try _pdfdoc.Unlock() sqlFileStream.Write(buffer, 0, buffer.Length) 'Cleanup sqlFileStream.Close() sqlCommand.Transaction.Commit() con.Close()
Thank you,
Matt