填写PDF并打印PDF时出现问题

时间:2019-03-01 17:44:46

标签: vb.net itext

我使用我的应用程序填写并打印表格。

当打印出表格时,除客户名称外的所有文本均为黑色...

我试图打印保存的PDF,并且发生了相同的结果。

当我打开填写的pdf文件并更改文本时,文件将正确打印出来。

我用来填写PDF并打印它的代码在...下,我是否可以更改代码,以免发生这种情况?

  Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
    Me.xmltopdf()
    Me.Print()
End Sub

Private Sub xmltopdf()
    Dim pdfTemp As String = My.Settings.SavePDFT ' ---> It's the original pdf form you want to fill
    Dim newFile As String = My.Settings.SavePDFS & Me.TextBox1.Text & ".PDF" ' ---> It will generate new pdf that you have filled from your program

    ' ------ READING -------

    Dim pdfReader As New PdfReader(pdfTemp)

    ' ------ WRITING -------

    ' If you don’t specify version and append flag (last 2 params) in below line then you may receive “Extended Features” error when you open generated PDF
    Dim pdfStamper As New PdfStamper(pdfReader, New FileStream(newFile, FileMode.Create), "\6c", True)

    Dim pdfFormFields As AcroFields = pdfStamper.AcroFields

    ' ------ SET YOUR FORM FIELDS ------

    pdfFormFields.SetField("Field_1", TextBox1.Text)
    pdfFormFields.SetField("Field_2", TextBox2.Text)
    ' There is more fields.. just removed them this.




    pdfStamper.FormFlattening = False

    ' close the pdf
    pdfStamper.Close()
    ' pdfReader.close() ---> DON"T EVER CLOSE READER IF YOU'RE GENERATING LOTS OF PDF FILES IN LOOP
End Sub


' Print PDF
 Private Sub Print()
' Wait a bit so the PDF file is created before printing.
    Threading.Thread.Sleep(2500)

    Dim psi As New ProcessStartInfo

    psi.UseShellExecute = True

    psi.Verb = "print"

    psi.WindowStyle = ProcessWindowStyle.Hidden

    'psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()

    psi.FileName = My.Settings.SavePDFS & Me.Ordre_NummerTextBox.Text & ".PDF" ' Here specify a document to be printed

    Process.Start(psi)

End Sub

enter image description here

这是打印出来的PDF。

1 个答案:

答案 0 :(得分:1)

我制作了一个新的PDF文件,但文件没有问题。

旧的PDF文件大25.8 MB,而新的PDF文件只有140 kB。

我还记得旧文件在过去被复制并更改过几次。