private void buttonAppyRotation_Click(object sender, EventArgs e) { bool success; int angle = Convert.ToInt32(numericUpDownAngle.Value); if (string.IsNullOrEmpty(filePath)) { MessageBox.Show("Please select a pdf first"); return; } else if (radioButtonRotateSpecific.Checked && string.IsNullOrWhiteSpace(textBoxRotateSpecific.Text)) { MessageBox.Show("Please specify some pages first"); return; } if (radioButtonRotateAll.Checked) { success = PDFActions.RotateAllPages(filePath, angle, true /*should be only for debugging mode?*/); if (success) { UpdateStatusLabel("Rotated pages"); //Todo: this should be updated from PDFActions.RotateAllPages so that we have the specific page numbers } } else if (radioButtonRotateEven.Checked) { success = PDFActions.RotateEvenPages(filePath, angle, true /*should be only for debugging mode?*/); if (success) { UpdateStatusLabel("Rotated even pages"); //Todo: this should be updated from PDFActions.RotateEvenPages so that we have the specific page numbers } } else if (radioButtonRotateOdd.Checked) { success = PDFActions.RotateOddPages(filePath, angle, true /*should be only for debugging mode?*/); if (success) { UpdateStatusLabel("Rotated odd pages"); //Todo: this should be updated from PDFActions.RotateOddPages so that we have the specific page numbers } } else if (radioButtonRotateSpecific.Checked) { List <KeyValuePair <int, int> > indiciesAndAngles = new List <KeyValuePair <int, int> >(); foreach (int pageIndex in ParseSpecificPages(textBoxRotateSpecific.Text)) { indiciesAndAngles.Add(new KeyValuePair <int, int>(pageIndex, angle)); } success = PDFActions.RotatePages(filePath, indiciesAndAngles, true /*should be only for debugging mode?*/); if (success) { UpdateStatusLabel("Rotated pages"); //Todo: this should be updated from PDFActions.RotatePages so that we have the specific page numbers } } }
private void buttonMerge_Click(object sender, EventArgs e) { if (radioButtonMergeBeginning.Checked) { PDFActions.MergePDFonBeginning(filePath, mergeFilePath, true /*should be only for debugging mode?*/); } else if (radioButtonMergeEnd.Checked) { PDFActions.MergePDFonEnd(filePath, mergeFilePath, true /*should be only for debugging mode?*/); } UpdateStatusLabel("Merged " + Path.GetFileNameWithoutExtension(mergeFilePath) + " into " + Path.GetFileNameWithoutExtension(filePath)); }
private void buttonApplyRemove_Click(object sender, EventArgs e) { bool success; if (string.IsNullOrEmpty(filePath)) { MessageBox.Show("Please select a pdf first"); return; } else if (radioButtonRemoveSpecific.Checked && string.IsNullOrWhiteSpace(textBoxRemoveSpecific.Text)) { MessageBox.Show("Please specify some pages first"); return; } if (radioButtonRemoveEven.Checked) { success = PDFActions.RemoveEvenPages(filePath, true /*should be only for debugging mode?*/); if (success) { UpdateStatusLabel("Removed even pages"); //Todo: this should be updated from PDFActions.RemoveEvenPages so that we have the specific page numbers } } else if (radioButtonRemoveOdd.Checked) { success = PDFActions.RemoveOddPages(filePath, true /*should be only for debugging mode?*/); if (success) { UpdateStatusLabel("Removed odd pages"); //Todo: this should be updated from PDFActions.RemoveOddPages so that we have the specific page numbers } } else if (radioButtonRemoveSpecific.Checked) { success = PDFActions.RemovePages(filePath, ParseSpecificPages(textBoxRemoveSpecific.Text), true /*should be only for debugging mode?*/); if (success) { UpdateStatusLabel("Removed pages"); //Todo: this should be updated from PDFActions.RemovePages so that we have the specific page numbers } } }
private void SaveChanges() { foreach (KeyValuePair <SinglePageEditor, PageChanges> pair in changes) { //REMEMBER: iText page indicies are not zero-based, but rather start from 1 switch (pair.Value) { case PageChanges.Rotate90: PDFActions.RotatePages(filePath, new List <KeyValuePair <int, int> >() { new KeyValuePair <int, int>(pair.Key.PageIndex + 1, 90) }); break; case PageChanges.Rotate180: PDFActions.RotatePages(filePath, new List <KeyValuePair <int, int> >() { new KeyValuePair <int, int>(pair.Key.PageIndex + 1, 180) }); break; case PageChanges.Rotate270: PDFActions.RotatePages(filePath, new List <KeyValuePair <int, int> >() { new KeyValuePair <int, int>(pair.Key.PageIndex + 1, 270) }); break; } } //Need to do the removing after all the rotating (because of page inde List <KeyValuePair <SinglePageEditor, PageChanges> > pagesToRemove = changes.Where(p => p.Value == PageChanges.Remove).ToList(); for (int i = 0; i < pagesToRemove.Count; i++) { //REMEMBER: iText page indicies are not zero-based, but rather start from 1. Here we also need to adjust by "i" to //resolve the original page index (Key.PageIndex) with the new page indicies after removing pages PDFActions.RemovePages(filePath, new List <int>() { pagesToRemove[i].Key.PageIndex + 1 - i }); } }