Exporting A Report from Code

Stimulsoft Reports.JAVA discussion
Post Reply
User avatar
milver.silva
Posts: 8
Joined: Sat May 02, 2020 3:19 pm
Location: Brazil

Exporting A Report from Code

Post by milver.silva »

I'm trying to use the same code as the example below to export the report to pdf

Link:
https://github.com/stimulsoft/Samples-J ... mCode.java

When I run the application, it runs normally.

Image
Image
Image
Image

but when i try to export to pdf it shows an error, throwing an exception. Is there any solution for this problem? :( :( :(


Image

----------------------------
[Customer Explanation]


----------------------------
[General Info]

Application: Stimulsoft Reports.JAVA
Version: 2023.1.8 from 24 February 2023, Java
JAVA Version: 19.0.2+7-44
OSVersion: Windows 11 amd64 10.0
UserName: Milver Silva

----------------------------
[Exception Info]
Message: Error export PDF

Cause: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "f2d" is null

StackTrace:
com.stimulsoft.base.exception.StiException: Error export PDF
at com.stimulsoft.report.export.service.StiPdfExportService.exportPdf(StiPdfExportService.java:6865)
at com.stimulsoft.report.export.service.StiPdfExportService.export(StiPdfExportService.java:6848)
at com.stimulsoft.report.StiExportManager.export(StiExportManager.java:210)
at com.stimulsoft.report.StiExportManager.exportPdf(StiExportManager.java:45)
at com.stimulsoft.report.StiExportManager.exportPdf(StiExportManager.java:41)
at com.stimulsoft.samples.ExportingAReportfromCode.export(ExportingAReportfromCode.java:200)
at com.stimulsoft.samples.ExportingAReportfromCode$1.actionPerformed(ExportingAReportfromCode.java:47)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6620)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3398)
at java.desktop/java.awt.Component.processEvent(Component.java:6385)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4995)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4827)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4827)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "f2d" is null
at com.stimulsoft.base.utils.StiFontHelper.getFontFile(StiFontHelper.java:107)
at com.stimulsoft.base.utils.StiFontHelper.getFontData(StiFontHelper.java:35)
at com.stimulsoft.report.export.tools.pdf.PdfFonts.getFontData(PdfFonts.java:311)
at com.stimulsoft.report.export.tools.pdf.PdfFonts.getFontDataBuf(PdfFonts.java:2062)
at com.stimulsoft.report.export.service.StiPdfExportService.renderFontTable(StiPdfExportService.java:2194)
at com.stimulsoft.report.export.service.StiPdfExportService.exportPdfException(StiPdfExportService.java:8002)
at com.stimulsoft.report.export.service.StiPdfExportService.exportPdf(StiPdfExportService.java:6863)
... 41 more


----------------------------
Milver Silva
Business Partner
Belém - Pará - Brasil
E-mail: milver.silva@gmail.com
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: Exporting A Report from Code

Post by Vadim »

Hello

This means that your system not allow to embed font file info PDF, please in StiPdfExportSettings setup setEmbeddedFonts(false)
User avatar
milver.silva
Posts: 8
Joined: Sat May 02, 2020 3:19 pm
Location: Brazil

Re: Exporting A Report from Code

Post by milver.silva »

My code:
Image

But it still generated an exception!


----------------------------
[Customer Explanation]


----------------------------
[General Info]

Application: Stimulsoft Reports.JAVA
Version: 2023.1.8 from 08 December 2022, Java
JAVA Version: 19.0.2+7-44
OSVersion: Windows 11 amd64 10.0
UserName: Milver Silva

----------------------------
[Exception Info]
Message: Error export PDF

Cause: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "f2d" is null

StackTrace:
com.stimulsoft.base.exception.StiException: Error export PDF
at com.stimulsoft.report.export.service.StiPdfExportService.exportPdf(StiPdfExportService.java:6865)
at com.stimulsoft.report.export.service.StiPdfExportService.export(StiPdfExportService.java:6848)
at com.stimulsoft.report.StiExportManager.export(StiExportManager.java:210)
at com.stimulsoft.report.StiExportManager.exportPdf(StiExportManager.java:45)
at com.stimulsoft.report.StiExportManager.exportPdf(StiExportManager.java:41)
at com.stimulsoft.samples.ExportingAReportfromCode.export(ExportingAReportfromCode.java:202)
at com.stimulsoft.samples.ExportingAReportfromCode$1.actionPerformed(ExportingAReportfromCode.java:49)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6620)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3398)
at java.desktop/java.awt.Component.processEvent(Component.java:6385)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4995)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4827)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4827)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "f2d" is null
at com.stimulsoft.base.utils.StiFontHelper.getFontFile(StiFontHelper.java:107)
at com.stimulsoft.base.utils.StiFontHelper.getFontData(StiFontHelper.java:35)
at com.stimulsoft.report.export.tools.pdf.PdfFonts.getFontData(PdfFonts.java:311)
at com.stimulsoft.report.export.tools.pdf.PdfFonts.getFontDataBuf(PdfFonts.java:2062)
at com.stimulsoft.report.export.service.StiPdfExportService.renderFontTable(StiPdfExportService.java:2194)
at com.stimulsoft.report.export.service.StiPdfExportService.exportPdfException(StiPdfExportService.java:8002)
at com.stimulsoft.report.export.service.StiPdfExportService.exportPdf(StiPdfExportService.java:6863)
... 41 more


----------------------------
Milver Silva
Business Partner
Belém - Pará - Brasil
E-mail: milver.silva@gmail.com
User avatar
milver.silva
Posts: 8
Joined: Sat May 02, 2020 3:19 pm
Location: Brazil

Re: Exporting A Report from Code

Post by milver.silva »

Sorry, I missed passing the settings in the method call

Code: Select all

StiPdfExportSettings pdfExportSettings = new StiPdfExportSettings();
pdfExportSettings.setEmbeddedFonts(false);
StiExportManager.exportPdf(report, pdfExportSettings, outputStream);
It worked perfectly, thank you very much!
Milver Silva
Business Partner
Belém - Pará - Brasil
E-mail: milver.silva@gmail.com
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Exporting A Report from Code

Post by Lech Kulikowski »

Hello,

You are welcome.
Post Reply