转换为PDF时删除.doc复制 [英] Remove .doc duplication when converted to PDF

查看:68
本文介绍了转换为PDF时删除.doc复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前有一个程序,通过用户输入和FileBrowserDialog将包含word文档的文件夹合并为一个组合文件。选择文件后,组合按钮将应用下面显示的代码,该代码将包含文档,输出位置和创建文件名称的文件夹。

Hello, I currently have a program that merges a folder consisting of word docs into one combined file via user input with a FileBrowserDialog. Once files are selected, a 'combine' button applies the code shown below which sources the folder containing the documents, output location and name of the file created.

string fileDate = DateTime.Now.ToString("dd-MM-yy");
string fileTime = DateTime.Now.ToString("HH.mm.ss");
string outcomeFolder = outputFolder;
string outputFileType = ".docx";
string outputFile = "Combined Folder " + fileDate + " @ " + fileTime + outputFileType;
string outputFileName = Path.Combine(outcomeFolder, outputFile);
        
// Combines the file name, output path selected and the yes / no for pagebreaks. 
MsWord.Merge(sourceFiles, outputFileName, pageBreaker);

// Message displaying how many files are combined. 
MessageBox.Show("A total of " + sourceFiles.Length.ToString() + " documents have been merged", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);}



MsWord引用的调用一个单独的.CS文件,它结合了文件夹组件,输出名称和布尔值来启用分页符。一旦成功组合文件夹的内容,MsWord还会自动将单词.doc保存到用户指定的位置。


The MsWord referenced calls a separate .CS file which combines the folder components, output name and a boolean to enable page-breaks. The MsWord also automatically saves the word .doc to the user specified location once the contents of the folder are successfully combined.

MsWord.Merge(sourceFiles, outputFileName, pageBreaker);



我想要解决的问题是我启用复选框


The issue i'm wanting to address is when I enable the check box

if (convert2PDFBox.Checked)
Microsoft.Office.Interop.Word.Application officeApp = new Microsoft.Office.Interop.Word.Application();

officeApp.Documents.Open(outputFileName);
outputFileType = ".pdf";
officeApp.ActiveDocument.SaveAs(outputFileName + outputFileType, WdSaveFormat.wdFormatPDF);
officeApp.Quit();



我希望程序只创建组合文件夹的PDF而不是2个单独的.doc和.PDF文件,其中它目前的确如此。由于MsWord.save函数是单独调用的,并且对我的程序的整体功能至关重要,我想知道一旦PDF转换发生,是否有可能删除最初组合的文件?例如combinedDocument。删除 - 基本上允许复制,但不向用户显示初始.doc - 只有.PDF



虽然问题很小,但我希望能够解决这个问题并以这种方式欢迎任何建议或建议。如果需要,我也可以提供任何其他信息,谢谢。



我的尝试:



我尝试使用ActiveDocument.SaveAs而不是转换,但是如前所述,问题在于转换前正在形成的文件。


I want the program to solely create a PDF of the combined folder and not 2 seperate .doc and .PDF files, which it currently does. Since the MsWord.save function is called separately and is essential to the overall function of my program, I was wondering is there a possibility of deleting the initially combined file once conversion of the PDF takes place? e.g. "combinedDocument".Delete - Essentially allowing the copy to take place however not presenting the user with the initial .doc - only the .PDF

Though the issue is small, I would love to get it addressed and welcome any suggestions or advice with this manner. I can also provide any additional information if needed, thank you.

What I have tried:

i've attempted using ActiveDocument.SaveAs as opposed to conversion, however as mentioned the issue is with the file being formed before conversion.

推荐答案

问题已经解决,我能够编辑调用的MsMerge命令并在cs中应用转换为PDF,名为

Issue was resolved, i was able to edit the MsMerge command called and applied a conversion to PDF there within the cs called
wordApplication.ActiveDocument.SaveAs(outputFile, Word.WdSaveFormat.wdFormatPDF);



i然后删除word文档的另存为默认值:


i then removed the Save As default of the word document:

wordApplication.Quit(
false, // save changes



这删除了保存创建为Word.Doc的文件的提示,因此只创建PDF格式


this removed the prompt to save the file created as Word.Doc, thus only creating the PDF format


这篇关于转换为PDF时删除.doc复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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