private static void Main(string[] args) { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component. //p.Serial = "XXXXXXXXXXX"; //Prepare variables with path. string docxFile = Path.GetFullPath(@"..\..\example.docx"); string pdfFileFromDocx = Path.GetFullPath(@"..\..\exampleResultDocx.pdf"); string rtfFile = Path.GetFullPath(@"..\..\example.rtf"); string pdfFileFromRtf = Path.GetFullPath(@"..\..\exampleResultRtf.pdf"); string htmlFile = Path.GetFullPath(@"..\..\example.htm"); string pdfFileFromHtml = Path.GetFullPath(@"..\..\exampleResultHtml.pdf"); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(Path.GetFullPath(@"..\..\")) { UseShellExecute = true }); // Convert DOCX file to PDF file p.DocxToPdfConvertFile(docxFile, pdfFileFromDocx); // Convert RTF file to PDF file p.RtfToPdfConvertFile(rtfFile, pdfFileFromRtf); // Convert HTML file to PDF file p.HtmlToPdfConvertFile(htmlFile, pdfFileFromHtml); }
static void Main(string[] args) { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component. //p.Serial = "XXXXXXXXXXX"; if (p != null) { string docxPath = @"..\..\example.docx"; string pdfPath = Path.ChangeExtension(docxPath, ".pdf"); // 2. Convert DOCX file to PDF file if (p.DocxToPdfConvertFile(docxPath, pdfPath) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } else { System.Console.WriteLine("Conversion failed!"); Console.ReadLine(); } } }
static void Main(string[] args) { // Activation of PDF Metamorphosis .Net after purchasing SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // Place your serial(s) number. // You will get own serial number(s) after purchasing the license. // If you will have any questions, email us to [email protected] or ask at online chat https://www.sautinsoft.com. p.Serial = "1234567890"; string docxPath = @"..\..\example.docx"; string pdfPath = Path.ChangeExtension(docxPath, ".pdf"); if (p.DocxToPdfConvertFile(docxPath, pdfPath) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } }
void CreatePdfsButton_Click(object sender, EventArgs e) { var excelColumnnameWithFilenameForOutput = ExcelColumnnameWithFilenameForOutputTextBox.Text; var excelColumnNameWithTargetEmailAddress = ExcelColumnNameWithTargetEmailAddressTextBox.Text; if (excelColumnnameWithFilenameForOutput.Length < 1) { MessageBox.Show("Please enter Columnname with PDF Filename to use in Outputfolder and E-Mail Attachment"); WriteMessage("Abortet."); return; } var dialogResult = MessageBox.Show("Do you want to send E-Mail with the application documents?", "Question", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes && string.IsNullOrWhiteSpace(excelColumnNameWithTargetEmailAddress)) { MessageBox.Show("Please enter Columnname with target E-Mail Address"); WriteMessage("Abortet."); return; } var docxPath = openFileDialogWord.FileName; var xlsxPath = openFileDialogExcel.FileName; var dataTable = ReadExcelToDataTable(xlsxPath); if (dataTable.Rows.Count <= 2) { WriteMessage("Warning: No Data found in Excel File"); WriteMessage("Abortet."); return; } using (var mainDoc = WordprocessingDocument.Open(docxPath, false)) for (int i = 1, dtRowsCount = dataTable.Rows.Count; i < dtRowsCount; i++) { var row = dataTable.Rows[i]; var invalidFileNameChars = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); var regex = new Regex($"[{Regex.Escape(invalidFileNameChars)}]"); excelColumnnameWithFilenameForOutput = regex.Replace(excelColumnnameWithFilenameForOutput, ""); var newDocxFileName = Path.Combine(outputFolderBrowserDialog.SelectedPath, row[excelColumnnameWithFilenameForOutput] + ".docx"); var newPdfFileName = Path.Combine(outputFolderBrowserDialog.SelectedPath, row[excelColumnnameWithFilenameForOutput] + ".pdf"); using (var resultDoc = WordprocessingDocument.Create(newDocxFileName, WordprocessingDocumentType.Document)) { foreach (var part in mainDoc.Parts) { resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId); } foreach (var descendant in resultDoc.MainDocumentPart.Document.Body.Descendants <Text>()) { foreach (DataColumn column in dataTable.Columns) { var placeholder = dataTable.Rows[0][column].ToString(); if (descendant.Text.Contains(placeholder)) { var newText = row[column].ToString(); descendant.Text = descendant.Text.Replace(placeholder, newText); } } descendant.Text.Replace("<EmailSubject>", ""); descendant.Text.Replace("</EmailSubject>", ""); descendant.Text.Replace("<EmailBody>", ""); descendant.Text.Replace("</EmailBody>", ""); descendant.Text.Replace("<InfoTextForEmail>", ""); } } // Create PDF file var retVal = pdfMetamorphosis.DocxToPdfConvertFile(newDocxFileName, newPdfFileName); if (retVal != 0) { WriteMessage("Warning: Error while creating PDF File: " + newPdfFileName); return; } // Send Email with Attachment throw new NotImplementedException(); } }