Probleme mit ExportASFixedFormat aus Word 2007

eagle1985

Mitglied
Hallo zusammen,

bin ziemlich Neu in .Net und kenne mich mit dem .Net-Framework und C# noch nicht so gut aus.

Probiere gerade ein wenig mit der Office-Steuerung aus dem .Net-Framework 2.0 rum.

Habe nun folgendes Problem:

Beim Export als PDF kommt immer die Meldung, dass der docStructTags ausserhalb des erwarteten Bereichs ist.

Habe mich auf msdn mal umgesehen aber keinen treffenden Grund dafür Gefunden. Kann es sein, dass ich die falsche Version der .Net-Library habe oder so?

Hier noch meinen Code:

Ich öffne Word, erstelle ein Document, ersetzte ein paar Texte und will dass ganze anschliessend als PDF speichern und das Word wieder Schliessen.

Wenn der PDF Export auskommentiert wird, funktioniert es soweit Problemlos.

Code:
using System;
using Microsoft.Office.Interop.Word;

namespace Office2007Steuerung 
{
    class MainProgramm
    {
        public static void Main(String[] args)
        {
            new MainProgramm();
        }

        public MainProgramm()
        {
            // Init des Server
            // Word öffnen
            Application wordApp = null;
            wordApp = new Application();
            wordApp.ScreenUpdating = true;
            wordApp.Visible = true;

            // Document öffnen
            Object oTemplate = "";
            Object oNewTemplate = false;
            Object oDocType = WdNewDocumentType.wdNewBlankDocument;
            Object oVisible = true;
            try
            {
                wordApp.Documents.Add(ref oTemplate, ref oNewTemplate, ref oDocType, ref oVisible);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            wordApp.ScreenRefresh();
            wordApp.Selection.TypeText("Ich du und der Esel wir sind 3");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText("EselEselEsel");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText("Ich du und der esel wir sind 3");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText("Ich du und der eSeL wir sind 3");
            wordApp.Selection.TypeParagraph();
            wordApp.Selection.TypeText("Esel der du fliegst im Himmel so frei wie ein eseL");
            wordApp.Selection.TypeParagraph();

            Object oFindText = "Esel";
            Object oReplaceText = "Vogel";
            Object oForward = true;
            Object oWrap = WdFindWrap.wdFindContinue;
            Object oFormat = false;
            Object oMatchCase = false;
            Object oMatchWholeWord = false;
            Object oMatchWildcards = false;
            Object oMatchSoundsLike = false;
            Object oMatchAllWordForms = false;
            Object oReplaceAll = WdReplace.wdReplaceAll;
            Object oFalse = false;

            wordApp.Selection.Find.Execute(ref oFindText, ref oMatchCase, ref oMatchWholeWord, ref oMatchWildcards, ref oMatchSoundsLike, ref oMatchAllWordForms, ref oForward, ref oWrap, ref oFormat, ref oReplaceText, ref oReplaceAll, ref oFalse, ref oFalse, ref oFalse, ref oFalse);

            wordApp.ScreenRefresh();

            // Als PDF speichern
            String pdfFileName = "C:\\Dokumente und Einstellungen\\user\\Eigene Dateien\\dummy-test.pdf";
            WdExportFormat exportFormat = WdExportFormat.wdExportFormatPDF;
            Boolean openAfterExport = true;
            WdExportOptimizeFor optimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
            WdExportRange docRange = WdExportRange.wdExportAllDocument;
            int from = 0;
            int to = 0;
            WdExportItem exportItem = WdExportItem.wdExportDocumentContent;
            Boolean includeDocProp = true;
            Boolean keepIRM = true;
            WdExportCreateBookmarks createBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
            bool docStructTags = true;
            Boolean bitmapMissingFonts = true;
            Boolean isPDFA = false;
            Object fixedFormatExtClassPtr = null;

//            try
//            {
                wordApp.ActiveDocument.ExportAsFixedFormat(pdfFileName, exportFormat, openAfterExport, optimizeFor, docRange, from, to, exportItem, includeDocProp, keepIRM, createBookmarks, docStructTags, bitmapMissingFonts, isPDFA, ref fixedFormatExtClassPtr);
//            }
//            catch (Exception e)
//            {
//                Console.WriteLine(e.Message);
//                Console.WriteLine(e.StackTrace);
//            }

            // Word schliessen
            //Object saveChanges = WdSaveOptions.wdSaveChanges;
            Object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
            Object oriFormat = WdOriginalFormat.wdOriginalDocumentFormat;
            //Object oFalse = false;
            wordApp.Quit(ref saveChanges, ref oriFormat, ref oFalse);
            
            
        }
    }
}

Entwicklungsumgebung: Microsoft Visual C@ 2008 Express Edition
.Net-Framework: glaube Version 2.0
Office-Version: Word 2007 mit Plugin Export as PDF/XPS

hoffe ihr könnt mir da Helfen

greez
 
Zurück