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

问题描述 投票:1回答:1

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

打印表单时,除了客户名称之外的所有文本都是拉伸黑色...

我试图打印保存的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。

vb.net itext
1个回答
1
投票

我制作了一个新的PDF文件并且没有任何问题。

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

此外,我记得旧文件被复制并在过去多次更改。

© www.soinside.com 2019 - 2024. All rights reserved.