Incorrect Line Breaks in a Windows Forms TextBox
OCR text extracted with IronOCR can lose its line breaks when shown in a Windows Forms TextBox, collapsing onto fewer lines than the source image.
The cause is a newline mismatch. IronOCR returns line breaks as a bare line feed (\n), but a Windows Forms TextBox only renders a break when it sees a carriage return followed by a line feed (\r\n). Without the carriage return, the control ignores the break.
The OCR runs against a source image like the one below:

Binding the raw OCR result straight to the control collapses the text onto a couple of lines instead of preserving the original layout:

Solution
1. Use AdvancedScan in 64-bit Mode
Install the IronOCR.Extensions.AdvancedScan package for more reliable extraction, and run the application in 64-bit mode to avoid compatibility issues.
<PackageReference Include="IronOCR.Extensions.AdvancedScan" />
<PackageReference Include="IronOCR.Extensions.AdvancedScan" />
2. Normalize the Line Endings
Replace every \n in the result with \r\n before assigning the text to the control.
ocr.Language = OcrLanguage.ChineseSimplifiedBest;
using (var ocrInput = new OcrInput())
{
ocrInput.LoadImage(txtPath.Text);
ocrInput.Deskew();
var result = ocr.ReadScreenShot(ocrInput);
// Replace line feed with carriage return and line feed
string ocrText = result.Text.Replace("\n", "\r\n");
// Display the corrected text in a TextBox
textBox1.Text = ocrText;
}
ocr.Language = OcrLanguage.ChineseSimplifiedBest;
using (var ocrInput = new OcrInput())
{
ocrInput.LoadImage(txtPath.Text);
ocrInput.Deskew();
var result = ocr.ReadScreenShot(ocrInput);
// Replace line feed with carriage return and line feed
string ocrText = result.Text.Replace("\n", "\r\n");
// Display the corrected text in a TextBox
textBox1.Text = ocrText;
}
Imports System
ocr.Language = OcrLanguage.ChineseSimplifiedBest
Using ocrInput As New OcrInput()
ocrInput.LoadImage(txtPath.Text)
ocrInput.Deskew()
Dim result = ocr.ReadScreenShot(ocrInput)
' Replace line feed with carriage return and line feed
Dim ocrText As String = result.Text.Replace(vbLf, vbCrLf)
' Display the corrected text in a TextBox
textBox1.Text = ocrText
End Using
The Replace("\n", "\r\n") call rewrites each line feed into the carriage-return/line-feed pair the TextBox expects, so the displayed text keeps the same line structure as the original image.
3. Verify the Output
Run the extraction again and compare the TextBox contents against the source image. The breaks should now line up with the original layout.


