private void UpdateGrid() { this.dataGrid.Rows.Clear(); int itemIndex = 0; foreach (MergeListFiles mergeitem in this.merger.MergeListFileArray) { ++itemIndex; int r = this.dataGrid.Rows.Add(); this.dataGrid.Rows[r].Cells[0].Value = this.rowcolors[mergeitem.Level].GetItemString(r); this.dataGrid.Rows[r].Cells[0].Style = this.rowcolors[mergeitem.Level].Style; this.dataGrid.Rows[r].Cells[1].Value = mergeitem.Path; this.dataGrid.Rows[r].Cells[2].Value = mergeitem.Pages; if (mergeitem.Bookmark != null) { this.dataGrid.Rows[r].Cells[3].Value = mergeitem.Bookmark; } DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)this.dataGrid.Rows[r].Cells[4]; check.Value = mergeitem.Include; DataGridViewComboBoxCell combocell = (DataGridViewComboBoxCell)this.dataGrid.Rows[r].Cells[5]; combocell.Items.Add("Root"); for (int x = 1; x < 20; ++x) { combocell.Items.Add("Level " + x.ToString()); } combocell.Value = combocell.Items[mergeitem.Level]; } this.Text = "PdfMerge - " + this.currentFile; this.outBox.Text = this.merger.MergeListInfo.OutFilename; this.checkBoxNumberPages.Checked = this.merger.MergeListInfo.NumberPages; this.textBoxStartPage.Text = this.merger.MergeListInfo.StartPage.ToString(); if (string.IsNullOrEmpty(this.merger.MergeListInfo.Annotation) == false) { this.textBoxAnnotate.Text = this.merger.MergeListInfo.Annotation; } else { this.textBoxAnnotate.Text = string.Empty; } this.PaginationFormat = this.merger.MergeListInfo.PaginationFormat; }
private void UpdateFromGrid() { this.dataGrid.EndEdit(); this.merger.MergeListFileArray = new List <MergeListFiles>(); foreach (DataGridViewRow row in this.dataGrid.Rows) { MergeListFiles mergeItem = new MergeListFiles(); mergeItem.Path = row.Cells[1].Value.ToString(); mergeItem.Pages = row.Cells[2].Value.ToString(); if (row.Cells[3].Value != null) { if (row.Cells[3].Value.ToString().Length > 0) { mergeItem.Bookmark = row.Cells[3].Value.ToString(); } } DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)row.Cells[4]; if ((bool)check.Value == false) { mergeItem.Include = false; } DataGridViewComboBoxCell combo = (DataGridViewComboBoxCell)row.Cells[5]; mergeItem.Level = combo.Items.IndexOf(row.Cells[5].Value); this.merger.MergeListFileArray.Add(mergeItem); } this.merger.MergeListInfo.OutFilename = this.outBox.Text; this.merger.MergeListInfo.NumberPages = this.checkBoxNumberPages.Checked; try { this.merger.MergeListInfo.StartPage = int.Parse(this.textBoxStartPage.Text); } catch { this.merger.MergeListInfo.StartPage = 1; } this.merger.MergeListInfo.Annotation = this.textBoxAnnotate.Text; this.merger.MergeListInfo.PaginationFormat = this.PaginationFormat; }
public string DoSplitMerge(string commandFilename, string outputFilename, ListBox lbStat, int startPageNumber, bool numberPages, string annotation, PaginationFormatting.PaginationFormats paginationFormat, bool createTestInfo = false) { PdfSharpSplitterMerger psm = null; int page = 1; int bmCount = 0; if (commandFilename != null) { try { int fileMissingCount = 0; if (commandFilename.ToLower().EndsWith(".xml")) { fileMissingCount = this.ReadXmlCommandFile(commandFilename); } else { fileMissingCount = this.ReadAsciiCommandFile(commandFilename); } if (fileMissingCount > 0) { this.ResolvePathsIfFoldersMoved(commandFilename, fileMissingCount); } } catch (Exception err) { return(err.Message); } } string line = string.Empty; try { psm = new PdfSharpSplitterMerger(); if (this.MergeListInfo.HasInfo == true) { psm.Title = this.MergeListInfo.InfoTitle; psm.Subject = this.MergeListInfo.InfoSubject; psm.Author = this.MergeListInfo.InfoAuthor; } if (commandFilename != null) { // get options from command file numberPages = this.MergeListInfo.NumberPages; annotation = this.MergeListInfo.Annotation; paginationFormat = this.MergeListInfo.PaginationFormat; startPageNumber = this.MergeListInfo.StartPage; } foreach (MergeListFiles merge in this.MergeListFileArray) { line = merge.Descriptor; string infile = merge.Path; string pagelst = merge.Pages; string file_add = infile; if (lbStat != null) { lbStat.Items.Add(line); lbStat.TopIndex = lbStat.Items.Count - 1; lbStat.Refresh(); } List <int> ps = this.ExtractPageList(pagelst); // merge the input file if (ps.Count > 0) { page += psm.Add(file_add, ps.ToArray()); } else { page += psm.Add(file_add); } // add bookmarks string rootTitle = merge.Bookmark; int level = merge.Level; bmCount += psm.AddBookmarksFromFile(rootTitle, level, merge.Include, line); } // this writes out the merged files psm.Finish(outputFilename, annotation, numberPages, startPageNumber, paginationFormat); if (createTestInfo) { SortedDictionary <string, string> report = new SortedDictionary <string, string>(); report.Add("MergeListFileArrayCount", this.MergeListFileArray.Count.ToString()); report.Add("PageCount", (page - 1).ToString()); report.Add("BookMarkCount", bmCount.ToString()); StringBuilder info = new StringBuilder(); foreach (KeyValuePair <string, string> kvp in report) { info.AppendFormat("{0}={1}\r\n", kvp.Key, kvp.Value); } File.WriteAllText(outputFilename + ".info", info.ToString()); } } catch (Exception err) { psm = null; string retval; if (line != null) { if (line.Length > 0) { retval = err.Message + "\nOn Line:\n" + line; } else { retval = err.Message; } } else { retval = err.Message; } return(retval); } psm = null; GC.Collect(); GC.WaitForPendingFinalizers(); // return empty string indicating no error return(string.Empty); }
public void Finish(string outfilename, string annotate, bool numberPages, int startPageNum, PaginationFormatting.PaginationFormats paginationFormat) { this.outputDocument.Info.Author = this.Author; if (this.Subject.Length > 0) { this.outputDocument.Info.Subject = this.Subject; } if (this.Title.Length > 0) { this.outputDocument.Info.Title = this.Title; } PdfOutline outline = null; this.bm.WriteToDoc(ref outline, ref this.outputDocument, 0); #region Add Page Numbering XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode); XFont font = new XFont("Verdana", 9, XFontStyle.Bold, options); XStringFormat pageNumFormat = new XStringFormat(); pageNumFormat.Alignment = XStringAlignment.Far; pageNumFormat.LineAlignment = XLineAlignment.Far; XStringFormat annotateFormat = new XStringFormat(); annotateFormat.Alignment = XStringAlignment.Near; annotateFormat.LineAlignment = XLineAlignment.Far; XGraphics gfx; XRect box; int pageNumber = startPageNum; int pageCount = this.outputDocument.Pages.Count; foreach (PdfPage page in this.outputDocument.Pages) { // Get a graphics object for page gfx = XGraphics.FromPdfPage(page); if (numberPages == true) { box = page.MediaBox.ToXRect(); box.Inflate(-30, -20); string pageLabel = PaginationFormatting.GetFormattedPageString( startPageNum, pageNumber, pageCount, paginationFormat); gfx.DrawString( pageLabel, font, XBrushes.Black, box, pageNumFormat); } if (string.IsNullOrEmpty(annotate) == false) { box = page.MediaBox.ToXRect(); box.Inflate(-30, -20); gfx.DrawString(annotate, font, XBrushes.Black, box, annotateFormat); } ++pageNumber; } #endregion this.outputDocument.Save(outfilename); this.bm.Clear(); }