如何使用C#将word文件拆分成多个pdf文件 [英] How to split word file into multiple pdf files using C#

查看:112
本文介绍了如何使用C#将word文件拆分成多个pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有word file.i想将word文件的每一页转换成不同的pdf文件。



我尝试了什么:



将word文件的每一页转换为pdf

There is word file.i want to convert each page of word file into different pdf files.

What I have tried:

Convert each page of word file into pdf

推荐答案

这是适用于我的解决方案

此代码片段需要任何解释,因为它很清楚。



Here is the solution that worked for me
This code snippet needs any explanation, because it's clear to understand.

using Word = Microsoft.Office.Interop.Word;
.
.
.
object FileName = @"c:\WordDocument.docx";
object falseValue = false; 
object missingValue = Missing.Value;
Word.Application wordApplication = new Word.Application();
Word.Document wordDocument = wordApplication.Documents.Open(ref FileName,
ref missingValue, ref missingValue, ref missingValue, ref missingValue, 
ref missingValue, ref missingValue, ref missingValue, ref missingValue, 
ref missingValue, ref missingValue, ref missingValue, ref missingValue, 
ref missingValue, ref missingValue, ref missingValue);
         
object EndOfPage = @"\page";
object wdWhat = WdGoToItem.wdGoToPage;
object wdWich = WdGoToDirection.wdGoToNext;
object count = (object)1;
int TotalPages, i;

TotalPages = wordDocument.ComputeStatistics(WdStatistic.wdStatisticPages, ref falseValue);

for (i = 1; i <= TotalPages; i++)
{
   //Select the content of actual page.
   Word.Range range  = wordDocument.Bookmarks.get_Item(ref EndOfPage).Range;
   //Export selected Range to PDF
   range.ExportAsFixedFormat(path, Word.WdExportFormat.wdExportFormatPDF);
   //Move to next Page
   range = range.GoTo(ref wdWhat, ref wdWich, ref count, ref missingValue);
   range.Select();
}


这篇关于如何使用C#将word文件拆分成多个pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆