我有一份pdf文件,我正在填写iTextSharp。我可以加载我的文档,用sql查询的结果填入字段,然后输出到选项卡式浏览器窗口。
我想将文档保存到服务器上的某个位置,以便可以在客户屏幕上加载该文档的物理副本, 我不能为我的生活找出如何将相同的数据输出到服务器上保存的位置。我尝试了不同的谷歌搜索结果,但我甚至没有关闭,我可能对这个过程没有正确的理解。
这是我目前的代码:
Dim mapPath As String = Server.MapPath("~/Content/PDF/Standard_HD.pdf")
Dim reader As New PdfReader(mapPath)
Dim output = New MemoryStream()
Dim stamper = New PdfStamper(reader, output, "\0", True)
'LOAD UNIT DETAILS FROM DATABASE
makeSQLceConnection()
sqlCmd = New SqlCommand("EXEC dbo.[web_wizardSheetPDF] @wizardID= '" & guid & "'")
sqlCmd.Connection = myCon
sqlReader = sqlCmd.ExecuteReader
Dim rowNumber As Integer = 1
Dim headerText As String = Nothing
Dim controlText As String = Nothing
While sqlReader.Read()
headerText = sqlReader(14).ToString
stamper.AcroFields.SetField("BoxColor", sqlReader(12).ToString)
stamper.AcroFields.SetField("HardwareColor", sqlReader(13).ToString)
Select Case rowNumber
Case = 1
stamper.AcroFields.SetField("Unit1", rowNumber)
stamper.AcroFields.SetField("TopBack1", sqlReader(6).ToString)
stamper.AcroFields.SetField("FrontBottom1", sqlReader(7).ToString)
stamper.AcroFields.SetField("Handing1", sqlReader(8).ToString)
stamper.AcroFields.SetField("Operation1", sqlReader(9).ToString)
stamper.AcroFields.SetField("Slat1", sqlReader(10).ToString)
stamper.AcroFields.SetField("Tracks1", sqlReader(11).ToString)
Case = 2
stamper.AcroFields.SetField("Unit2", rowNumber)
stamper.AcroFields.SetField("TopBack2", sqlReader(6).ToString)
stamper.AcroFields.SetField("FrontBottom2", sqlReader(7).ToString)
stamper.AcroFields.SetField("Handing2", sqlReader(8).ToString)
stamper.AcroFields.SetField("Operation2", sqlReader(9).ToString)
stamper.AcroFields.SetField("Slat2", sqlReader(10).ToString)
stamper.AcroFields.SetField("Tracks2", sqlReader(11).ToString)
Case = 3
stamper.AcroFields.SetField("Unit3", rowNumber)
stamper.AcroFields.SetField("TopBack3", sqlReader(6).ToString)
stamper.AcroFields.SetField("FrontBottom3", sqlReader(7).ToString)
stamper.AcroFields.SetField("Handing3", sqlReader(8).ToString)
stamper.AcroFields.SetField("Operation3", sqlReader(9).ToString)
stamper.AcroFields.SetField("Slat3", sqlReader(10).ToString)
stamper.AcroFields.SetField("Tracks3", sqlReader(11).ToString)
Case = 4
stamper.AcroFields.SetField("Unit4", rowNumber)
stamper.AcroFields.SetField("TopBack4", sqlReader(6).ToString)
stamper.AcroFields.SetField("FrontBottom4", sqlReader(7).ToString)
stamper.AcroFields.SetField("Handing4", sqlReader(8).ToString)
stamper.AcroFields.SetField("Operation4", sqlReader(9).ToString)
stamper.AcroFields.SetField("Slat4", sqlReader(10).ToString)
stamper.AcroFields.SetField("Tracks4", sqlReader(11).ToString)
Case = 5
stamper.AcroFields.SetField("Unit5", rowNumber)
stamper.AcroFields.SetField("TopBack5", sqlReader(6).ToString)
stamper.AcroFields.SetField("FrontBottom5", sqlReader(7).ToString)
stamper.AcroFields.SetField("Handing5", sqlReader(8).ToString)
stamper.AcroFields.SetField("Operation5", sqlReader(9).ToString)
stamper.AcroFields.SetField("Slat5", sqlReader(10).ToString)
stamper.AcroFields.SetField("Tracks5", sqlReader(11).ToString)
Case = 6
stamper.AcroFields.SetField("Unit6", rowNumber)
stamper.AcroFields.SetField("TopBack6", sqlReader(6).ToString)
stamper.AcroFields.SetField("FrontBottom6", sqlReader(7).ToString)
stamper.AcroFields.SetField("Handing6", sqlReader(8).ToString)
stamper.AcroFields.SetField("Operation6", sqlReader(9).ToString)
stamper.AcroFields.SetField("Slat6", sqlReader(10).ToString)
stamper.AcroFields.SetField("Tracks6", sqlReader(11).ToString)
End Select
rowNumber += 1
End While
stamper.AcroFields.SetField("MotorsControls", controlText)
stamper.AcroFields.SetField("Header", headerText)
sqlReader.Close()
myCon.Close()
closeSQLceConnection()
'close the stamper after we our done
stamper.FormFlattening = False
stamper.Close()
reader.Close()
'send completed pdf to browser
Response.AddHeader("Content-Disposition", "inline; filename=SWSC_DOC_PDF.pdf")
Response.ContentType = "application/pdf"
Response.BinaryWrite(output.ToArray())
'File.WriteAllBytes(Server.MapPath("~/Test"),output.ToArray())
Response.[End]()
我为没有任何我迄今为止尝试过的例子而道歉,他们甚至令人尴尬地离开了。