public static TestSourceFile ( string fileName ) : SourceTestResult | ||
fileName | string | |
return | SourceTestResult |
public void AddInputFile(string file) { switch (Combiner.TestSourceFile(file)) { case Combiner.SourceTestResult.Unreadable: MessageBox.Show(string.Format("File could not be opened as a PDF document:\n\n{0}", file), "Illegal file type", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case Combiner.SourceTestResult.Protected: MessageBox.Show(string.Format("PDF document does not allow copying:\n\n{0}", file), "Permission denied", MessageBoxButtons.OK, MessageBoxIcon.Hand); break; case Combiner.SourceTestResult.Ok: inputListBox.Items.Add(file); break; } }
public void AddInputFile(string file) { // to open a text file with a list of pdfs (or further text files, i guess) to be added if (file.EndsWith(".txt")) { string[] pdf_files = System.IO.File.ReadAllLines(file); foreach (string item in pdf_files) { AddInputFile(item); } // txt file itself is not to be bound in to the output pdf. return; } // support password in txt manifest files delimited by pipe character "|" // support page selection in txt manifest files string filename = null; string password = null; string pageSelections = ""; string[] item_info = file.Split('|'); if (item_info.Length > 0) { filename = item_info[0]; if (item_info.Length > 1) { password = item_info[1]; } pageSelections = ""; if (item_info.Length > 2) { pageSelections = item_info[2]; } } if (!System.IO.File.Exists(filename)) { MessageBox.Show(string.Format("File not found:\n\n{0}", filename), "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Boolean tryAgain = true; Boolean newPassword = false; while (tryAgain || newPassword) { newPassword = false; switch (Combiner.TestSourceFile(filename, currentPassword)) { case Combiner.SourceTestResult.Unreadable: MessageBox.Show(string.Format("File could not be opened as a PDF document:\n\n{0}", filename), "Illegal file type", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case Combiner.SourceTestResult.Protected: MessageBox.Show(string.Format("PDF document does not allow copying:\n\n{0}", filename), "Permission denied", MessageBoxButtons.OK, MessageBoxIcon.Hand); break; case Combiner.SourceTestResult.Ok: // inputListBox.Items.Add(file); PdfItem pi = new PdfItem(); pi.BinderParentForm = this; pi.FileName = filename; pi.PageDescriptor = pageSelections; pi.Selected = false; FileListPanel.Controls.Add(pi); if (password != null) { currentPassword = StrToByteArray(password); } passwords[file] = currentPassword; break; case Combiner.SourceTestResult.PasswordRequired: if (tryAgain) { PasswordEntry pe = new PasswordEntry(); pe.Prompt = "Password required for file: \n" + file; DialogResult dr = pe.ShowDialog(this); if (dr == System.Windows.Forms.DialogResult.OK) { currentPassword = StrToByteArray(pe.Password); newPassword = true; } } else { MessageBox.Show(string.Format("Password supplied didn't open PDF document:\n\n{0}", file), "Bad password", MessageBoxButtons.OK, MessageBoxIcon.Hand); } break; } tryAgain = false; } }