使用aspose24.8版本,将一个pdf转换为ppt,再将ppt转换为pdf时,在save方法耗时太长

代码如下

public UUID convertPDFtoPPTX_SlideAsImages(UUID documentGUID) {
        long startTime = System.nanoTime();
        try (InputStream in = iFilePublicService.getFileStream(documentGUID); Document pdfDocument = new Document(in);
            ByteArrayOutputStream pptxBaos = new ByteArrayOutputStream();
            ByteArrayOutputStream pdfBaos = new ByteArrayOutputStream()) {

            // Step 1: Convert PDF to PPTX
            PptxSaveOptions pptxSaveOptions = new PptxSaveOptions();
            pptxSaveOptions.setSlidesAsImages(true);
            pdfDocument.save(pptxBaos, pptxSaveOptions);

            // Step 2: Load PPTX from ByteArrayOutputStream
            try (ByteArrayInputStream pptxBais = new ByteArrayInputStream(pptxBaos.toByteArray());) {
                Presentation presentation = new Presentation(pptxBais);
                presentation.save(pdfBaos, 1);

                LocalDateTime now = LocalDateTime.now();
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
                String timestamp = now.format(formatter);
                return iFilePublicService.uploadFile("convertPDFtoPPTX_SlideAsImages" + timestamp + ".pdf",
                    pdfBaos.toByteArray());
            }
        } catch (Exception e) {
            log.error("Error convertPDFtoPPTX_SlideAsImages and back to PDF", e);
        } finally {
            long endTime = System.nanoTime();
            long duration = endTime - startTime;
            double durationInMillis = (double)duration / 1_000_000;
            log.info("convertPDFtoPPTX_SlideAsImages method took {} ms", durationInMillis);
        }
        return UUIDExtension.Empty;
    }

在执行

pdfDocument.save(pptxBaos, pptxSaveOptions);

需要至少7秒,这是因为什么导致的
这是对应文件
05多单位-有换行-开标情况记录表(30家).pdf (12.6 KB)

相同的代码,转换另外一个文件,全部执行完才需要4s。
对比过字体,没什么差别。
06多单位-无换行-开标情况记录表(37家).pdf (59.9 KB)

@eternalxw

并不总是与字体相关的因素会影响 API 的性能。但文件大小、复杂结构和可用内存等其他因素也会影响操作。即使两个相同的 PDF 也可能具有不同的结构,并可能导致 API 的行为不同。不管怎样,你试过24.11版本吗?您可以使用它吗?如果您发现任何改进,请告诉我们?

升级后并未发生改变,耗时基本一致,请问有什么可以优化的吗

@eternalxw

我们已在内部问题跟踪系统中打开以下新票证,并将根据 Free Support Policies 中提到的条款提供修复。

问题 ID:PDFJAVA-44599

如果您需要优先支持,以及直接联系我们的付费支持管理团队,您可以获取 Paid Support Services

将这代码放到云上之后,部分文件会提示异常

java.lang.ClassCastException: com.aspose.pdf.internal.font.l47u cannot be cast to com.aspose.pdf.internal.font.l37l at com.aspose.pdf.internal.l5k.lI.lI(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l5k.lj.lI(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l4f.lu.lj(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l4f.lu.lb(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l4f.lu.lf(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l4f.lu.lf(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l3l.l2t.lI(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l3l.l2t.lb(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.internal.l3l.ly.lI(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.l6p.lI(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.ADocument.ld(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.ADocument.lt(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.ADocument.lI(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.Document.lI(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.ADocument.save(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.aspose.pdf.Document.save(Unknown Source) ~[aspose-pdf-24.8.jar!/:?] at com.mysoft.czxt.cgsolutionmng.service.domainservice.GptCheckDomainService.convertPDFtoPPTX_SlideAsImages(GptCheckDomainService.java:647) ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at com.mysoft.czxt.cgsolutionmng.service.domainservice.GptCheckDomainService$$FastClassBySpringCGLIB$$c082109.invoke() ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[org.springframework-spring-core-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:792) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) ~[spring-aop-5.3.32.jar!/:5.3.32] at com.mysoft.framework.fasttracker.tracing.TracingAspectConfiguration.customizeTracing(TracingAspectConfiguration.java:107) ~[mysoft-fasttracker-3.0.4.22.jar!/:3.0.4.22] at com.mysoft.framework.fasttracker.tracing.TracingAspectConfiguration.aroundDomainService(TracingAspectConfiguration.java:52) ~[mysoft-fasttracker-3.0.4.22.jar!/:3.0.4.22] at sun.reflect.GeneratedMethodAccessor525.invoke(Unknown Source) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_422] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_422] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:707) ~[spring-aop-5.3.32.jar!/:5.3.32] at com.mysoft.czxt.cgsolutionmng.service.domainservice.GptCheckDomainService$$EnhancerBySpringCGLIB$$f666be33.convertPDFtoPPTX_SlideAsImages() ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at com.mysoft.czxt.cgsolutionmng.service.gptCheckParam.GptCheckPublicService.convertPdf(GptCheckPublicService.java:113) ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at com.mysoft.czxt.cgsolutionmng.service.gptCheckParam.GptCheckPublicService$$FastClassBySpringCGLIB$$2877a483.invoke() ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[org.springframework-spring-core-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:792) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) ~[spring-aop-5.3.32.jar!/:5.3.32] at com.mysoft.framework.fasttracker.tracing.TracingAspectConfiguration.customizeTracing(TracingAspectConfiguration.java:107) ~[mysoft-fasttracker-3.0.4.22.jar!/:3.0.4.22] at com.mysoft.framework.fasttracker.tracing.TracingAspectConfiguration.aroundAppService(TracingAspectConfiguration.java:41) ~[mysoft-fasttracker-3.0.4.22.jar!/:3.0.4.22] at sun.reflect.GeneratedMethodAccessor407.invoke(Unknown Source) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_422] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_422] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:707) ~[spring-aop-5.3.32.jar!/:5.3.32] at com.mysoft.czxt.cgsolutionmng.service.gptCheckParam.GptCheckPublicService$$EnhancerBySpringCGLIB$$f81e44e1.convertPdf() ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at com.mysoft.czxt.cgsolutionmng.service.controller.pubcontroller.GptCheckParamPubController.convertPdf(GptCheckParamPubController.java:51) ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at com.mysoft.czxt.cgsolutionmng.service.controller.pubcontroller.GptCheckParamPubController$$FastClassBySpringCGLIB$$cff3e882.invoke() ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[org.springframework-spring-core-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:792) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) ~[spring-aop-5.3.32.jar!/:5.3.32] at com.mysoft.framework.fasttracker.tracing.TracingAspectConfiguration.customizeTracing(TracingAspectConfiguration.java:107) ~[mysoft-fasttracker-3.0.4.22.jar!/:3.0.4.22] at com.mysoft.framework.fasttracker.tracing.TracingAspectConfiguration.aroundPubAction(TracingAspectConfiguration.java:74) ~[mysoft-fasttracker-3.0.4.22.jar!/:3.0.4.22] at sun.reflect.GeneratedMethodAccessor866.invoke(Unknown Source) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_422] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_422] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762) ~[spring-aop-5.3.32.jar!/:5.3.32] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:707) ~[spring-aop-5.3.32.jar!/:5.3.32] at com.mysoft.czxt.cgsolutionmng.service.controller.pubcontroller.GptCheckParamPubController$$EnhancerBySpringCGLIB$$b8c2083e.convertPdf() ~[czxt-cgsolutionmng-service-5.0.26.0.jar:5.0.26.0] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_422] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_422] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_422] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_422] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[mysoft-spring-web-5.3.32.jar!/:5.3.32] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[mysoft-spring-web-5.3.32.jar!/:5.3.32] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.32.jar!/:5.3.32] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:898) ~[spring-webmvc-5.3.32.jar!/:5.3.32] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:809) ~[spring-webmvc-5.3.32.jar!/:5.3.32] at org.springframework.web.servlet.mvc.method.AbstractHandlerMeth

我本质只是为了将PDF转换为一个PDF扫描件,由PDF直接转换会导致转换后的字体出现乱码,在尝试后才使用这个方案。但现在这个方案在云上也出现异常,那如何才能将一个PDF文件转换为扫描件PDF,并且不会出现乱码?

@eternalxw

看起来这个问题是由于系统中缺少字体而发生的。请确保 PDF 中使用的所有字体均已安装并存在于系统中。如果问题仍然存在,请与我们分享导致此异常的示例 PDF 文档。我们将在我们的环境中测试该场景并相应地解决它。

要创建扫描的 PDF,您可以首先将 PDF 页面转换为图像,然后再次使用这些图像创建新的 PDF 文档。请查看以下文章。

但是现在这个转换的,如果没有字体就会出现乱码或者报错,有没有方案能够想类似截图一样,不需要考虑字体的。

@eternalxw

我们担心 API 中没有这样的功能来转换机器中没有任何字体的 PDF。 API 使用 DOM 方法,将整个文档与必要的资源一起加载到内存中,并且这些资源中也包含字体。它帮助 API 处理文档。因此,我们始终建议安装所有必需的字体。