導航:首頁 > 文檔加密 > c語言應用編程pdf

c語言應用編程pdf

發布時間:2025-08-15 17:26:00

Ⅰ 關於用C#生成pdf

是否可以考慮使用WordDocument.SendFax方法?

參考一下這個java的程序,你有一些收獲。
java 實現word轉為 tif格式??急

1.我用列印的方式沒有得到任何文件(用的是虛擬傳真列印機)
2.我用JACOB老是缺少組建異常
3.用jawin調用word轉為pdf的方法出異常

1.我用列印的方式沒有得到任何文件(用的是虛擬傳真列印機)

public class Y {
/*列印指定的文件*/
public void printFileAction()
{
//構造一個文件選擇器,默認為當前目錄
JFileChooser fileChooser = new JFileChooser("c:\\");
int state = fileChooser.showOpenDialog(null);//彈出文件選擇對話框
if (state == fileChooser.APPROVE_OPTION)//如果用戶選定了文件
{
File file = fileChooser.getSelectedFile();//獲取選擇的文件
//構建列印請求屬性集
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//設置列印格式,因為未確定文件類型,這里選擇AUTOSENSE
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//查找所有的可用列印服務
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
//定位默認的列印服務
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
//顯示列印對話框
PrintService service = ServiceUI.printDialog(null, 200, 200, printService
, defaultService, flavor, pras);
if (service != null)
{
try
{
DocPrintJob job = service.createPrintJob();//創建列印作業
FileInputStream fis = new FileInputStream(file);//構造待列印的文件流
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);//建立列印文件格式
job.print(doc, pras);//進行文件的列印
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}

}

2.我用JACOB老是缺少組建異常
package com;
import com.jacob.com.*;
import com.jacob.activeX.*;

public class Dispatch_MSWord {
private ActiveXComponent wordCom=null;
private Object wordDoc=null;
private final Variant False=new Variant(false);
private final Variant True=new Variant(true);

/**
* 打開word文檔
* @param filePath word文檔
* @return 返回word文檔對象
*/
public boolean openWord(String filePath){
//建立ActiveX部件
wordCom=new ActiveXComponent("Word.Application");

try{
//返回wrdCom.Documents的Dispatch
Object wrdDocs=wordCom.getProperty("Documents").toDispatch();
//調用wrdCom.Documents.Open方法打開指定的word文檔,返回wordDoc
wordDoc=Dispatch.invoke((Dispatch) wrdDocs,"Open",Dispatch.Method,new Object[]{filePath},new int[1]).toDispatch();
return true;
}
catch(Exception ex){
ex.printStackTrace();
}
return false;
}

/**
* 關閉word文檔
*/
public void closeWord(){
//關閉word文件
wordCom.invoke("Quit",new Variant[]{});
}

/**
* 打開word,調用word中的宏
* @param filePath word文件路徑
* @param macroName 被調用的宏名字
* @param parameter 調用宏的參數數組
*/
public void callWordMacro(String filePath,String macroName,Object parameter[]){

if (!openWord(filePath)){
closeWord();
return;
}
else{
//使用方法傳入的參數parameter調用word文檔中的MyWordMacro宏
Dispatch.invoke((Dispatch)wordDoc,macroName,Dispatch.Method,parameter,new int[1]);
closeWord();
}
}

/**
* 打開word,替換其中的文字
* @param filePath word文件路徑
* @param sourceStr 源文字
* @param replaceStr 替換後的文字
*/
public void callReplaceWord(String filePath,String sourceStr,String replaceStr){

if (!openWord(filePath)){
closeWord();
return;
}

try{
//獲得Selection對象
Dispatch selectDoc=wordCom.getProperty("Selection").toDispatch();
//獲得Find對象
Dispatch find = Dispatch.call(selectDoc,"Find").toDispatch();

//設置替換的方法屬性,但是不支持ReplaceWith的屬性,而且使用Replancement.Text屬性也無濟於事。
Dispatch.put(find,"Text",sourceStr);

//所以使用Find對象的Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)方法
//詳細內容見MSDN的office2000開發文檔
Variant True=new Variant(true);
Variant False=new Variant(false);
Variant FindText=new Variant(sourceStr);
Variant ReplaceWith=new Variant(replaceStr);
Variant Format=False;
Variant Forward=True;
Variant MatchCase=True;
Variant MatchWholeWord=True;
Variant MatchWildcards=False;
Variant MatchSoundsLike=False;
Variant MatchAllWordForms=False;
int wdFindWrap_FindContinue=1;
Variant Wrap=new Variant(wdFindWrap_FindContinue);
int wdReplace_ReplaceAll=2;
Variant Replace=new Variant(wdReplace_ReplaceAll);

//使用callN方法調用execute方法
Dispatch.callN(find,"Execute",new Variant[]{
FindText, MatchCase, MatchWholeWord, MatchWildcards,
MatchSoundsLike, MatchAllWordForms, Forward, Wrap,
Format, ReplaceWith, Replace
});
Dispatch.invoke((Dispatch) wordDoc,"SaveAs",Dispatch.Method,new Object[]{"c:\\111.doc"},new int[1]);
closeWord();
}
catch(Exception ex){
ex.printStackTrace();
}
finally{
closeWord();
}
}

/**
* 將word文檔列印為PS文件後,使用Distiller將PS文件轉換為PDF文件
* @param sourceFilePath 源文件路徑
* @param destinPSFilePath 首先生成的PS文件路徑
* @param destinPDFFilePath 生成PDF文件路徑
*/
public void docToPDF(String sourceFilePath,String destinPSFilePath,String destinPDFFilePath){
if (!openWord(sourceFilePath)){
closeWord();
return;
}
//建立Adobe Distiller的com對象
ActiveXComponent distiller=new ActiveXComponent("PDFDistiller.PDFDistiller.1");
try{
//設置當前使用的列印機,我的Adobe Distiller列印機名字為"Adobe PDF"
wordCom.setProperty("ActivePrinter",new Variant("Adobe PDF"));

//設置printout的參數,將word文檔列印為postscript文檔。目前只使用了前5個參數,如果要使用更多的話可以參考MSDN的office開發相關api
//是否在後台運行
Variant Background=False;
//是否追加列印
Variant Append =False;
//列印所有文檔
int wdPrintAllDocument=0;
Variant Range =new Variant(wdPrintAllDocument);
//輸出的postscript文件的路徑
Variant OutputFileName =new Variant(destinPSFilePath);

//調用word文檔對象的PrintOut方法:將word文檔列印為postscript文檔,簡稱ps文檔
Dispatch.callN((Dispatch)wordDoc, "PrintOut", new Variant[]{Background,Append,Range,OutputFileName}) ;

System.out.println("由word文檔列印為ps文檔成功!");

//調用Distiller對象的FileToPDF方法所用的參數,詳細內容參考Distiller Api手冊
//作為輸入的ps文檔路徑
Variant inputPostScriptFilePath=new Variant(destinPSFilePath);
//作為輸出的pdf文檔的路徑
Variant outputPDFFilePath=new Variant(destinPDFFilePath);
//定義FileToPDF方法要使用adobe pdf設置文件的路徑,在這里沒有賦值表示並不使用pdf配置文件
Variant PDFOption=new Variant("");
//調用FileToPDF方法將ps文檔轉換為pdf文檔
Dispatch.callN(distiller,"FileToPDF",new Variant[]{inputPostScriptFilePath,outputPDFFilePath,PDFOption});
System.out.println("由ps文檔轉換為pdf文檔成功!");

}
catch(Exception ex){
ex.printStackTrace();
}
finally{
closeWord();
}
}

public static void main(String[] argv){
Dispatch_MSWord d=new Dispatch_MSWord();
//d.callWordMacro("E:/eclipse3.1RC3/workspace/jacobPractice/src/com/bjinfotech/practice/jacob/MacroTest.doc","MyWordMacro",new String[]{"這是調用word宏的測試程序"});
//d.callReplaceWord("E:/eclipse3.1RC3/workspace/jacobPractice/src/com/bjinfotech/practice/jacob/MacroTest.doc","$TITLE$","文字已經被替換");
d.docToPDF("c:\\1.doc","c:\\1p.ps","c:\\1p.pdf");
}

}

供你參考啊

Ⅱ microsoft visual c++可以導出pdf嗎

你好,是可以導出pdf的,安裝Adobe Acrobat XI Pro軟體,用Adobe PDF列印機列印你要輸出的內容,即可得到你要的PDF文檔。

拓展 Microsoft Visual C++

Microsoft Visual C++是由Microsoft公司開發的一款便捷實用的C語言編程工具,具有集成開發環境。Microsoft Visual C++具備很多微軟的運行組件,使得用戶在運行軟體或游戲的時候可獲得安全的運行環境。

希望我的回答能夠幫助到您。

閱讀全文

與c語言應用編程pdf相關的資料

熱點內容
單片機期末試卷 瀏覽:555
phpregisterglobal 瀏覽:407
android常用命令 瀏覽:671
什麼p圖app可以加隸書字體 瀏覽:968
安卓手機的全景聲怎麼用 瀏覽:545
ubuntu系統如何連接區域網內的伺服器 瀏覽:918
加州與紐約源碼 瀏覽:424
聽中央財經新聞用什麼APP 瀏覽:57
拜占庭pdf 瀏覽:735
七牛phpsdk 瀏覽:699
網吧能找到游戲的文件夾嗎 瀏覽:715
程序員項目組專用名 瀏覽:998
程序員的項目提成 瀏覽:99
adb解壓下載 瀏覽:784
寄語app是干什麼的 瀏覽:765
廣聯達加密鎖安裝盤如何 瀏覽:6
貴陽移動dns伺服器地址 瀏覽:285
高光機編程變數 瀏覽:956
linuxjava安裝目錄 瀏覽:244
瑜伽程序員訓練 瀏覽:732