当前位置:首页 > 代码 > 正文

c代码转换pdf(C代码转换汇编)

admin 发布:2022-12-19 23:01 177


本篇文章给大家谈谈c代码转换pdf,以及C代码转换汇编对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

怎么用C语言读取PDF文件

1.pdf(Portable Document Format的简称,意为“便携式文档格式”),是由Adobe Systems用于与应用程序、操作系统、硬件无关的方式进行文件交换所发展出的文件格式。PDF文件以PostScript语言图象模型为基础,无论在哪种打印机上都可保证精确的颜色和准确的打印效果,即PDF会忠实地再现原稿的每一个字符、颜色以及图象。

2.对于程序来说,不管后缀名如何,文件分为两种类型:文本文件和二进制文件。

C语言里有一系列文件操作函数。区分文本和二进制文件,需要在打开文件时设置不同的控制符mode的变量即可。

3.fopen的函数原型:FILE * fopen(const char * path,const char * mode);

fopen函数的第一个参数是文件路径,第二个参数是打开方式,有以下几种方式:

r 以只读方式打开文件,该文件必须存在。

r+ 以可读写方式打开文件,该文件必须存在。

rb+ 读写打开一个二进制文件,允许读数据。

rw+ 读写打开一个文本文件,允许读和写。

w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若文件不存在则建立该文件。

w+ 打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。

a 以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)

a+ 以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 (原来的EOF符不保留)

wb 只写打开或新建一个二进制文件;只允许写数据。

wb+ 读写打开或建立一个二进制文件,允许读和写。

wt+ 读写打开或着建立一个文本文件;允许读写。

at+ 读写打开一个文本文件,允许读或在文本末追加数据。

ab+ 读写打开一个二进制文件,允许读或在文件末追加数据。

上述的形态字符串都可以再加一个b字符,如rb、w+b或ab+等组合,加入b 字符用来告诉函数库打开的文件为二进制文件,而非纯文字文件。

关于用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");

}

}

供你参考啊

有什么方法生成pdf文件,c

可以使用虚拟打印机来处理:

方法一:使用虚拟打印机pdf factory即可,而且其他格式文件只要是能够打印,选择这个虚拟打印机,都可以做成PDF文件,很简单实用;

方法二:用其他虚拟打印机转成PDF文件。

方法三:使用专门的转换软件,把文件转成PDF文件。

关于c代码转换pdf和C代码转换汇编的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/29029.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载