当前位置:网站首页>Preview of converting doc and PDF to SWF file
Preview of converting doc and PDF to SWF file
2022-04-23 03:11:00 【AutoCrud】
One 、 install openoffice.org
The main modules are writer( Text document ),impress( Presentation ),Calc( The spreadsheet ),Draw( mapping ),Math( The formula ),base( database )
I downloaded is openoffice.org 3.3.0. Download and install directly .
however , We need to start openoffice server. There are two ways :
1. Start... From the command line openoffice server, The disadvantage is that every time the system restarts , All need to be manually openoffice server start-up .
2. take openoffice server Start as a service of the operating system , Now that it has become a system service , You can set the startup to start automatically .
Let's look at the first way ,
1. Start... From the command line openoffice server
stay cmd Under orders ,cd opeonofiice Installation path for /program Such as :cd c:\program files\openoffice.org 3\program\soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
2. Start as a system service
We still need Windows Resource Kit tools, take openoffice server Set as system service .
Windows Resource Kit tools Microsoft is designed for managers 、 Developed by developers and advanced users , Including management activities Catalog 、 Group Policy 、TCP/IP The Internet 、 notes Books and tables 、 System security 、 monitoring And so on Windows Server 2003 Other aspects of the operating system are In many aspects Unconventionally installed tool components .Resource Kit Tools for XP The release of made XP Users can also use Resource Kit Tools Deal with these problems .
download windows resource kit tools, We do the default installation .
1. open Windows Resource Kit Tools
stay Command Shell Execute the following command :
"C:\Program Files\Windows Resource Kits\Tools\instsrv" OpenOfficeUnoServer "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
Open management tools -> Services can be found to OpenOfficeUnoServer Named Services
2. Open the registry to find the following path
HKEY_LOCAL_MACHINE -> SYSTEM ->ControlSet001 ->Services ->OpenOfficeUnoServer
New item Parameters, Add two string values under this item :
key:Application
value:C:\Program Files\OpenOffice.org 3\program\soffice.exe
key:AppParameters
value:-invisible -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard
3. In the service console , start-up openoffice service
4. stay CMD Use the following command to view 8100 Whether it has been monitored :netstat -anop tcp
such OpenOffice3.0 Just run as a service in Windows System on the .( Use cmd command :netstat -anp tcp see 8100 Whether the port works )
Then you can pass socket Way to connect openOffice, To use the openoffice Some services provided , Such as file conversion service ,ms office turn pdf wait .
Open source project JODConverter It's a combination openoffice For document conversion java Components .
There is also a command line tool swftools, This tool can make pdf Convert to swf The format of the document , Provide to ie Client browsing .
Two 、 Use JODConverter take office Document conversion to pdf
JODConverter It's a java Of OpenDucument File converter , Many file formats can be converted , It USES
OpenOffice To do the conversion work , It can do the following conversion work :
1.Microsoft Office Format conversion to OpenDucument, as well as OpenDucument Convert to Microsoft Office
2.OpenDucument Convert to PDF,Word、Excel、PowerPoint Convert to PDF,RTF Convert to PDF etc. .
It's an open source project .
My project is in eclipse Under development .
Download the latest version jodconverter-2.2.2, hold lib The package of the folder is imported into your DocConverter Project lib In the folder .
package ...
import java.io.File;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
public class DOC2PDFUtil extends Thread{
private File inputFile;
private File outputFile;
public DOC2PDFUtil(File inputFile,File outputFile){
this.inputFile = inputFile;
this.outputFile = outputFile;
}
public void docToPdf(){
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
try{
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
}catch (Exception e) {
e.printStackTrace();
}finally{
if(connection != null){
connection.disconnect();
connection = null;
}
}
}
public void run(){
this.docToPdf();
}
public File getInputFile() {
return inputFile;
}
public void setInputFile(File inputFile) {
this.inputFile = inputFile;
}
public File getOutputFile() {
return outputFile;
}
public void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}
public static void main(String[] args) {
File inputFile = new File("E://attachment// Drought system testing problem .docx");
File outputFile = new File("E://attachment// Drought system testing problem .pdf");
DOC2PDFUtil dp = new DOC2PDFUtil(inputFile, outputFile);
dp.start();
}
}
3、 ... and 、 Use swftools take pdf Turn into swf
install swftools, Be careful : It is better not to have spaces in the installation path
package ...
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class PDF2SWFUtil {
public static synchronized void pdf2swf(String fileDir,String exePath) throws IOException{
String filePath = fileDir.substring(0,fileDir.lastIndexOf("/"));
String fileName = fileDir.substring(filePath.length() + 1,fileDir.lastIndexOf("."));
Process pro = null;
if(isWindowsSystem()){
String cmd = exePath + " \"" + fileDir + " \" -o \"" + filePath + "/" + fileName + ".swf\"";
System.out.println(cmd);
pro = Runtime.getRuntime().exec(cmd);
}else{
String[] cmd = new String[3];
cmd[0] = exePath;
cmd[1] = fileDir;
cmd[2] = filePath + "/" + fileName + ".swf";
pro = Runtime.getRuntime().exec(cmd);
}
new DoOutPut(pro.getInputStream()).start();
new DoOutPut(pro.getErrorStream()).start();
try {
pro.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static boolean isWindowsSystem(){
String p = System.getProperty("os.name");
return p.toLowerCase().indexOf("windows")>=0?true:false;
}
private static class DoOutPut extends Thread{
public InputStream is;
public DoOutPut(InputStream is){
this.is = is;
}
public void run(){
BufferedReader br = new BufferedReader(new InputStreamReader(this.is));
String str = null;
try{
while((str = br.readLine()) != null);
}catch (Exception e) {
e.printStackTrace();
}finally{
if(br != null){
try{
br.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
public static void main(String[] args){
String exePath = "D:/SWFTools/pdf2swf.exe";
try{
pdf2swf("E:/attachment/ Drought system testing problem .docx", exePath);
}catch(IOException e){
e.printStackTrace();
}
}
}
Four 、office Document conversion to pdf, Convert colleagues to swf
package ...
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
public class DocConverter {
private int environment=1;
private String fileName;
private File pdfFile;
private File swfFile;
private File docFile;
private String command;
public DocConverter(String fileString,String command){
this.command = command;
ini(fileString);
}
private void ini(String fileString){
if(isWindowsSystem()){
environment = 1;
}else{
environment = 2;
}
fileName = fileString.substring(0,fileString.lastIndexOf("."));
docFile = new File(fileString);
pdfFile = new File(fileName+".pdf");
swfFile = new File(fileName+".swf");
}
private boolean isWindowsSystem(){
String p = System.getProperty("os.name");
return p.toLowerCase().indexOf("windows")>=0?true:false;
}
private void doc2pdf() throws Exception{
if(docFile.exists()){
if(!pdfFile.exists()){
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
try{
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(docFile, pdfFile);
connection.disconnect();
}catch (java.net.ConnectException e) {
e.printStackTrace();
System.out.println("....swf Convert exceptions ,openoffice Service not started !");
throw e;
}catch (OpenOfficeException e) {
e.printStackTrace();
System.out.println(".....swf Converter anomaly , Read file conversion failed !");
throw e;
}catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
else
{
System.out.println("**** Has been converted to pdf, There's no need to transform ****");
}
}
else
{
System.out.println("****swf Converter anomaly , The document to be converted does not exist , Unable to convert ****");
}
}
/*
* convert to swf
*/
private void pdf2swf() throws Exception
{
Runtime r=Runtime.getRuntime();
if(!swfFile.exists())
{
if(pdfFile.exists())
{
if(environment==1)//windows Environmental treatment
{
try {
Process p=r.exec( command + " " +pdfFile.getPath() + " -o " + swfFile.getPath() + " -T 9");
System.out.print(loadStream(p.getInputStream()));
System.err.print(loadStream(p.getErrorStream()));
System.out.print(loadStream(p.getInputStream()));
System.err.println("****swf Conversion success , File output :"+swfFile.getPath()+"****");
// if(pdfFile.exists())
// {
// pdfFile.delete();
// }
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
else if(environment==2)//linux Environmental treatment
{
try {
Process p=r.exec("pdf2swf "+ pdfFile.getPath()+" -o "+swfFile.getPath()+" -T 9");
System.out.print(loadStream(p.getInputStream()));
System.err.print(loadStream(p.getErrorStream()));
System.err.println("****swf Conversion success , File output :"+swfFile.getPath()+"****");
if(pdfFile.exists())
{
pdfFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
else {
System.out.println("****pdf non-existent , Unable to convert ****");
}
}
else {
System.out.println("****swf There is no need to convert ****");
}
}
static String loadStream(InputStream in) throws IOException
{
int ptr=0;
in=new BufferedInputStream(in);
StringBuffer buffer=new StringBuffer();
while((ptr=in.read())!=-1)
{
buffer.append((char)ptr);
}
return buffer.toString();
}
/*
* Convert the main method
*/
public boolean conver()
{
if(swfFile.exists())
{
System.out.println("****swf The converter is working , The file has been converted to swf****");
return true;
}
if(environment==1)
{
System.out.println("****swf The converter is working , Currently set the running environment windows****");
}
else {
System.out.println("****swf The converter is working , Currently set the running environment linux****");
}
try {
doc2pdf();
pdf2swf();
} catch (Exception e) {
e.printStackTrace();
return false;
}
if(swfFile.exists())
{
return true;
}
else {
return false;
}
}
/*
* Return file path
* @param s
*/
public String getswfPath()
{
if(swfFile.exists())
{
String tempString =swfFile.getPath();
tempString=tempString.replaceAll("\\\\", "/");
return tempString;
}
else{
return "";
}
}
/*
* Set output path
*/
public void setOutputPath(String outputPath)
{
if(!outputPath.equals(""))
{
String realName=fileName.substring(fileName.lastIndexOf("/"),fileName.lastIndexOf("."));
if(outputPath.charAt(outputPath.length())=='/')
{
swfFile=new File(outputPath+realName+".swf");
}
else
{
swfFile=new File(outputPath+realName+".swf");
}
}
}
public static void main(String s[])
{
DocConverter d=new DocConverter("E:/attachment/1405391789462/1405391789462.docx","D:/SWFTools/pdf2swf.exe");
d.conver();
}
}
版权声明
本文为[AutoCrud]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220628598370.html
边栏推荐
- Use of slice grammar sugar in C #
- Blazor University (12) - component lifecycle
- Blazor University (11) component - replace attributes of subcomponents
- 使用栈来解决”迷你语法分析器“的问题
- . net core current limiting control - aspnetcoreratelimit
- The most easy to understand dependency injection and control inversion
- 先中二叉建树
- Laravel new route file
- This new feature of C 11, I would like to call it the strongest!
- Blazor University (11)组件 — 替换子组件的属性
猜你喜欢

Blazor University (12) - component lifecycle

ASP.NET和ASP.NETCore多环境配置对比

《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案

2022年度Top9的任务管理系统

Yes Redis using distributed cache in NE6 webapi

微软是如何解决 PC 端程序多开问题的

荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比

Recursion - outputs continuously increasing numbers
![[Mysql] LEFT函数 | RIGHT函数](/img/26/82e0f2280de011636c26931a74e749.png)
[Mysql] LEFT函数 | RIGHT函数

ASP.NET 6 中间件系列 - 自定义中间件类
随机推荐
.NET点滴:说说Middleware构造中获取不到Scoped服务的问题
C read / write binary file
How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
Tencent video price rise: earn more than 7.4 billion a year! Pay attention to me to receive Tencent VIP members, and the weekly card is as low as 7 yuan
If the deep replication of objects is realized through C #?
C语言实现通讯录----(静态版本)
Mysql database, inconsistent index character set, slow SQL query, interface timeout
編碼電機PID調試(速度環|比特置環|跟隨)
C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
ASP.NET和ASP.NETCore多环境配置对比
MYSQL03_ SQL overview, rules and specifications, basic select statements, display table structure
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
Fundamentals of software testing and development
一套组合拳,打造一款 IDEA 护眼方案
使用split来解决“最常见的单词”问题
ASP. Net 6 middleware series - Custom middleware classes
Miniapi of. Net7 (special section): NET7 Preview3
一套关于 内存对齐 的C#面试题,做错的人很多!
Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
Systemctl start Prometheus + grafana environment