Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Storing and Opening PDF file in .net from SAP-SPOOL


I have a problem in opening the pdf file using .net code from SAP-SPOOL .I am getting error as follows..

"There was a error in opening a document.The file is damaged and could not be repaired".

I am extracting data from SAP-SPOOL to .net environment using sap.connector with Rfc.In this rfc, I have to open a PDF file which is in a table format which contains two columns(tdformat,tdline).

Please help me out.Thanks in advance..

This is my code..

pdfproxy = New SAPProxy1(cs)


pdfproxy.Z_Rfc_Po_Pdf_Create( strpurchaseorder, bytecount, pdft)


Dim ds As DataSet = New DataSet


Dim sb As StringBuilder = New StringBuilder

For Each dr As DataRow In ds.Tables(0).Rows

Dim dataline As String = dr(0) & dr(1)

If dataline.Length < 134 Then

dataline = dataline.PadRight(134, " ")

End If



Dim pdf As String = sb.ToString

Dim context As System.Web.HttpContext

context = System.Web.HttpContext.Current

Dim response As System.Web.HttpResponse

response = context.Response

Dim pdfLength = pdf.Length

' create name for PDF

Dim pdfBytes() As Byte = encoding.GetBytes(pdf.ToCharArray(), 0, pdfLength)


response.ContentType = "application/Pdf"

response.AppendHeader("content-disposition", "attachment; filename=" + strfilename)

response.OutputStream.Write(pdfBytes, 0, pdfLength)


response.SuppressContent = True


Former Member
Not what you were looking for? View more on this topic or Ask a question