The Input PDF has a password that we do not have for making design changes using Adobe but there is no read password, I update form fields using Spire.PDF and I place a picture on the PDF and I save it, there is no password for reading on it to begin with and in 5.7.0 of Spire.PDF this process works flawlessly, but in the latest version that I have of Spire.PDF 8.3.9 after running the exact same code and saving the document, the resulting document contains a read only password that it didn't contain before and I never set in code. I will email support with the PDF in question, then what you will need to do to test, is to do a regular load of the PDF document, update a form field, attach a JPG image and simply save it, then try to open it in Adobe Acrobat DC. Additionally, even though Adobe wants the read password on the resulting PDF, you can open the PDF in Edge or Chrome and read it just fine.
Windows 10, 64 bit desktop
Windows Forms Application
.NET Framework 4.6 version of the library
Attached is a short snippet that should work for your purpose in testing the PDF I send.
- Code: Select all
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("testfile.pdf");
//Get form
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
//Fill the data for textBoxField
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
listTextBoxNames.Add(textBoxField.Name);
switch (textBoxField.Name)
{
case "AgencyCode": {
textBoxField.Text = "TEST FIELD";
} break;
default:
{
textBoxField.Text = textBoxField.Name;
}
break;
}
}
}
// need to now apply the image to the document, remove what you do not need, just place the image anywhere, doesn't matter for testing
PdfImage image = PdfImage.FromFile("yourimage.jpg");
// use for scaling if needed
float width = image.Width/5f;
float height = image.Height/5f;
float x = 40;
float y = 192;
PointF location = new PointF(x, y);
SizeF size = new SizeF(width, height);
PdfPageCollection pageinfo = doc.Pages;
PdfPageBase lastpage = doc.Pages[doc.Pages.Count-1];
lastpage.Canvas.DrawImage(image, location, size);
doc.SaveToFile("outputfile.pdf");
Hopefully the stripped down code works on your end, sending the source PDF over.