Im creating big PDF files with large amount of buttons. When opening this files in Adobe Acrobat I have problem with broken form fields. Adobe is trying to fix these fields and it takes very long time. To see process of "Fixing up form fields" by Adobe, firstly open adobe and then from menu File - > Open. Small window will appear on bottom right side of adobe window.
Here is example code that I use to create pdf:
- Code: Select all
class Program
{
static void Main(string[] args)
{
var tw = new TestButtons();
tw.CreatePdf();
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
public class TestButtons
{
private readonly PdfNewDocument document;
public TestButtons()
{
document = new PdfNewDocument();
}
public void CreatePdf()
{
for (int i = 1; i <= 1000; i++)
{
Console.WriteLine($"Creating page {i}");
CreatePage(i);
}
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string resultPath = Path.Combine(path, $"TestButtons.pdf");
document.Save(resultPath);
}
private void CreatePage(int insertIndex)
{
var page = document.Pages.Insert(insertIndex, new Size(500, 500), new PdfMargins(0f));
for (int i = 1; i < 10; i++)
{
var btn = new PdfButtonField(page, $"{insertIndex}.{i}")
{
Bounds = new RectangleF(10, 10 + (26 * i), 25, 25),
HighlightMode = PdfHighlightMode.NoHighlighting,
BorderWidth = 1,
BorderColor = new PdfRGBColor(Color.Red),
BackColor = new PdfRGBColor(Color.Transparent),
ForeColor = new PdfRGBColor(Color.Red),
ToolTip = "Tooltip",
Text = "Test "
};
document.Form.Fields.Add(btn);
}
}
}
In my real output PDFs I use way more buttons to navigate between and it takes much more time to fix form fields by Adobe Acrobat.
If i dont add buttons to Form.Fields then Adobe is not fixing anything during opening but then i have two other issues:
Problem 1 - finding elements by name in java script takes long time i.e
and time is increased with number of pages, fields on pages 4000 and higher takes even about 30 seconds to find and in this time Adobe Acrobat is not responding.var f = this.getField('buttonName');
Problem 2 - Using option "Save As" in Adobe acrobat for created document will save new document without any buttons (fields) .
System Information:
Im using newest Spire PDF for .Net
Adobe Acrobat Reader DC Version 2020.012.20043
Windows 10 64 bit