We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

TextBoxField: Preview-text and Edit-text does not have the same position



Platform: .net
Version: 11.5, with trial license

For some reason the text inside a TextBoxField does not hold the same position when just viewing the field, as it does when you set focus to the field to begin editing.
After editing the field (i.e adding a space), the new positioning of the text is not the same as before the editing took place.
This is especially noticable when using a non-standard font inside the textboxfield

I've tried this in both Adobe and Foxit with the same result.

When saving the same file after editing, and re-opening it, the textposition has permanently changed, and differs from the position it had in before editing took place.

This bug makes it impossible to create a document which is partialle pre-populated with editable data, because the layout of the text will change once the user starts editing, causing the document to look bad.

DemoCode:

Document Doc = new Document();
Doc.PageInfo.Margin = new MarginInfo(20, 20, 20, 20);
Aspose.Pdf.Page Page = Doc.Pages.Add();
Page.SetPageSize(Aspose.Pdf.PageSize.A4.Width, Aspose.Pdf.PageSize.A4.Height);

var otherfont = FontRepository.FindFont("Comic Sans MS");

Table tbl = new Table();
tbl.DefaultCellBorder = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.Black);
tbl.ColumnWidths = "80 100";
tbl.DefaultCellTextState = new TextState();
tbl.DefaultCellTextState.FontSize = 10;

{
var row = tbl.Rows.Add();
var c1 = row.Cells.Add("");
var c2 = row.Cells.Add("Before");
var c3 = row.Cells.Add("After");
}

{
var row = tbl.Rows.Add();
var c1 = row.Cells.Add("Default font:");
var c2 = row.Cells.Add();
var c3 = row.Cells.Add();

Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField tbf = new TextBoxField();
tbf.Value = "Hello World";
tbf.PartialName = "default";
tbf.Height = 15;
tbf.Width = 100;
c2.Paragraphs.Add(tbf);

Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField tbf2 = new TextBoxField();
tbf2.Value = "Hello World";
tbf2.PartialName = "default2";
tbf2.Height = 15;
tbf2.Width = 100;
c3.Paragraphs.Add(tbf2);
}


{

var row = tbl.Rows.Add();
row.FixedRowHeight = 20;
var c1 = row.Cells.Add("Other font:");
c1.DefaultCellTextState.Font = otherfont;
var c2 = row.Cells.Add();
var c3 = row.Cells.Add();
Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField tbf = new TextBoxField();
tbf.PartialName = "nonstandard";
tbf.Value = "Hello World";
tbf.Height = 20 - 2;
tbf.Width = 100;
c2.Paragraphs.Add(tbf);

Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField tbf2 = new TextBoxField();
tbf2.Value = "Hello World";
tbf2.PartialName = "nonstandard2";
tbf2.Height = 20 - 2;
tbf2.Width = 100;
c3.Paragraphs.Add(tbf2);
}

Page.Paragraphs.Add(tbl);



//The only way to set a specific font to a formfield
//seems to be to fake-save the document, and then modify it
using (MemoryStream ms = new MemoryStream())
{
Doc.Save(ms);

Doc.Form["nonstandard"].DefaultAppearance = new DefaultAppearance(otherfont, 10, System.Drawing.Color.Black);
Doc.Form["nonstandard2"].DefaultAppearance = new DefaultAppearance(otherfont, 10, System.Drawing.Color.Black);
}

string outputdir = @"..\..\output\";
string saveto = outputdir + "demo.pdf";
Doc.Save(saveto);

//when the document has opened up in acrobat or similar pdf viewer, edit the last column called 'after' for both of the rows
//(i.e add a space)
//when you now compare these with the columns called 'before', you'll see the difference
System.Diagnostics.Process.Start(saveto);


Hi Johan,


Thanks for your inquiry. I have noticed the reported issue with TextBoxField, so logged an investigation ticket PDFNEWNET-40736 in our issue tracking system for further investigation and rectification. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,