Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2014 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b21947138176732fa438 to your computer and use it in GitHub Desktop.
Save anonymous/b21947138176732fa438 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Org.BouncyCastle.Security.Certificates;
using Paragraph = System.Windows.Documents.Paragraph;
namespace TestUtility.Forms.Controls
{
/// <summary>
/// Interaction logic for PDF_Fields.xaml
/// </summary>
public partial class PDF_Fields : UserControl
{
public PDF_Fields()
{
InitializeComponent();
string PDFLocation = ""; //accept this location in control definition
//List XML Entries
var XMLFields = new List<string>(); //Get a string listing of the XML objects in the namespaces ManualInputForm.xml file.
//Get PDF Field Data For Fields in XML X/Y/Width/Height
var reader = new PdfReader(PDFLocation);
var Fields = new List<XAMLPDFField>();
foreach (var field in XMLFields)
{
XAMLPDFField p = new XAMLPDFField();
IList<AcroFields.FieldPosition> fieldPositions = reader.AcroFields.GetFieldPositions(field);
if (fieldPositions == null || fieldPositions.Count <= 0) throw new ApplicationException("Error locating field");
AcroFields.FieldPosition fieldPosition = fieldPositions[0]; //holds left, right, top, and bottom
p.page = fieldPosition.page;
p.x = fieldPosition.position.Left;
p.y = fieldPosition.position.Top;
p.width = fieldPosition.position.Width;
p.height = fieldPosition.position.Height;
Fields.Add(p);
}
//Add PDF as a Background to the XAML
//Loop Databound Texboxes to the XML at the XY Data with the recorded width and height
}
}
class XAMLPDFField
{
public float x;
public float y;
public float height;
public float width;
public int page;
public XAMLPDFField()
{ }
public XAMLPDFField(int c1, int c2, int Width, int Height)
{
x = c1;
y = c2;
width = Width;
height = Height;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment