0

My documents are stored in a database that I want to send mail with attachments.

I want to convert stored docx to pdf.

var result = from c in valinor.documents
             select new
             {
                 c.document_name,
                 c.document_size,
                 c.document_content
             };

var kk = result.ToList();
for (int i = 0; i<kk.Count; i++)
{
    MemoryStream stream = new MemoryStream(kk[i].document_content);
    Attachment attachment = new Attachment(stream, kk[i].document_name + ".pdf", "application/pdf");
    mail.Attachments.Add(attachment);
}

How can I convert document_content to pdf?

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
  • 1
    What have you tried? Here's one possibility that the search function returned http://stackoverflow.com/questions/8817623/converting-docx-to-pdf-using-openxml-and-pdfcreator-in-c-sharp –  Mar 12 '13 at 14:17
  • at 'stream' content is doc or pdf – Sankar M Mar 12 '13 at 14:19
  • the stream content a docx –  Mar 12 '13 at 14:38

2 Answers2

1

You need to use Microsoft.Office.Interop.Word in MIcrosoft office dll.

  • add reference to your project Microsoft.Office.Interop.Word
  • Check my sample of Code.

It's nice and Easy. 100% work for me.

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);
Komal12
  • 3,340
  • 4
  • 16
  • 25
0

You will need a third party component such as ABCpdf and (probably) Word installed on the machine and use that component to convert from docx to pdf.

ChrisBint
  • 12,773
  • 6
  • 40
  • 62