Beispiel #1
0
        public FieldOptionForm(Point location, PDFField pdfField, List<string> dataSourceColumns)
        {
            // Init
            this.pdfField = pdfField;
            if (SavedLocation == new Point(0,0))
            {
                this.DesktopLocation = location;
            }
            else
            {
                this.DesktopLocation = SavedLocation;
            }
            InitializeComponent();

            // Datasource
            foreach (var column in dataSourceColumns)
                cbDataSourceColumns.Items.Add(column);

            cbDataSourceColumns.SelectedIndex = 0;
            if (!String.IsNullOrEmpty(pdfField.DataSourceValue))
            {
                int index = cbDataSourceColumns.FindString(pdfField.DataSourceValue);

                if (index != -1)
                    cbDataSourceColumns.SelectedIndex = cbDataSourceColumns.FindString(pdfField.DataSourceValue);
            }

            cbUseValueFromDataSource.Checked = pdfField.UseValueFromDataSource;
            cbUseValueFromDataSource_CheckedChanged(null, null);

            cbReadOnly.Checked = pdfField.MakeReadOnly;
            cbReadOnly_CheckedChanged(null, null);
        }
Beispiel #2
0
        private List <PDFField> ListDynamicXFAFields(System.Xml.XmlNode n)
        {
            List <PDFField> pdfFields = new List <PDFField>();

            foreach (System.Xml.XmlNode child in n.ChildNodes)   // > 0 Childs == Group
            {
                pdfFields.AddRange(ListDynamicXFAFields(child)); // Search field
            }
            if (n.ChildNodes.Count == 0)                         // 0 Childs == Field
            {
                var acroFields = pdfReader.AcroFields;

                var pdfField = new PDFField();

                // If a value is set the value of n.Name would be "#text"
                if ((n.Name.ToCharArray(0, 1))[0] != '#')
                {
                    pdfField.Name = acroFields.GetTranslatedFieldName(n.Name);
                }
                else
                {
                    pdfField.Name = acroFields.GetTranslatedFieldName(n.ParentNode.Name);
                }

                pdfField.CurrentValue = n.Value;

                pdfField.Typ = "";

                pdfFields.Add(pdfField);

                return(pdfFields);
            }

            return(pdfFields);
        }
Beispiel #3
0
        public FieldOptionForm(Point location, PDFField pdfField, List <string> dataSourceColumns)
        {
            // Init
            this.pdfField = pdfField;
            if (SavedLocation == new Point(0, 0))
            {
                this.DesktopLocation = location;
            }
            else
            {
                this.DesktopLocation = SavedLocation;
            }
            InitializeComponent();


            // Datasource
            foreach (var column in dataSourceColumns)
            {
                cbDataSourceColumns.Items.Add(column);
            }

            cbDataSourceColumns.SelectedIndex = 0;
            if (!String.IsNullOrEmpty(pdfField.DataSourceValue))
            {
                int index = cbDataSourceColumns.FindString(pdfField.DataSourceValue);

                if (index != -1)
                {
                    cbDataSourceColumns.SelectedIndex = cbDataSourceColumns.FindString(pdfField.DataSourceValue);
                }
            }

            cbUseValueFromDataSource.Checked = pdfField.UseValueFromDataSource;
            cbUseValueFromDataSource_CheckedChanged(null, null);

            cbReadOnly.Checked = pdfField.MakeReadOnly;
            cbReadOnly_CheckedChanged(null, null);
        }
Beispiel #4
0
        private List <PDFField> ListGenericFields()
        {
            var fields     = new List <PDFField>();
            var acroFields = pdfReader.AcroFields;

            foreach (var field in acroFields.Fields)
            {
                if (acroFields.GetFieldType(field.Key.ToString()) != (int)AcroFieldsTypes.BUTTON)
                {
                    // If readonly, continue loop
                    var n = field.Value.GetMerged(0).GetAsNumber(PdfName.FF);
                    if (n != null && ((n.IntValue & (int)PdfFormField.FF_READ_ONLY) > 0))
                    {
                        continue;
                    }
                    else
                    {
                        var pdfField = new PDFField();
                        pdfField.Name         = field.Key.ToString();
                        pdfField.CurrentValue = acroFields.GetField(field.Key.ToString());
                        try
                        {
                            pdfField.Typ = Convert.ToString((AcroFieldsTypes)acroFields.GetFieldType(pdfField.Name));
                        }
                        catch (Exception)
                        {
                            pdfField.Typ = "";
                        }

                        fields.Add(pdfField);
                    }
                }
            }

            return(fields);
        }
Beispiel #5
0
        public bool Do(string configurationFilePath)
        {
            try
            {
                Console.WriteLine("--- Load configuration file ---");
                configurationFilePath = Environment.ExpandEnvironmentVariables(configurationFilePath);
                XDocument xDocument = XDocument.Parse(File.ReadAllText(configurationFilePath));

                //// Options
                var xmlOptions = xDocument.Root.Element("Options");
                // DataSource
                Console.WriteLine("Load spreadsheet");
                dataSource = new Spreadsheet();
                dataSource.Open(Environment.ExpandEnvironmentVariables(xmlOptions.Element("DataSource").Element("Parameter").Value));
                ((Spreadsheet)dataSource).SetSheet(xmlOptions.Element("Spreadsheet").Element("Table").Value);

                // PDF
                Console.WriteLine("Load PDF");
                pdf = new PDF();
                pdf.Open(Environment.ExpandEnvironmentVariables(xmlOptions.Element("PDF").Element("Filepath").Value));

                //// PDFFieldValues
                Console.WriteLine("Load field configuration");
                Dictionary<string, PDFField> pdfFields = new Dictionary<string, PDFField>();
                foreach (var node in xDocument.Root.Element("PDFFieldValues").Descendants("PDFFieldValue"))
                {
                    var pdfField = new PDFField();
                    pdfField.Name = node.Element("Name").Value;
                    pdfField.DataSourceValue = node.Element("NewValue").Value;
                    pdfField.UseValueFromDataSource = Convert.ToBoolean(node.Element("UseValueFromDataSource").Value);
                    pdfField.MakeReadOnly = Convert.ToBoolean(node.Element("MakeReadOnly").Value);

                    pdfFields.Add(pdfField.Name, pdfField);
                }

                //// Filename
                Console.WriteLine("Load filename options");
                var xmlFilename = xmlOptions.Element("Filename");
                prefix = xmlFilename.Element("Prefix").Value;
                useValueFromDataSource = Convert.ToBoolean(xmlFilename.Element("ValueFromDataSource").Value);
                DataSourceColumnsFilenameIndex = ((Spreadsheet)dataSource).Columns.IndexOf(xmlFilename.Element("DataSource").Value);
                suffix = xmlFilename.Element("Suffix").Value;
                useRowNumber = Convert.ToBoolean(xmlFilename.Element("RowNumber").Value);

                //// Other
                Console.WriteLine("Load general options");
                bool finalize = Convert.ToBoolean(xmlOptions.Element("Finalize").Value);
                string outputDir = Environment.ExpandEnvironmentVariables(xmlOptions.Element("OutputDir").Value);

                Console.WriteLine("--- Start processing ---");
                PDFFiller.CreateFiles(pdf, finalize, dataSource, pdfFields, outputDir + @"\", ConcatFilename, WriteLinePercent);
                Console.WriteLine("!!! Finished !!!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }

            return true;
        }
Beispiel #6
0
        private List<PDFField> ListGenericFields()
        {
            var fields = new List<PDFField>();
            var acroFields = pdfReader.AcroFields;

            foreach (var field in acroFields.Fields)
                if (acroFields.GetFieldType(field.Key.ToString()) != (int)AcroFieldsTypes.BUTTON)
                {
                    // If readonly, continue loop
                    var n = field.Value.GetMerged(0).GetAsNumber(PdfName.FF);
                    if (n != null && ((n.IntValue & (int)PdfFormField.FF_READ_ONLY) > 0))
                    {
                        continue;
                    }
                    else
                    {
                        var pdfField = new PDFField();
                        pdfField.Name = field.Key.ToString();
                        pdfField.CurrentValue = acroFields.GetField(field.Key.ToString());
                        try
                        {
                            pdfField.Typ = Convert.ToString((AcroFieldsTypes)acroFields.GetFieldType(pdfField.Name));
                        }
                        catch (Exception)
                        {
                            pdfField.Typ = "";
                        }

                        fields.Add(pdfField);
                    }
                }

            return fields;
        }
Beispiel #7
0
        private List<PDFField> ListDynamicXFAFields(System.Xml.XmlNode n)
        {
            List<PDFField> pdfFields = new List<PDFField>();

            foreach (System.Xml.XmlNode child in n.ChildNodes) // > 0 Childs == Group
                pdfFields.AddRange(ListDynamicXFAFields(child)); // Search field

            if (n.ChildNodes.Count == 0) // 0 Childs == Field
            {
                var acroFields = pdfReader.AcroFields;

                var pdfField = new PDFField();

                // If a value is set the value of n.Name would be "#text"
                if ((n.Name.ToCharArray(0, 1))[0] != '#')
                {
                    pdfField.Name = acroFields.GetTranslatedFieldName(n.Name);
                }
                else
                {
                    pdfField.Name = acroFields.GetTranslatedFieldName(n.ParentNode.Name);
                }

                pdfField.CurrentValue = n.Value;

                pdfField.Typ = "";

                pdfFields.Add(pdfField);

                return pdfFields;
            }

            return pdfFields;
        }