/// <summary> /// /// </summary> /// <param name="title">The title of a file.</param> /// <param name="interpreter">The xml interpreter.</param> public FRCPdfPrinterIND(string title, FRCXmlInterpreter interpreter) { //Creates a new pdf document with title and file name from the parameter. document = new PdfDocument(); document.Info.Title = title; currentPage = document.AddPage(); this.interpreter = interpreter; this.fencer = interpreter.getFencerList(); this.pouleRound = interpreter.getPouleRoundList(); for (int i = 0; i < this.fencer.Count; i++) { rankListAllPouleRounds.Add((FRCFencer)this.fencer[i].Clone()); } }
/// <summary> /// Converts one or several xml files to pdf files. /// This method should be called when buttonConvert is clicked. /// </summary> private void convert() { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "PDF | *.pdf"; sfd.OverwritePrompt = true; sfd.CheckPathExists = true; string filePath, fileName, directoryPath; FRCXmlInterpreter interpreter; FRCPdfPrinter printer; PdfDocument bundle = new PdfDocument(); if (radioButtonOnlyFiles.Checked) { for (int i = 0; i < listBoxFileName.Items.Count; i++) { filePath = listBoxFileName.Items[i].ToString(); directoryPath = Path.GetDirectoryName(filePath); interpreter = new FRCXmlInterpreter(filePath); interpreter.interpretXml(); printer = new FRCPdfPrinter(xmlTitles[i], interpreter); PdfDocument document = printer.printResults(); fileName = directoryPath + "\\" + xmlTitles[i] + ".pdf"; try { //Save document document.Save(fileName); MessageBox.Show("Convertion succeeded!", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (IOException) { MessageBox.Show("PDF documents with same file name as chosen xml file must be closed.", "PDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else if (sfd.ShowDialog() == DialogResult.OK) { directoryPath = Path.GetDirectoryName(sfd.FileName); for (int i = 0; i < listBoxFileName.Items.Count; i++) { filePath = listBoxFileName.Items[i].ToString(); interpreter = new FRCXmlInterpreter(filePath); interpreter.interpretXml(); printer = new FRCPdfPrinter(xmlTitles[i], interpreter); PdfDocument document = printer.printResults(); fileName = directoryPath + "\\" + xmlTitles[i] + ".pdf"; try { //Save document document.Save(fileName); } catch (IOException) { MessageBox.Show("PDF documents with same file name as chosen xml file must be closed.", "PDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } document = PdfReader.Open(fileName, PdfDocumentOpenMode.Import); //Concatenate documents. for (int j = 0; j < document.PageCount; j++) { bundle.AddPage(document.Pages[j]); } if (radioButtonOnlyBundle.Checked) { try { File.Delete(fileName); } catch (IOException exc) { MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } try { bundle.Save(sfd.FileName); Process.Start(sfd.FileName); } catch (IOException) { MessageBox.Show("PDF documents with same file name as chosen xml file must be closed.", "PDF Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// /// </summary> /// <param name="title">The title of a file.</param> /// <param name="interpreter">The xml interpreter.</param> public FRCPdfPrinter(string title, FRCXmlInterpreter interpreter) { this.title = title; this.interpreter = interpreter; }