Guest User

Untitled

a guest
Jan 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public void converttxttoPDF(string sourcePath, string destPath)
  2. {
  3. try
  4. {
  5. iTextSharp.text.Document document = new iTextSharp.text.Document();
  6. string filename = Path.GetFileNameWithoutExtension(sourcePath);
  7. System.IO.StreamReader myFile = new System.IO.StreamReader(sourcePath);
  8. string myString = myFile.ReadToEnd();
  9. myFile.Close();
  10. if (!Directory.Exists(destPath))
  11. Directory.CreateDirectory(destPath);
  12. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(destPath + "\" + filename + ".pdf", FileMode.CreateNew));
  13. document.Open();
  14. document.Add(new iTextSharp.text.Paragraph(myString));
  15. document.Close();
  16. }
  17. catch (Exception ex)
  18. {
  19. MessageBox.Show(ex.Message);
  20. }
  21. }
  22.  
  23. myString = string.IsNullOrEmpty(myString) ? " " : myString;
  24. document.Add(new iTextSharp.text.Paragraph(myString));
  25.  
  26. Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
  27. wordDocument = word.Documents.Open(savedFileName, ReadOnly: true);
  28. wordDocument.ExportAsFixedFormat(attahcmentPath + "/pdf" + attachment.BetAttachmentCode + ".pdf", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
  29. word.Quit(false);
Add Comment
Please, Sign In to add comment