Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect rendering of text fields #105

Closed
arquitecturatic opened this issue Mar 14, 2022 · 0 comments
Closed

Incorrect rendering of text fields #105

arquitecturatic opened this issue Mar 14, 2022 · 0 comments

Comments

@arquitecturatic
Copy link

arquitecturatic commented Mar 14, 2022

Summary of the issue

There is an error when try to fill the Acrobat Form. Attached the templates and the results after filled.

Environment

iTextSharp.LGPLv2.Core version: 1.7.5
.NET Core SDK version: .Net Standard 2.0
IDE: VS 2019

Example code/Steps to reproduce:

var workStream = new MemoryStream();
var reader = new PdfReader(@"R:\\template.pdf");
var stamper = new PdfStamper(reader, workStream);

stamper.AcroFields.SetField("{NUMERO_DIAS_VISTA2}", "2039");

stamper.Writer.CloseStream = false;
stamper.Close();
reader.Close();
byte[] byteInfo = workStream.ToArray();
workStream.Write(byteInfo, 0, byteInfo.Length);
workStream.Position = 0;
File.WriteAllBytes(@"r:\demo1.pdf", byteInfo);

Fix

diff --git "a/src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/PdfReader.cs" "b/src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/PdfReader.cs"
index dd7b950..0667b5d 100644
--- "a/src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/PdfReader.cs"
+++ "b/src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/PdfReader.cs"
@@ -2502,7 +2502,17 @@ namespace iTextSharp.text.pdf
                     if (map.ContainsKey(k))
                     {
                         Tokens.Seek(address[k]);
-                        PdfObject obj = ReadPrObject();
+                        Tokens.NextToken();
+                        PdfObject obj;
+                        if (Tokens.TokenType == PrTokeniser.TK_NUMBER)
+                        {
+                            obj = new PdfNumber(Tokens.StringValue);
+                        }
+                        else
+                        {
+                            Tokens.Seek(address[k]);
+                            obj = ReadPrObject();
+                        }
                         _xrefObj[objNumber[k]] = obj;
                     }
                 }

Output:

template.pdf
filled_fixed.pdf
filled_175.pdf

@arquitecturatic arquitecturatic changed the title Incorrect render text fields Incorrect rendering of text fields Mar 14, 2022
@VahidN VahidN closed this as completed in 1bf4d28 Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant