我正在尝试将PDF转换为PDF/A. 目前我可以使用OpenOffice pdf viewer插件和Jodconverter 2一起完成此操作.但这样做非常麻烦.
有没有人知道我可以用来做这个的任何开源/免费Java库?
到目前为止,我找到了这些开源库,但没有一个支持将PDF转换为PDF/A.
iText
gnujpdf
PDF Box
FOP
JFreeReport
PJX
JPedal
PDFjet
jPod
PDF渲染器
UPDATE
似乎Apache FOP能够将文档(不是PDF文档)转换为PDF/A.
我创建了一个使用JodConverter
和Open-Office
转换excel(.xlsx
)PDF
的应用程序,该应用程序工作正常,但我面临两个问题
输出PDF的页面是A4大小的形式,因为某些工作表内容已被切掉.因为我希望excel的每个工作表都像一个页面一样完整.
没有工作表丢失,如果我的excel有8个工作表我在PDF
输出中只得到两个或三个
即使我们试图pdf
直接从开放办公室转换,它也给出了上述类似的问题
Excel文件 - ss1.xlsx
输出PDF - work.pdf
任何人都可以告诉我一些解决方案
我的代码如下所示
public class MyConverter {
public static void main(String[] args) throws ConnectException {
File inputFile = new File("C:/Users/Work/Desktop/ss1.xlsx");
File outputFile = new File("C:/Users/Work/Desktop/work.pdf");
// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// close the connection
connection.disconnect();
}
Run Code Online (Sandbox Code Playgroud) 我一直在改进文档管理项目,一个要求是在网页中呈现文档(word,pdf等).Pdf可以使用iframe,object或embed标记和servlet进行渲染.但是其他文件如word,excel无法在网页中呈现.我的解决方案是在渲染时将这些文档转换为pdf或html,并像这样渲染它们.我试图用JODCONVERTER转换它们并且它确实转换但是将一个单词(docx)几乎用700页转换为pdf 25-30秒,到html 30-35秒.这太过分了.在事件过程中,等待太多对用户来说并不好.文件将存储在我们的服务器上,而不是其他地方.是否有更快的转换或更好的解决方案?
谢谢!
我有1000个要转换为pdf的.docx文件,因此我编写了一个程序来执行此操作,但是在抛出错误之前,我永远无法浏览所有1000个文件。我使用来启动LibreOffice的无头版本soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;"
。我正在使用LibreOffice 4.2.0.4和JODConverter 2.2.2。这是我的转换代码(在此之前,我只迭代目录中的所有.docx文件):
try {
File inputFile = new File(sourceFile);
if (!inputFile.exists()) {
return -1;
}
File outputFile = new File(destFile);
OpenOfficeConnection connection = new SocketOpenOfficeConnection(host_Str,
Integer.parseInt(port_Str));
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
connection.disconnect();
return 0;
}
catch (ConnectException e) {
System.out.println("Openoffice listener exception!");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
在抛出错误之前,我始终可以转换至少50个文件;这是我遇到的错误之一:
Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException:
conversion failed: could not save output document; OOo errorCode: 3088
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(OpenOfficeDocumentConverter.java:142)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.convertInternal(OpenOfficeDocumentConverter.java:120)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:104)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:74)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:70)
at …
Run Code Online (Sandbox Code Playgroud) 我工作的软件来存储法律文件,我在想,PDF可能是工作的理想格式.但是我,什么将最适合在这方面的PDF文件的实际格式我的需求有点困惑.
我对文件有以下要求:
我最初看的是使用PDF/A-1但是我发现这种格式似乎不喜欢使用JPEG图像,或者至少在使用JODConverter时没有.
任何关于哪种格式最能满足这些需求的建议/解释都将不胜感激!
我试图让 JODConverter 在带有 Jdk 1.8.0_144 的 Window 10 上工作。正如您从代码中看到的,我认为这可能是一个时间问题,因此延迟。如您所见,JODConverter 认为 OfficeManager 正在运行。我正在使用以下代码:
import java.io.File;
import org.jodconverter.JodConverter;
import org.jodconverter.office.LocalOfficeManager;
import org.jodconverter.office.OfficeException;
import org.jodconverter.office.OfficeManager;
import org.jodconverter.office.OfficeUtils;
import org.jodconverter.process.ProcessManager;
public class JodConverterTest {
public static void main(String[] args) throws OfficeException, InterruptedException {
OfficeManager officeManager
= LocalOfficeManager.builder()
.officeHome("C:\\Program Files\\LibreOffice")
.portNumbers(2372)
.build();
officeManager.start();
File inputFile = new File("c:\\test\\rtf.rtf");
File outputFile = new File("c:\\test\\rtf.pdf");
try {
System.out.println("officeManager.isRunning()="+officeManager.isRunning());
Thread.sleep(10000);
System.out.println("officeManager.isRunning()="+officeManager.isRunning());
JodConverter.convert(inputFile).to(outputFile).execute();
} finally {
// Stop the office process
OfficeUtils.stopQuietly(officeManager);
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行时出现以下错误:-
officeManager.isRunning()=true
officeManager.isRunning()=true
Exception …
Run Code Online (Sandbox Code Playgroud) 我正在使用JODConverter将.xls和.ppt转换为.pdf格式.为此,我有类似的代码
try{
//do something
System.out.println("connecting to open office");
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
System.out.println("connection object created");
connection.connect();
System.out.println("connection to open office successful");
//do something
if(!successful)
throw new FileNotFoundException();
}catch(Exception e){
System.out.println("hello here");
System.out.println("Caught Exception while converting to PDF ");
LOGGER.error("Error in converting media" + e.getMessage());
throw new MediaConversionFailedException();
}finally{
decode_pdf.closePdfFile();
System.out.println("coming in finally");
//do something here
}
Run Code Online (Sandbox Code Playgroud)
我的输出:
connecting to open office
connection object created
coming in finally
Run Code Online (Sandbox Code Playgroud)
PS返回类型的方法是 void
这怎么可能 ?即使connection.connect()中存在一些问题,它也会进入catch块.困惑
我正在使用 JodConverter 将我的 .docx (Microsoft Office) 文件转换为 pdf 但不知何故它没有隐藏并给我错误。版本 2.2.0 。
我的问题是是否可以使用 JODCoverter 将 .docx 文件转换为 pdf?
为什么我得到以下异常..
几天我坚持这个问题..
请帮我..
INFO: ProcessManager implementation is WindowsProcessManager
org.artofsolving.jodconverter.office.OfficeException: failed to start and connect
at org.artofsolving.jodconverter.office.ManagedOfficeProcess.startAndWait(ManagedOfficeProcess.java:61)
at org.artofsolving.jodconverter.office.PooledOfficeManager.start(PooledOfficeManager.java:102)
at org.artofsolving.jodconverter.office.ProcessPoolOfficeManager.start(ProcessPoolOfficeManager.java:59)
at com.hiringsteps.ats.util.service.impl.UtilService.convertWord2Pdf(UtilService.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy51.convertWord2Pdf(Unknown Source)
at com.hiringsteps.ats.applicant.facade.impl.ApplicantFacade.convert2PdfNHighlight(ApplicantFacade.java:553)
at com.hiringsteps.ats.applicant.facade.impl.ApplicantFacade.register(ApplicantFacade.java:433)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at …
Run Code Online (Sandbox Code Playgroud) jodconverter ×9
java ×8
pdf ×3
docx ×1
exception ×1
html5 ×1
libreoffice ×1
ms-office ×1
netbeans ×1
pdfa ×1
program-flow ×1
servlets ×1
try-catch ×1
xlsx ×1