CrystalCmd is a Java program to load json files into crystal reports and produce PDFs.
Originally was designed as toy, a proof of concept, to see if mono and now .net core apps can generate basic crystal reports on linux using a java implementation.
Note that, when using the command line option, this is very slow and highly recommended to use the server option.
test server: c.majorsilence.com
Example running from base CrystalCmd folder.
curl https://c.majorsilence.com/status
curl -F "reportdata=@test.json" -F "reporttemplate=@the_dataset_report.rpt" https://c.majorsilence.com/export --output testout.pdf
# test localhost
curl -F "reportdata=@test.json" -F "reporttemplate=@the_dataset_report.rpt" http://127.0.0.1:4321/export --output testout.pdf
CrystalCmd upports running as a command line tool. Pass in path to report, data, and output fileand a pdf is generated.
java -jar CrystalCmd.jar -reportpath "/path/to/report.rpt" -datafile "/path/to/data.json" -outpath "/path/to/generated/file.pdf"
example 2
java -jar CrystalCmd.jar -reportpath "/home/peter/Projects/CrystalCmd/the_dataset_report.rpt" -datafile "/home/peter/Projects/CrystalCmd/test.json" -outpath "/home/peter/Projects/CrystalCmd/java/CrystalCmd/build/output.pdf"
CrystalCmd supports running in server mode. If you runn it with no command line arguments it starts a web server listending on port 4321. There are two end points that can be called.
- http://localhost:4321/status
- http://localhost:4321/export
- Returns pdf as bytestream
- Must be passed two post variables as byte arrays
- reporttemplate
- reportdata
Run the server.
java -jar CrystalCmd.jar
Call the server.
curl -F "reporttemplate=@the_dataset_report.rpt" -F "reportdata=@test.json" http://localhost:4321/export > myoutputfile.pdf
docker run -p 2005:4321 -t majorsilence/crystalcmd
Or run it as a daemon.
docker run -p 2005:4321 -d majorsilence/crystalcmd
Now check the status in your browser:
install
snap install ./java/CrystalCmd/build/CrystalCmd.snap --force-dangerous --classic
run
crystalcmd -reportpath "/home/peter/Projects/CrystalWrapper/the_dataset_report.rpt" -datafile "/home/peter/Projects/CrystalWrapper/test.json" -outpath "/home/peter/Projects/CrystalWrapper/Java/build/output.pdf"
sudo ./build_snap.sh
sudo apt-get install openjdk-16-jdk
Download eclipse java edition.
Setup eclipse with crystal references.
Import java/CrystalCmd folder as ecplise project (Eclipse -> File -> Open Projects from File System).
Download intelliJ community edition.
sudo apt-get install openjdk-16-jre
- Eclipse -> File -> Export -> Java -> Runnable Jar File
Package required libraries into generated JAR
output as "CrystalCmd.jar" in folder ./CrystalCmd/java/CrystalCmd/build
Use this project to generate test data from c# program
https://origin.softwaredownloads.sap.com/public/site/index.html
After some experimentation, a workaround was to create the fonts folder in the AdoptOpenJDK JRE (jre\lib\fonts) and copy a single font file from the Linux msttcorefonts mentioned above into the newly created fonts folder. My document uses all Arial font, but it doesn't seem to matter what font file is in the fonts folder. I copied Webdings.ttf. The file does have to be a real font file. I tried making a dummy text file and rename it to Webdings.ttf, but the NPE occurred with the dummy font file.
Once a real font is copied to jre\lib\fonts, The PDF is created just fine with the Arial font embedded. It seems that there just has to be a one real font at jre\lib\fonts to get started, and then crjava/AdoptOpenJDK will eventually use fontconfig to find the correct Windows font.
Example:
Copy a file to C:\Users[UserName].jdks\openjdk-16.0.1\lib\fonts from C:\Windows\Fonts.