private void button2_Click(object sender, EventArgs e) { try { //folderbrowserdialog для выбора папки FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); // cоздаем конвертер DocToPDFConverter converter = new DocToPDFConverter(); //массив пдф документов PdfDocument[] pdfs; if (folderBrowser.ShowDialog() == DialogResult.OK) { //массив файлов из папки string[] files = Directory.GetFiles(folderBrowser.SelectedPath); progressBar1.Value = 0; progressBar1.Maximum = files.Length; //задаем размеры массива пдф файлов pdfs = new PdfDocument[files.Length]; //перебераем в цикле все файлы и конвертируем for (int i = 0; i < files.Length; i++) { if (Path.GetExtension(files[i]) == ".docx") { pdfs[i] = converter.ConvertToPDF(new WordDocument(files[i], FormatType.Docx)); progressBar1.Value++; pdfs[i].Save(System.IO.Path.GetDirectoryName(files[i]) + "/" + System.IO.Path.GetFileNameWithoutExtension(files[i]) + ".pdf"); pdfs[i].Close(); } else if (Path.GetExtension(files[i]) == ".doc") { pdfs[i] = converter.ConvertToPDF(new WordDocument(files[i], FormatType.Docx)); progressBar1.Value++; pdfs[i].Save(System.IO.Path.GetDirectoryName(files[i]) + "/" + System.IO.Path.GetFileNameWithoutExtension(files[i]) + ".pdf"); pdfs[i].Close(); } } //освобождаем ресурсы конвертера converter.Dispose(); } } catch (Exception ex) { MessageBox.Show("Пустой файл!"); } }
private void button1_Click(object sender, System.EventArgs e) { string text = @"..\..\..\..\..\..\..\Common\Data\PDF\Essential PDF.rtf"; WordDocument wordDoc = new WordDocument(text); DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(wordDoc); //Save the pdf file pdfDoc.Save("RTFtoPDF.pdf"); wordDoc.Close(); converter.Dispose(); pdfDoc.Close(); //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] System.Diagnostics.Process.Start("RTFtoPDF.pdf"); this.Close(); } else { // Exit this.Close(); } }
public ActionResult RTL(string Group1) { if (Group1 == null) { return(View()); } // Creating a new document. WordDocument document = new WordDocument(); document.EnsureMinimal(); // Reading Arabic text from text file. StreamReader s = new StreamReader(ResolveApplicationDataPath("Arabic.txt", "Data\\DocIO"), System.Text.Encoding.ASCII); string text = s.ReadToEnd(); // Appending Arabic text to the document. document.LastParagraph.ParagraphFormat.Bidi = true; IWTextRange txtRange = document.LastParagraph.AppendText(text); txtRange.CharacterFormat.Bidi = true; // Set the RTL text font size. txtRange.CharacterFormat.FontSizeBidi = 16; #region Document save option //Save as .doc format if (Group1 == "WordDoc") { return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(document.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(document); document.Close(); converter.Dispose(); return(pdfDoc.ExportAsActionResult("Sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } #endregion Document save option return(View()); }
public ActionResult RTFtoPDF(string InsideBrowser) { string text = ResolveApplicationDataPath("Essential PDF.rtf"); WordDocument wordDoc = new WordDocument(text); DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(wordDoc); wordDoc.Close(); converter.Dispose(); //Stream the output to the browser. if (InsideBrowser == "Browser") { return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
static void Main(string[] args) { //Get the path of existing Word document string fullpath = @"...\..\DocToPDF.docx"; //Loads an existing Word document WordDocument wordDocument = new WordDocument(fullpath, FormatType.Docx); //Creates an instance of the DocToPDFConverter DocToPDFConverter converter = new DocToPDFConverter(); //Converts Word document into PDF document PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument); //Releases all resources used by DocToPDFConverter converter.Dispose(); //Saves the PDF file pdfDocument.Save("DocToPDF.pdf"); //Closes the instance of document objects pdfDocument.Close(true); wordDocument.Close(); }
private void btnTopdf_Click(object sender, RoutedEventArgs e) { try { if (this.textBox1.Text != String.Empty && fullPath != string.Empty) { if (!this.textBox1.Text.EndsWith(".doc") && !this.textBox1.Text.EndsWith(".docx") && !this.textBox1.Text.EndsWith(".rtf") && !this.textBox1.Text.EndsWith(".docm") && !this.textBox1.Text.EndsWith(".dotx") && !this.textBox1.Text.EndsWith(".dotm") && !this.textBox1.Text.EndsWith(".dot") && !this.textBox1.Text.EndsWith(".txt")) { MessageBox.Show("Browse a Word document to convert to PDF", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (fullPath.EndsWith("\\")) { fullPath += this.textBox1.Text; } if (File.Exists(fullPath)) { using (WordDocument wordDoc = new WordDocument(fullPath)) { try { DocToPDFConverter converter = new DocToPDFConverter(); //Enable Direct PDF rendering mode for faster conversion. converter.Settings.EnableFastRendering = chkBox1.IsChecked.Value; converter.Settings.EmbedCompleteFonts = checkBox1.IsChecked.Value; converter.Settings.AutoTag = checkBox2.IsChecked.Value; converter.Settings.EmbedFonts = checkBox3.IsChecked.Value; converter.Settings.PreserveFormFields = checkBox4.IsChecked.Value; converter.Settings.ExportBookmarks = checkBox5.IsChecked.Value ? Syncfusion.DocIO.ExportBookmarkType.Headings : Syncfusion.DocIO.ExportBookmarkType.Bookmarks; if (checkBox6.IsChecked.Value) { wordDoc.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Formatting | RevisionType.Insertions; } //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(wordDoc); //Save the pdf file pdfDoc.Save("Word to PDF.pdf"); pdfDoc.Close(); converter.Dispose(); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Word to PDF.pdf") { UseShellExecute = true }; process.Start(); } catch (Exception ex) { MessageBox.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } catch (Exception ex) { if (ex is IOException) { MessageBox.Show("Please close the file (" + Directory.GetCurrentDirectory() + "\\Word to PDF.pdf" + ") then try generating the document.", "File is already open", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("Document could not be generated, Could you please email the error details with along input document to [email protected] for trouble shooting" + "\r\n" + ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } else { MessageBox.Show("File doesn’t exist"); } } else { MessageBox.Show("Browse a Word document to convert to PDF", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void button1_Click(object sender, System.EventArgs e) { try { // Creating a new document. WordDocument document = new WordDocument(); document.EnsureMinimal(); //Set Margin of the document document.LastSection.PageSetup.Margins.All = 72; // Reading Arabic text from text file. #if NETCORE StreamReader s = new StreamReader(@"..\..\..\..\..\..\..\common\Data\DocIO\Arabic.txt", System.Text.Encoding.ASCII); #else StreamReader s = new StreamReader(@"..\..\..\..\..\..\common\Data\DocIO\Arabic.txt", System.Text.Encoding.ASCII); #endif string text = s.ReadToEnd(); // Appending Arabic text to the document. document.LastParagraph.ParagraphFormat.Bidi = true; IWTextRange txtRange = document.LastParagraph.AppendText(text); txtRange.CharacterFormat.Bidi = true; // Set the RTL text font size. txtRange.CharacterFormat.FontSizeBidi = 16; //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); document.Close(); converter.Dispose(); //Save the pdf file pdfDoc.Save("Sample.pdf"); pdfDoc.Close(true); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void button1_Click(object sender, System.EventArgs e) { try { // Get XML file path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\common\Data\DocIO\"; //Opens an existing Word document WordDocument document = new WordDocument(dataPath + "Mathematical Equation.docx"); //Gets the last section in the document WSection section = document.LastSection; //Gets paragraph from Word document WParagraph paragraph = document.LastSection.Body.ChildEntities[3] as WParagraph; //Gets MathML from the paragraph WMath math = paragraph.ChildEntities[0] as WMath; //Gets the radical equation IOfficeMathRadical mathRadical = math.MathParagraph.Maths[0].Functions[1] as IOfficeMathRadical; //Gets the fraction equation in radical IOfficeMathFraction mathFraction = mathRadical.Equation.Functions[0] as IOfficeMathFraction; //Gets the n-array in fraction IOfficeMathNArray mathNAry = mathFraction.Numerator.Functions[0] as IOfficeMathNArray; //Gets the math script in n-array IOfficeMathScript mathScript = mathNAry.Equation.Functions[0] as IOfficeMathScript; //Gets the delimiter in math script IOfficeMathDelimiter mathDelimiter = mathScript.Equation.Functions[0] as IOfficeMathDelimiter; //Gets the math script in delimiter mathScript = mathDelimiter.Equation[0].Functions[0] as IOfficeMathScript; //Gets the math run element in math script IOfficeMathRunElement mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement; //Modifies the math text value (mathParaItem.Item as WTextRange).Text = "x"; //Gets the math bar in delimiter IOfficeMathBar mathBar = mathDelimiter.Equation[0].Functions[2] as IOfficeMathBar; //Gets the math run element in bar mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement; //Modifies the math text value (mathParaItem.Item as WTextRange).Text = "x"; //Gets the paragraph from Word document paragraph = document.LastSection.Body.ChildEntities[6] as WParagraph; //Gets MathML from the paragraph math = paragraph.ChildEntities[0] as WMath; //Gets the math script equation mathScript = math.MathParagraph.Maths[0].Functions[0] as IOfficeMathScript; //Gets the math run element in math script mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement; //Modifies the math text value (mathParaItem.Item as WTextRange).Text = "x"; //Gets the paragraph from Word document paragraph = document.LastSection.Body.ChildEntities[7] as WParagraph; //Gets MathML from the paragraph WMath math2 = paragraph.ChildEntities[0] as WMath; //Gets bar equation mathBar = math2.MathParagraph.Maths[0].Functions[0] as IOfficeMathBar; //Gets the math run element in bar mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement; //Gets the math text (mathParaItem.Item as WTextRange).Text = "x"; //Save as docx format if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Edit Equation.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Edit Equation.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Edit Equation.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); //Save the pdf file pdfDoc.Save("Edit Equation.pdf"); converter.Dispose(); pdfDoc.Close(); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Edit Equation.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Edit Equation.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void button1_Click(object sender, System.EventArgs e) { try { //Creates a new word document instance WordDocument document = new WordDocument(); //Adds new section to the document IWSection section = document.AddSection(); //Sets page margins document.LastSection.PageSetup.Margins.All = 72; //Adds new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Appends text to paragraph IWTextRange textRange = paragraph.AppendText("Mathematical equations"); textRange.CharacterFormat.FontSize = 28; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; paragraph.ParagraphFormat.AfterSpacing = 12; #region Sum to the power of n //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n."); //Creates an equation with sum to the power of N CreateSumToThePowerOfN(paragraph); #endregion #region Fourier series //Adds new paragraph to the section paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L"); //Creates a Fourier series equation CreateFourierseries(paragraph); #endregion #region Triple scalar product //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of triple scalar product"); //Creates a triple scalar product equation CreateTripleScalarProduct(paragraph); #endregion #region Gamma function //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of gamma function"); //Creates a gamma function equation CreateGammaFunction(paragraph); #endregion #region Vector relation //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of vector relation "); //Creates a vector relation equation CreateVectorRelation(paragraph); #endregion //Save as docx format if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Create Equation.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Create Equation.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Create Equation.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); //Save the pdf file pdfDoc.Save("Create Equation.pdf"); converter.Dispose(); pdfDoc.Close(); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Create Equation.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Create Equation.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void button1_Click(object sender, EventArgs e) { try { //progressbar progressBar1.Value = 0; progressBar1.Maximum = 1; //объявляем ковертер DocToPDFConverter converter = new DocToPDFConverter(); //объявляем openfiledialog и savefiledialog OpenFileDialog op = new OpenFileDialog(); SaveFileDialog sv = new SaveFileDialog(); sv.Filter = "Document |*.pdf"; if (op.ShowDialog() == DialogResult.OK) { if (Path.GetExtension(op.FileName) == ".docx") { //создаем документ docx WordDocument doc = new WordDocument(op.FileName, FormatType.Docx); //создаем документ pdf PdfDocument pdf = converter.ConvertToPDF(doc); progressBar1.Value++; //освобждаем ресурсы конвертера converter.Dispose(); //закрываем docx файл doc.Close(); //сохранение pdf if (sv.ShowDialog() == DialogResult.OK) { pdf.Save(sv.FileName); } //закрытие pdf pdf.Close(); } else if (Path.GetExtension(op.FileName) == ".doc") { //создаем документ doc WordDocument doc = new WordDocument(op.FileName, FormatType.Doc); //создаем документ pdf PdfDocument pdf = converter.ConvertToPDF(doc); progressBar1.Value++; //освобждаем ресурсы конвертера converter.Dispose(); //закрываем doc файл doc.Close(); //сохранение pdf if (sv.ShowDialog() == DialogResult.OK) { pdf.Save(sv.FileName); } } } } catch (Exception ex) { MessageBox.Show("Пустой файл!"); } }
public ActionResult CreateEquation(string Button, string Group1) { if (Button == null) { return(View()); } //Opens an existing Word document WordDocument document = new WordDocument(ResolveApplicationDataPath("Create Equation.docx", "Data\\DocIO")); //Gets the last section in the document WSection section = document.LastSection; //Sets page margins document.LastSection.PageSetup.Margins.All = 72; //Adds new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Appends text to paragraph IWTextRange textRange = paragraph.AppendText("Mathematical equations"); textRange.CharacterFormat.FontSize = 28; paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; paragraph.ParagraphFormat.AfterSpacing = 12; #region Sum to the power of n //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n."); //Creates an equation with sum to the power of N CreateSumToThePowerOfN(paragraph); #endregion #region Fourier series //Adds new paragraph to the section paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L"); //Creates a Fourier series equation CreateFourierseries(paragraph); #endregion #region Triple scalar product //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of triple scalar product"); //Creates a triple scalar product equation CreateTripleScalarProduct(paragraph); #endregion #region Gamma function //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of gamma function"); //Creates a gamma function equation CreateGammaFunction(paragraph); #endregion #region Vector relation //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of vector relation "); //Creates a vector relation equation CreateVectorRelation(paragraph); #endregion //Save as .docx format if (Group1 == "WordDocx") { return(document.ExportAsActionResult("CreateEquation.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(document); document.Close(); converter.Dispose(); return(pdfDoc.ExportAsActionResult("CreateEquation.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
private void button1_Click(object sender, EventArgs e) { try { String dst_path = get_file_path(); String ext = return_radio_rozszerzenie(); String filename = @"Resources\szablon1.docx"; string filetocopy = @"Backup\szablon1.docx"; File.Copy(filetocopy, filename, true); int count = Convert.ToInt32(numericUpDown1.Value); String numer = count.ToString(); ChangeTextInCell(filename, numer, 0, 1); ChangeTextInCell(filename, dateTimePicker1.Text, 1, 0); ChangeTextInCell(filename, Pole1.Text, 2, 0); ChangeTextInCell(filename, Pole2.Text, 3, 1); ChangeTextInCell(filename, Pole3.Text, 4, 1); ChangeTextInCell(filename, Pole4.Text, 5, 1); ChangeTextInCell(filename, Pole5.Text, 6, 1); ChangeTextInCell(filename, Pole6.Text, 7, 1); ChangeTextInCell(filename, Pole7.Text, 8, 0); ChangeTextInCell(filename, Pole8.Text, 9, 0); ChangeTextInCell(filename, Pole8.Text, 10, 0); ChangeTextInCell(filename, Pole10.Text, 11, 0); ChangeTextInCell(filename, Pole11.Text, 12, 0); if (return_radio_rozszerzenie().Equals(".pdf")) { //Loads an existing Word document WordDocument wordDocument = new WordDocument(filename, FormatType.Docx); //Creates an instance of the DocToPDFConverter DocToPDFConverter converter = new DocToPDFConverter(); //Converts Word document into PDF document PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument); //Releases all resources used by DocToPDFConverter converter.Dispose(); //Closes the instance of document objects wordDocument.Close(); //Saves the PDF file pdfDocument.Save(dst_path + "\\" + Path.GetFileName(textBox1.Text + ext)); //Closes the instance of document objects pdfDocument.Close(true); } else { File.Copy(filename, dst_path + "\\" + Path.GetFileName(textBox1.Text + ext)); } MessageBox.Show("Zapisano pomyślnie!"); File.Delete(filename); } catch { MessageBox.Show("Błąd zapisu!"); } }
public ActionResult EditEquation(string Button, string Group1) { if (Button == null) { return(View()); } if (Button == "View Template") { return(new TemplateResult("Mathematical Equation.docx", ResolveApplicationDataPath("Data\\DocIO"), HttpContext.ApplicationInstance.Response)); } //Opens an existing Word document WordDocument document = new WordDocument(ResolveApplicationDataPath("Mathematical Equation.docx", "Data\\DocIO")); //Gets the last section in the document WSection section = document.LastSection; //Gets paragraph from Word document WParagraph paragraph = document.LastSection.Body.ChildEntities[3] as WParagraph; //Gets MathML from the paragraph WMath math = paragraph.ChildEntities[0] as WMath; //Gets the radical equation IOfficeMathRadical mathRadical = math.MathParagraph.Maths[0].Functions[1] as IOfficeMathRadical; //Gets the fraction equation in radical IOfficeMathFraction mathFraction = mathRadical.Equation.Functions[0] as IOfficeMathFraction; //Gets the n-array in fraction IOfficeMathNArray mathNAry = mathFraction.Numerator.Functions[0] as IOfficeMathNArray; //Gets the math script in n-array IOfficeMathScript mathScript = mathNAry.Equation.Functions[0] as IOfficeMathScript; //Gets the delimiter in math script IOfficeMathDelimiter mathDelimiter = mathScript.Equation.Functions[0] as IOfficeMathDelimiter; //Gets the math script in delimiter mathScript = mathDelimiter.Equation[0].Functions[0] as IOfficeMathScript; //Gets the math run element in math script IOfficeMathRunElement mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement; //Modifies the math text value (mathParaItem.Item as WTextRange).Text = "x"; //Gets the math bar in delimiter IOfficeMathBar mathBar = mathDelimiter.Equation[0].Functions[2] as IOfficeMathBar; //Gets the math run element in bar mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement; //Modifies the math text value (mathParaItem.Item as WTextRange).Text = "x"; //Gets the paragraph from Word document paragraph = document.LastSection.Body.ChildEntities[6] as WParagraph; //Gets MathML from the paragraph math = paragraph.ChildEntities[0] as WMath; //Gets the math script equation mathScript = math.MathParagraph.Maths[0].Functions[0] as IOfficeMathScript; //Gets the math run element in math script mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement; //Modifies the math text value (mathParaItem.Item as WTextRange).Text = "x"; //Gets the paragraph from Word document paragraph = document.LastSection.Body.ChildEntities[7] as WParagraph; //Gets MathML from the paragraph WMath math2 = paragraph.ChildEntities[0] as WMath; //Gets bar equation mathBar = math2.MathParagraph.Maths[0].Functions[0] as IOfficeMathBar; //Gets the math run element in bar mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement; //Gets the math text (mathParaItem.Item as WTextRange).Text = "x"; //Save as .docx format if (Group1 == "WordDocx") { return(document.ExportAsActionResult("EditEquation.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(document); document.Close(); converter.Dispose(); return(pdfDoc.ExportAsActionResult("EditEquation.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }