private void ResetPDF() { pdf = null; dgvBulkPDF.Rows.Clear(); pdfFields.Clear(); tbPDF.Text = ""; tbFormTyp.Text = ""; }
/**************************************************/ private void bSelectPDF_Click(object sender, EventArgs e) { // Select File OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); openFileDialog.Filter = "PDF|*.pdf"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == DialogResult.OK) { // PDF if (pdf != null) pdf.Close(); pdf = new PDF(); OpenPDF(openFileDialog.FileName); } }
private bool OpenPDF(string pdfPath) { try { ResetPDF(); pdf = new PDF(); pdf.Open(pdfPath); // Fill DataGridView tbPDF.Text = pdfPath; if (pdf.IsXFA) { tbFormTyp.Text = "XFA Form"; } else { tbFormTyp.Text = "Acroform"; } foreach (PDFField pdfField in pdf.ListFields()) { dgvBulkPDF.Rows.Add(); int row = dgvBulkPDF.Rows.Count - 1; dgvBulkPDF.Rows[row].Cells["ColField"].Value = pdfField.Name; dgvBulkPDF.Rows[row].Cells["ColTyp"].Value = pdfField.Typ; dgvBulkPDF.Rows[row].Cells["ColValue"].Value = pdfField.CurrentValue; pdfFields.Add(pdfField.Name, pdfField); var dgvButtonCell = new DataGridViewButtonCell(); dgvButtonCell.Value = Properties.Resources.CellButtonSelect; dgvBulkPDF.Rows[row].Cells["ColOption"] = dgvButtonCell; } return true; } catch (Exception ex) { ExceptionHandler.Throw(String.Format(Properties.Resources.ExceptionPDFIsCorrupted, pdfPath), ex.ToString()); ResetPDF(); } return false; }
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; }