I am trying to use Spire.PDF to fill forms, however I have one form that is in landscape mode where the code is not working. The text gets inserted in the wrong part of the page and the orientation of the text is wrong also.
This is the code I am using:
protected void Page_Load(object sender, EventArgs e)
{
string fileToOpen = Path.Combine(HttpContext.Current.Server.MapPath("~"), "docs\\waiver\\2016_452_3039_waiver.pdf");
PdfDocument doc = new PdfDocument();
try
{
doc.LoadFromFile(fileToOpen);
}
catch (Exception ex)
{
throw new Exception("Waiver template not found at " + fileToOpen + "\n" + ex.ToString());
}
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
if (formWidget != null)
{
//formWidget.
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
textBoxField.Text = textBoxField.Name;
field.Flatten = true;
field.ReadOnly = true;
}
}
}
MemoryStream attachStream = new MemoryStream();
doc.SaveToStream(attachStream);
doc.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=waiver.pdf");
Response.AddHeader("Content-Length", attachStream.Length.ToString());
Response.ContentType = "application/pdf";
Response.BinaryWrite(attachStream.ToArray());
Response.Flush();
}
}
I tried uploading the PDF but I got a message that that extension is not allowed