5

背景: C# と Interop を使用して Word ドキュメントを生成しようとしています。テーブル、ヘッダー、フッター、ダイアグラムの挿入に成功しました.ほとんどのものは正常に機能しています. 次のステップとして、これを pdf に変換しようとしています。

プロセスの適応: Word 2011 と Word 2007 (saveaspdf プラグインをインストールした後) を使用しているため、「名前を付けて保存」を使用してドキュメントを PDF に保存し、ファイルの種類を pdf として保存しています。

発生した問題: 次のコードを使用して、ドキュメントに PDF を埋め込むことができました。

        Object oIconLabel = new FileInfo(file_path).Name;
        Object oFileDesignInfo = file_path;
        Object oClassType = "AcroExch.Document.7";
        Object oTrue = true;
        Object oFalse = false;
        Object oMissing = System.Reflection.Missing.Value;
        Object index = 0;
        Range r = d.Bookmarks.get_Item(ref eod).Range;

        r.InlineShapes.AddOLEObject(
            ref oClassType, ref oFileDesignInfo, ref oFalse, ref oTrue, ref oMissing,
            ref index, ref oIconLabel, ref oMissing);

ここで d は Document オブジェクトです。今、この単語文書をpdfとして保存しようとしたとき、

 d.SaveAs(ref filename, ref filetype, 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);

pdf が生成されています。しかし、私が埋め込んだドキュメントは、生成された pdf に埋め込まれていません。むしろアイコンだけが表示されています。

ドキュメントをpdfに埋め込むにはどうすればよいですか。この種の状況を通常どのように処理しますか。質問が明確でない場合はお知らせください。

4

3 に答える 3

9

それは私が選んだ間違ったAPIです。名前を付けて保存しないでください。ExportAsFixedFormat です。

ドキュメントはここにあります

サンプルの使用方法は

d.ExportAsFixedFormat(filename.ToString(), WdExportFormat.wdExportFormatPDF,false,WdExportOptimizeFor.wdExportOptimizeForOnScreen,
                    WdExportRange.wdExportAllDocument,1,1,WdExportItem.wdExportDocumentContent,true,true,
                    WdExportCreateBookmarks.wdExportCreateHeadingBookmarks,true,true,false,ref oMissing);
于 2012-12-05T19:39:14.413 に答える
4

このコードは、Word文書のテキスト、表、グラフ、および画像でうまく機能します。
サーバーに Word をインストールする必要があります。
Word 2013 を使用していますが、問題ありません。

Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application();

                    object oMissing = System.Reflection.Missing.Value;
                    Object oFalse = false;
                    Object filename = (Object)path;

                    Microsoft.Office.Interop.Word.Document doc = wordApplication.Documents.Open(ref filename, ref oMissing,
                        ref oFalse, 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();

                    var pathfilename = Path.Combine(Server.MapPath("~/UploadDocuments/PDF"), fileName).Replace(".docx", ".pdf"); ;
                    Object filename2 = (Object)pathfilename;

                    doc.SaveAs(ref filename2, WdSaveFormat.wdFormatPDF,
                        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);


                    // close word doc and word app.
                    object saveChanges = WdSaveOptions.wdDoNotSaveChanges;

                    ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);

                    ((_Application)wordApplication).Quit(ref oMissing, ref oMissing, ref oMissing);

                    wordApplication = null;
                    doc = null;
于 2016-06-23T13:04:53.363 に答える
0

関数SaveAsのすべてのパラメーターの意味については、ここを参照してください。

http://msdn.microsoft.com/en-us/library/office/bb256835(v=office.12).aspx

UseISO19005_1 = Trueを使用して、フォントサブセットを埋め込みます

于 2012-08-03T14:18:37.440 に答える