Universal Document Converter
Informazioni sul prodotto
Scarica
Acquista
Tutorial
Soluzioni per sviluppatori
Servizio di assistenza
Chi è fCoder SIA


      Cerca nel sito
   


      Conversioni più richieste
Da Adobe PDF a JPEG
Da documento Word a PDF
Da foglio di lavoro Excel a PDF
Da PowerPoint a JPEG
Da disegno Visio a PDF
Da disegno AutoCAD a TIFF
Da pagina Web a JPEG
Convertire di lavoro Excel in PDF
Convertire da DjVu in PDF
Pagine Web in PDF



Pagina principale>Developer Solutions>Examples>Visual C#>Word Documents to PDF

Converting Word Documents to PDF


//////////////////////////////////////////////////////////////////////////////////////////////////// // This example was designed for using in Microsoft Visual C# from // Microsoft Visual Studio 2003 or above. // // 1. Microsoft Word 97 or above should be installed and activated on your PC. // // 2. Universal Document Converter 5.2 or above should be installed, too. // // 3. Add references to "Microsoft Word XX.0 Object Library" and "Universal Document Converter Type Library" // using the Project | Add Reference menu > COM tab. // XX is the Microsoft Office version installed on your computer. // // 4. Notice that the number of Microsoft Word's method parameters may depend on the Office version. //////////////////////////////////////////////////////////////////////////////////////////////////// using System; using System.IO; using Word = Microsoft.Office.Interop.Word; //using Word; in VS2003 using UDC; namespace WordToPDF { class Program { static void PrintWordToPDF(string WordDocFilePath) { //Create a UDC object and get its interfaces IUDC objUDC = new APIWrapper(); IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter"); IProfile Profile = Printer.Profile; //Use Universal Document Converter API to change settings of convertered document Profile.PageSetup.ResolutionX = 600; Profile.PageSetup.ResolutionY = 600; Profile.FileFormat.ActualFormat = FormatID.FMT_PDF; Profile.FileFormat.PDF.ColorSpace = ColorSpaceID.CS_TRUECOLOR; Profile.FileFormat.PDF.Multipage = MultipageModeID.MM_MULTI; Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED; Profile.OutputLocation.FolderPath = @"c:\UDC Output Files"; Profile.OutputLocation.FileName = @"&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]"; Profile.OutputLocation.OverwriteExistingFile = false; //Create a Word's Application object Word.Application WordApp = new Word.Application(); Object FilePath = WordDocFilePath; Object ReadOnly = true; Object Missing = Type.Missing; //This will be passed when ever we don’t want to pass value //Open document from file Word.Document WordDoc = WordApp.Documents.Open(ref FilePath, ref Missing, ref ReadOnly, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing); //Print all pages of the document Object Background = false; WordApp.ActivePrinter = "Universal Document Converter"; WordApp.PrintOut(ref Background, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing); //Close the document Object SaveChanges = false; WordDoc.Close(ref SaveChanges, ref Missing, ref Missing); //Quit the word application WordApp.Quit(ref Missing, ref Missing, ref Missing); } static void Main(string[] args) { string TestFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFile.doc"); PrintWordToPDF(TestFilePath); } } }


© fCoder SIA Chi è fCoder SIA | Mappa del sito