Reputation: 63
I use my application to fill and print out forms.
When the form is printed out all the text except the name of the customer is stretch black...
I have tried to print the saved PDF and the same result is happening.
When i open the filled out pdf and change the text, the file is printed out correctly..
The code i'm using to fill out the PDF and printing it is under... Is there something that i can change in my code so this dont happens?
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
This is the printet out PDF.
Upvotes: 1
Views: 116
Reputation: 63
I made a new PDF File and have had no problems with it sinse.
The old PDF file was 25.8 MB large and the new one is only 140 kB.
Also i remember that the Old file is copied and change several times in the past.
Upvotes: 1