convertir doc en pdf en c #

Comment puis-je convertir. Doc au format PDF en utilisant asp.net c #. Je ne peux utiliser aucun composant tiers.

Le code devrait être dans

  1. C # ou vb.net
  2. Compatible avec VS 2005. (Si non, merci de poster vos réponses, je les convertirais manuellement en VS 2005)

Faites-moi savoir si une requête.

Merci!

private Microsoft.Office.Interop.Word.ApplicationClass MSdoc; //Use for the parameter whose type are not known or say Missing object Unknown = Type.Missing; private void word2PDF(object Source, object Target) { //Creating the instance of Word Application if (MSdoc == null)MSdoc = new Microsoft.Office.Interop.Word.ApplicationClass(); try { MSdoc.Visible = false; MSdoc.Documents.Open(ref Source, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); MSdoc.Application.Visible = false; MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize; object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; MSdoc.ActiveDocument.SaveAs(ref Target, ref format, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); } catch (Exception e) { MessageBox.Show(e.Message); } finally { if (MSdoc != null) { MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown); //WordDoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown); } // for closing the application WordDoc.Quit(ref Unknown, ref Unknown, ref Unknown); } } 

Conditions préalables:

  • MS word2007 avec (l’assemblage d’interopérabilité primaire sera installé par défaut).
  • plugin SaveAsPDFandXPS (gratuit à partir du site MS)

Assurez-vous que vous avez référence à Word.12. Il appenda automatiquement Microsoft.Office.interop.word à votre référence. Suivez-les pour une autre application de bureau. (Remarque: vous devez avoir installé VS 2005 Tools pour Office 2e Édition. Runtime (VSTO 2005 SE) (x86)

 //Add Office Library using Word = Microsoft.Office.Interop.Word; object str_letter_path = @"D:\DOCTEST.doc"; object outputFilePathPDF = @"D:\PDFTEST.PDF"; Word.Application wordApp = new Word.Application(); wordApp.Visible = false; wordApp.ScreenUpdating = false; object oMissing = System.Reflection.Missing.Value; object fileFormat = Word.WdSaveFormat.wdFormatPDF; Word.Document doc = wordApp.Documents.Open(ref str_letter_path, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); doc.Activate(); doc.SaveAs(ref outputFilePathPDF, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges; if (doc != null) ((Word._Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing); ((Microsoft.Office.Interop.Word._Application)wordApp).Quit(ref saveChanges, ref oMissing, ref oMissing);