So for some reason when I save my richtextbox text to a pdf format it goes well because when I open it chrome it look like it should however if i reopen the pdf file the word letters get spread out on each line I don't know why it's doing that.
I saw the problem happen to someone else but it was in wpf richtextbox but mine is in a winform richtextbox
Here is the guy wpf richtextbox problem and the image is from stackoverflow but im showing you the example
https://i.stack.imgur.com/xWsaR.jpg
Now my problem
https://www.dropbox.com/s/yf6nowelfugmvyx/Screenshot%20%2816%29.png?dl=0
When I save the file for the first time I use itext7 for vb.net
here is my code
Dim pdfDoc As iText.Kernel.Pdf.PdfDocument = New iText.Kernel.Pdf.PdfDocument(New iText.Kernel.Pdf.PdfWriter(dlg.FileName))
Dim myDocument As iText.Layout.Document = New iText.Layout.Document(pdfDoc, iText.Kernel.Geom.PageSize.A4)
Try
myDocument.Add(New iText.Layout.Element.Paragraph(RichTextBoxEx1.rtb.Text))
Catch de As iText.Kernel.PdfException
Console.Error.WriteLine(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
End Try
'step 5: Remember to close the document'
Text = dlg.FileName
myDocument.Close()
So before the user exits out I have a autosave option which checks to see if "io.file.exists(Me.Text)". The Me.Text aka Text is the form text and the form text is the filename as long the file exists. So when the user adds any more text to the richtextbox the pdf file will add the additional text to the file
this is the autosave pdf code
GemBox.Document.ComponentInfo.SetLicense("my license key number")
RichTextBoxEx1.rtb.SaveFile(Text, RichTextBoxStreamType.RichText)
GemBox.Document.DocumentModel.Load(Text, options:=GemBox.Document.LoadOptions.RtfDefault).Save(Text, GemBox.Document.SaveOptions.PdfDefault)
then when i open the pdf in the richtextbox I use this following code for that
Dim FileName As String = dlg.FileName
Using SourceStream As FileStream = IO.File.Open(FileName, FileMode.Open)
Dim r As Nasosoft.Documents.Pdf.PdfTextReader = New Nasosoft.Documents.Pdf.PdfTextReader(SourceStream, Encoding.Default)
RichTextBoxEx1.rtb.Text = (r.ReadToEnd)
End Using
So when i open the the pdf in chrome the first time it goes great even with the autosave and if its a regular pdf that I didn't edit the text it comes out great in the richtextbox the only issue is when i open it again for the second time in the richtextbox the letters in the words get spread out on each line but not together in a normal horizontal text.
In my opinion I believe the culprit is the code with nasosoft.
What I have tried:
I have tried changing the A4 format in the itext7 to something else to see if it would maybe fix the issue but either way it still comes out like this when i open the edited pdf document
https://www.dropbox.com/s/yf6nowelfugmvyx/Screenshot%20%2816%29.png?dl=0
however when i open a unedited pdf the text comes out great here is an image of that
https://www.dropbox.com/s/6oawnbdeu9gvuw8/Screenshot%20%2817%29.png?dl=0