Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void converttxttoPDF(string sourcePath, string destPath)
- {
- try
- {
- iTextSharp.text.Document document = new iTextSharp.text.Document();
- string filename = Path.GetFileNameWithoutExtension(sourcePath);
- System.IO.StreamReader myFile = new System.IO.StreamReader(sourcePath);
- string myString = myFile.ReadToEnd();
- myFile.Close();
- if (!Directory.Exists(destPath))
- Directory.CreateDirectory(destPath);
- iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(destPath + "\" + filename + ".pdf", FileMode.CreateNew));
- document.Open();
- document.Add(new iTextSharp.text.Paragraph(myString));
- document.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- myString = string.IsNullOrEmpty(myString) ? " " : myString;
- document.Add(new iTextSharp.text.Paragraph(myString));
- Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
- wordDocument = word.Documents.Open(savedFileName, ReadOnly: true);
- wordDocument.ExportAsFixedFormat(attahcmentPath + "/pdf" + attachment.BetAttachmentCode + ".pdf", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
- word.Quit(false);
Add Comment
Please, Sign In to add comment