我正在开发一个使用iTextSharp和vb.net生成并打印PDF表单的应用程序。
PDF模板是一个四页组合文档。第一页是关于单个患者的报告,包含五个必填字段(标记为红色)。此信息将用于在页面底部自行生成PDF417条形码,以便为患者提供ID。 另外三页是针对该特定患者的不同检查的单独实验室提交表格。这些单据还包含第一页上这些必填字段的一些信息。这些字段会自动填充(我在这里感觉到一个javascript)。每个单据也会自行生成一个相关的条形码。
在收到并向患者披露实验室结果后,必须彻底填写第一页的其余字段。
在第一页上有一些相互依赖的下拉列表。它们不是级联的,但它们包含问题的答案,可能需要或可能不需要针对同一主题回答其他问题。我的意思是,有时我可以跳过基于之前关于同一主题的答案的问题。在其他一些情况下,必须回答这两个问题。
我成功地使用我的代码自动创建表单并填写了表单,但我特意与这些相互依赖的下拉列表进行了斗争。 通过将索引作为参数传递,我不会让框显示答案本身,而是显示数字索引。有些东西告诉我,当我使用iTextSharp填写表格而不是点击并选择时,可能会有一些布尔变量,一些我绕过的javascript。
结果,我得到一个无效的条形码是自生成的。 我试过传递答案本身(一个字符串)而不是索引。 它确实填写了正确的表格,但我最终得到了一个异常宽的条形码。 我相信条形码背后的脚本使用索引,而不是字段中的文本。在这一点上,我无法取得任何进展。
我的猜测是试图找出嵌入式代码到底是什么,并希望通过代码触发任何需要触发的事件,以使条形码正常工作。enter code here
任何帮助将非常感谢。
这是有问题的PDF以及我的代码。
请原谅我,如果它看起来不漂亮。我是vb.net的新手
提前致谢。
https://drive.google.com/open?id=0ByxujotstiajcTJPNkt4TW51V3M
函数GenerateForms()As Boolean
Dim pdfTemplate As String = DefaultPath + " \CTRForm.pdf"
Dim pdfReader As New PdfReader(pdfTemplate)
Dim pdfStamper As PdfStamper
Dim AuxOption As String
Dim OrderingInfo(2) As String
'ThisCTR = DefaultPath + "\CTR " + Form2.MetroDOC.Text
ThisCTR = My.Computer.FileSystem.SpecialDirectories.Desktop + "\CTR " + Form2.MetroDOC.Text
'********************** Check if a Folder for this CTR Session Exists
If Directory.Exists(ThisCTR) = False Then
Directory.CreateDirectory(ThisCTR)
End If
'*************************
newFile = ThisCTR
If Form2.MetroSiteID.SelectedIndex = 0 Then
newFile = newFile + "\01362_"
Else
newFile = newFile + "\01364_"
End If
newFile = newFile + FlipDate(Form2.MetroDOC.Text) + "_" + FlipDate(Form2.MetroDOB.Text)
Select Case Form2.MetroGender.SelectedIndex
Case 0
newFile = newFile + "_1_"
Case 1
newFile = newFile + "_2_"
Case 2
newFile = newFile + "_3_"
Case 3
newFile = newFile + "_4_"
Case 4
newFile = newFile + "_5_"
Case 5
newFile = newFile + "_6_"
End Select
newFile = newFile + Form2.MetroLblClientCode.Text + ".pdf"
Try
pdfStamper = New PdfStamper(pdfReader, New FileStream(newFile, FileMode.Create), "\DC", True) '\6c
' pdfStamper.Writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7)
Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
' Fill out PDF form fields
'jump to the end of the routine just for implementing purposes
' GoTo SkippingSomeCommands
Select Case Form2.MetroOrderingInfo.SelectedIndex
Case 0
OrderingInfo(0) = "SANTO"
OrderingInfo(1) = "ALVARO"
OrderingInfo(2) = "6176426213"
Case 1
OrderingInfo(0) = "PINTO"
OrderingInfo(1) = "ANDERSON"
OrderingInfo(2) = "61777870557"
Case 2
OrderingInfo(0) = "AMORIM"
OrderingInfo(1) = "CRISTIANO"
OrderingInfo(2) = "8579286831"
Case 3
OrderingInfo(0) = "RONCANCIO"
OrderingInfo(1) = "GABRIEL"
OrderingInfo(2) = "6178255897"
Case 4
OrderingInfo(0) = "KRIEGER"
OrderingInfo(1) = "MAGNA"
OrderingInfo(2) = "9789701250"
Case 5
OrderingInfo(0) = "DUARTE"
OrderingInfo(1) = "MURILLO"
OrderingInfo(2) = "6177642091"
End Select
AuxOption = ""
Select Case Form2.MetroInsurance.SelectedIndex
Case 0
AuxOption = "1" 'Aetna
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 1
AuxOption = "2" 'BCBSMA
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 2
AuxOption = "3" 'BMC Healthnet
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 3
AuxOption = "4" 'Celticare
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 4
AuxOption = "5" 'CIGNA
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 5
AuxOption = "6" 'Fallon
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 6
AuxOption = "7" 'Harvard Pilgrim
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 7
AuxOption = "8" 'Health New England
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 8
AuxOption = "9" 'MassHealth
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "1") 'MassHealth/Medicaid
Case 9
AuxOption = "10" 'Medicare
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "2")'Medicare
Case 10
AuxOption = "11" 'Neighborhood Health Plan
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 11
AuxOption = "12" 'Network Health
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 12
AuxOption = "13" 'Tufts
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 13
AuxOption = "14" 'Unicare
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "6")'Private Insurance
Case 14
AuxOption = "15" 'None
pdfFormFields.SetField("CTR_V41[0].Page1[0].insure_status[0]", "4") '4 = No Insurance
pdfFormFields.SetField("CTR_V41[0].Page1[0].no_insure[0]", "2") '2 = If No Insurance Did Receive assist.? = No
End Select
'Page 1
pdfFormFields.SetField("CTR_V41[0].Page1[0].sub_req[0]", "8") '8 selects HIV/HCV + CTGC + Syphilis
If Form2.MetroSiteID.SelectedIndex = 0 Then
pdfFormFields.SetField("CTR_V41[0].Page1[0].site[0]", "01362")
Else
pdfFormFields.SetField("CTR_V41[0].Page1[0].site[0]", "01364")
End If
pdfFormFields.SetField("CTR_V41[0].Page1[0].dt_sesn[0]", FilterNumbers(Form2.MetroDOC.Text))
pdfFormFields.SetField("CTR_V41[0].Page1[0].clientcode[0]", Form2.MetroLblClientCode.Text)
pdfFormFields.SetField("CTR_V41[0].Page1[0].dob[0]", FilterNumbers(Form2.MetroDOB.Text))
Select Case Form2.MetroGender.SelectedIndex
Case 0
pdfFormFields.SetField("CTR_V41[0].Page1[0].currentgender[0]", "1") '1= male
pdfFormFields.SetField("CTR_V41[0].Page1[0].birthsex[0]", "1")'1 = male
Case 1
pdfFormFields.SetField("CTR_V41[0].Page1[0].currentgender[0]", "2") '2= female
pdfFormFields.SetField("CTR_V41[0].Page1[0].birthsex[0]", "2")'1 = female
Case 2
pdfFormFields.SetField("CTR_V41[0].Page1[0].currentgender[0]", "3") '3 = trans m-f
pdfFormFields.SetField("CTR_V41[0].Page1[0].birthsex[0]", "1")'1 = male
Case 3
pdfFormFields.SetField("CTR_V41[0].Page1[0].currentgender[0]", "4") '4 = trans f-m
pdfFormFields.SetField("CTR_V41[0].Page1[0].birthsex[0]", "2")'1 = female
Case 4
pdfFormFields.SetField("CTR_V41[0].Page1[0].currentgender[0]", "5") '5 = trans Unspec.
pdfFormFields.SetField("CTR_V41[0].Page1[0].birthsex[0]", "3")'3 = declined
Case 5
pdfFormFields.SetField("CTR_V41[0].Page1[0].currentgender[0]", "6") '6 = declined
pdfFormFields.SetField("CTR_V41[0].Page1[0].birthsex[0]", "3")'3 = declined
Case 5
End Select
pdfFormFields.SetField("CTR_V41[0].Page1[0].state[0]", "MA")
pdfFormFields.SetField("CTR_V41[0].Page1[0].zip[0]", Form2.MetroZipCode.Text)
'pdfFormFields.SetField("CTR_V41[0].Page1[0].housing_status[0]", "Stably housed") 'housing status stably by default
'pdfFormFields.SetField("CTR_V41[0].Page1[0].election1[0]", "Tested confidentially") 'answers Tested Confidentially
'pdfFormFields.SetField("CTR_V41[0].Page1[0].dt_sample1[0]", FilterNumbers(Form2.MetroDOC.Text))
'pdfFormFields.SetField("CTR_V41[0].Page1[0].tech1[0]", "Serum") 'answers Serum by default
'pdfFormFields.SetField("CTR_V41[0].Page1[0].confirm1", "Yes") 'answers Serum specimen provided as yes by default
'pdfFormFields.SetField("CTR_V41[0].Page1[0].hav_vax[0]", "No") 'answers no as default but can be manually changed to previously vaccinated
'pdfFormFields.SetField("CTR_V41[0].Page1[0].hbv_vax[0]", "No")
'Page 2,
pdfFormFields.SetField("CTR_V41[0].Page2[0].namelast_p[0]", UCase(Form2.MetroLastName.Text))
pdfFormFields.SetField("CTR_V41[0].Page2[0].namefrst_p[0]", UCase(Form2.MetroFirstName.Text))
pdfFormFields.SetField("CTR_V41[0].Page2[0].street_p[0]", UCase(Form2.MetroStAddress.Text))
pdfFormFields.SetField("CTR_V41[0].Page2[0].city_p[0]", UCase(Form2.MetroCity.Text))
pdfFormFields.SetField("CTR_V41[0].Page2[0].phonenum_p[0]", FilterNumbers(Form2.MetroPhone.Text))
pdfFormFields.SetField("CTR_V41[0].Page2[0].namelast_v[0]", OrderingInfo(0))
pdfFormFields.SetField("CTR_V41[0].Page2[0].namefrst_v[0]", OrderingInfo(1))
pdfFormFields.SetField("CTR_V41[0].Page2[0].phonenum_v[0]", OrderingInfo(2))
pdfFormFields.SetField("CTR_V41[0].Page2[0].faclname_v[0]", "MASSACHUSETTS ALLIANCE OF PORTUGUESE SPEAKERS")
pdfFormFields.SetField("CTR_V41[0].Page2[0].membid_p[0]", Form2.MetroMemberID.Text)
pdfFormFields.SetField("CTR_V41[0].Page2[0].groupid_p[0]", Form2.MetroGroupID.Text)
pdfFormFields.SetField("CTR_V41[0].Page2[0].colldate[0]", FilterNumbers(Form2.MetroDOC.Text))
pdfFormFields.SetField("CTR_V41[0].Page2[0].insconm_p[0]", AuxOption)
'Page 3
pdfFormFields.SetField("CTR_V41[0].Page3[0].namelast_p[0]", UCase(Form2.MetroLastName.Text))
pdfFormFields.SetField("CTR_V41[0].Page3[0].namefrst_p[0]", UCase(Form2.MetroFirstName.Text))
pdfFormFields.SetField("CTR_V41[0].Page3[0].street_p[0]", UCase(Form2.MetroStAddress.Text))
pdfFormFields.SetField("CTR_V41[0].Page3[0].city_p[0]", UCase(Form2.MetroCity.Text))
pdfFormFields.SetField("CTR_V41[0].Page3[0].phonenum_p[0]", FilterNumbers(Form2.MetroPhone.Text))
pdfFormFields.SetField("CTR_V41[0].Page3[0].specsrce[0]", "4") '4 selects Urine Test
pdfFormFields.SetField("CTR_V41[0].Page3[0].namelast_v[0]", OrderingInfo(0))
pdfFormFields.SetField("CTR_V41[0].Page3[0].namefrst_v[0]", OrderingInfo(1))
pdfFormFields.SetField("CTR_V41[0].Page3[0].phonenum_v[0]", OrderingInfo(2))
pdfFormFields.SetField("CTR_V41[0].Page3[0].faclname_v[0]", "MASSACHUSETTS ALLIANCE OF PORTUGUESE SPEAKERS")
pdfFormFields.SetField("CTR_V41[0].Page3[0].membid_p[0]", Form2.MetroMemberID.Text)
pdfFormFields.SetField("CTR_V41[0].Page3[0].groupid_p[0]", Form2.MetroGroupID.Text)
pdfFormFields.SetField("CTR_V41[0].Page3[0].colldate[0]", FilterNumbers(Form2.MetroDOC.Text))
pdfFormFields.SetField("CTR_V41[0].Page3[0].insconm_p[0]", AuxOption)
'Page 4
pdfFormFields.SetField("CTR_V41[0].Page4[0].namelast_p[0]", UCase(Form2.MetroLastName.Text))
pdfFormFields.SetField("CTR_V41[0].Page4[0].namefrst_p[0]", UCase(Form2.MetroFirstName.Text))
pdfFormFields.SetField("CTR_V41[0].Page4[0].street_p[0]", UCase(Form2.MetroStAddress.Text))
pdfFormFields.SetField("CTR_V41[0].Page4[0].city_p[0]", UCase(Form2.MetroCity.Text))
pdfFormFields.SetField("CTR_V41[0].Page4[0].phonenum_p[0]", FilterNumbers(Form2.MetroPhone.Text))
pdfFormFields.SetField("CTR_V41[0].Page4[0].namelast_v[0]", OrderingInfo(0))
pdfFormFields.SetField("CTR_V41[0].Page4[0].namefrst_v[0]", OrderingInfo(1))
pdfFormFields.SetField("CTR_V41[0].Page4[0].phonenum_v[0]", OrderingInfo(2))
pdfFormFields.SetField("CTR_V41[0].Page4[0].faclname_v[0]", "MASSACHUSETTS ALLIANCE OF PORTUGUESE SPEAKERS")
pdfFormFields.SetField("CTR_V41[0].Page4[0].membid_p[0]", Form2.MetroMemberID.Text)
pdfFormFields.SetField("CTR_V41[0].Page4[0].groupid_p[0]", Form2.MetroGroupID.Text)
pdfFormFields.SetField("CTR_V41[0].Page4[0].colldate[0]", FilterNumbers(Form2.MetroDOC.Text))
pdfFormFields.SetField("CTR_V41[0].Page4[0].insconm_p[0]", AuxOption)
' report by reading values from completed PDF
' flatten the form to remove editting options, set it to false
' to leave the form open to subsequent manual edits
pdfStamper.FormFlattening = False
' close the pdf
pdfStamper.Close()
pdfReader.Close()
pdfStamper = Nothing
pdfReader = Nothing
Form2.LblStatus.Text = "CTR Forms Sucessfuly Generated."
Form2.MetroProgressBar.Visible = True
Form2.MetroProgressBar.Value = Form2.MetroProgressBar.Value + 50
GenerateForms = True
Catch ex As Exception
MsgBox("Uh OH! Can't Generate Client's Forms!" & vbCrLf & ex.Message) 'vbCrLf = Carriage Return
GenerateForms = False
End Try
End Function