【问题标题】:Problem when filling out a PDF and printing the PDF填写 PDF 和打印 PDF 时出现问题
【发布时间】:2019-03-01 17:44:45
【问题描述】:

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

当表格打印出来时,除了客户姓名之外的所有文字都是黑色的……

我已尝试打印保存的 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

这是打印出来的 PDF。

【问题讨论】:

  • 这毕竟不起作用 - 我在我的应用程序和我的 PDF 表单中将字体和字体大小设置为相同,似乎可以正常工作,但有时并非所有内容都打印出来。
  • 请分享有问题的 PDF。
  • 我将尝试使用新的 PDF 文件,我发现我的新 PDF 只有 140 KB,而我的旧 PDF 是 25 MB...如果它不起作用,我将分享 PDF

标签: vb.net itext


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    相关资源
    最近更新 更多