Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Oct 06, 2025 9:24 am

Im trying to do a side project with liferay and using this library as an integration.
I have some issue from retrieving the file when i use the DL.
The file actually is correctly retrieved ( i saw it from some log) but when i try to open a new PdfDocument it says incorrect format.
If i try this library offline, with the same pdf passed via absolute path it works. What's happening?

Code: Select all
DLFolder sheetFolder = DLFolderLocalServiceUtil.fetchFolder(prescription.getGroupId(), folder.getFolderId(), prescriptionSheetTitle);
                        if (Validator.isNotNull(sheetFolder)) {
                            _log.info("sheetFolder is not null: " + sheetFolder.getName());
                            List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getFileEntries(sheetFolder.getGroupId(), sheetFolder.getFolderId());
                            List<DLFileEntry> activeFileEntries = dlFileEntries.stream()
                                    .filter(dlFileEntry -> !dlFileEntry.isInTrash())
                                    .collect(Collectors.toList());
                            activeFileEntries.forEach(_log::info);
                            if (ListUtil.isNotEmpty(activeFileEntries)) {
                                DLFileEntry dlFileEntry = activeFileEntries.get(GetterUtil.DEFAULT_INTEGER);
                                    _log.info("[getStreamPrescriptionPDF] [getFileName]"
                                            + "[" + dlFileEntry.getFileName()  + "]"
                                    );

                                IcebluePDFExporterImpl icebluePDFExporter = new IcebluePDFExporterImpl();
                                byte[] bytes = icebluePDFExporter.replaceToken(reportPDFFields, dlFileEntry.getContentStream(), system, locale);
//                                AsposePDFExporterImpl icebluePDFExporter = new AsposePDFExporterImpl();
//                                byte[] bytes = icebluePDFExporter.replaceToken(reportPDFFields, dlFileEntry.getContentStream(), system, locale);

                                return bytes;
                            }


Code: Select all
 pdfDocument = new PdfDocument();
            try{
            pdfDocument.loadFromStream(inputStreamTemplate);
//                pdfDocument.loadFromFile(inputPath);
            } catch (Exception e) {
                if(_log.isErrorEnabled()){
                    _log.error("[replaceToken] [cannot load file] [" + e.getMessage() + "]");
                }
                throw new RuntimeException(e);
            }


with error:
Caused by: com.liferay.portal.kernel.log.LogSanitizerException: class com.spire.pdf.packages.sprblo: PDF file structure is not valid__com.spire.pdf.packages.sprffp.<init>(Unknown Source)__com.spire.pdf.packages.sprffp.<init>(Unknown Source)__com.spire.pdf.PdfDocument.spr┐⌾(Unknown Source)__com.spire.pdf.PdfDocument.loadFromStream(Unknown Source)__it.reply.open.vivisol.iceblue.pdf.exporter.impl.IcebluePDFExporterImpl.replaceToken(IcebluePDFExporterImpl.java:122)__it.reply.open.vivisol.iceblue.web.command.GeneratePdfActionCommand.getStreamPrescriptionPDF(GeneratePdfActionCommand.java:359)__it.reply.open.vivisol.iceblue.web.command.GeneratePdfActionCommand.doProcessAction(GeneratePdfActionCommand.java:110)__com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand.processAction(BaseMVCActionCommand.java:48)__com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:393)__com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:75)__com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:247)__com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:68)__com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:41)__com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:105)__javax.servlet.http.HttpServlet.service(HttpServlet.java:623)__org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:147)__org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:63)__org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)__org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)__com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:562)__com.liferay.portlet.internal.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:602)__com.liferay.portlet.internal.InvokerPortletImpl.processAction(InvokerPortletImpl.java:280)__com.liferay.portlet.internal.PortletContainerImpl._processAction(PortletContainerImpl.java:495)__com.liferay.portlet.internal.PortletContainerImpl.lambda$processAction$0(PortletContainerImpl.java:139)__com.liferay.portlet.internal.PortletContainerImpl._preserveGroupIds(PortletContainerImpl.java:402)__com.liferay.portlet.internal.PortletContainerImpl.processAction(PortletContainerImpl.java:132)__com.liferay.portlet.SecurityPortletContainerWrapper.processAction(SecurityPortletContainerWrapper.java:73)__com.liferay.portlet.RestrictPortletContainerWrapper.processAction(RestrictPortletContainerWrapper.java:63)__com.liferay.portal.kernel.portlet.PortletContainerUtil.processAction(PortletContainerUtil.java:108)__com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:361)__com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:165)__com.liferay.portal.struts.PortalRequestProcessor._process(PortalRequestProcessor.java:377)__com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:143)__com.liferay.portal.internal.servlet.MainServlet.doGet(MainServlet.java:193)__javax.servlet.http.HttpServlet.service(HttpServlet.java:529)__com.liferay.portal.internal.servlet.MainServlet.service(MainServlet.java:581)__javax.servlet.http.HttpServlet.service(HttpServlet.java:623)__com.liferay.shielded.container.internal.proxy.ServletWrapper.service(ServletWrapper.java:103)__org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:199)__org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)__org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)__org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)__org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:117)__it.reply.open.vivisol.registration.web.filter.IncompleteRegistrationFilter.processFilter(IncompleteRegistrationFilter.java:61)__com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:42)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)__com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:152)__com.liferay.change.tracking.internal.servlet.filter.CTCollectionPreviewFilter.processFilter(CTCollectionPreviewFilter.java:57)__com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:42)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)__com.liferay.portal.servlet.filters.password.modified.PasswordModifiedFilter.processFilter(PasswordModifiedFilter.java:47)__com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:42)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)__com.liferay.portal.servlet.filters.lockout.LockoutFilter.processFilter(LockoutFilter.java:49)__com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:42)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)__com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:152)__com.liferay.portal.servlet.filters.secure.BaseAuthFilter.processFilter(BaseAuthFilter.java:341)__com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:42)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)__com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:114)__com.liferay.shielded.container.internal.proxy.FilterWrapper.doFilter(FilterWrapper.java:69)__org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:168)__org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)__org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:621)__org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:401)__org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:340)__org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:285)__com.liferay.friendly.url.internal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:570)__javax.servlet.http.HttpServlet.service(HttpServlet.java:623)__com.liferay.portal.servlet.ServletAdapter.service(ServletAdapter.java:89)__javax.servlet.http.HttpServlet.service(HttpServlet.java:623)__com.liferay.shielded.container.i


any suggests?

jadinard
 
Posts: 13
Joined: Wed Aug 13, 2025 2:25 pm

Tue Oct 07, 2025 2:48 am

Hello,

Thank you for your inquiry. Regarding the issue you encountered with the "pdfDocument.loadFromStream (inputStreamTemplate);", we suggest that you first save the "inputStreamTemplate" data as a PDF document and confirm if there are any problems with the saved PDF document. If the Stream saved PDF document itself has problems opening, our product will also have abnormal reading. If the saved PDF document has no problem opening itself, are you currently testing with our latest version "Spire.PDF Pack (Hotfix) Version: 11.9.17"? If you are not using the latest version, we recommend testing it with our latest version again. If there are still issues, you can provide the saved PDF document for us to further analyze. You can provide it here or send by email “[email protected]".

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1510
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF