1

Wrestling to create PDF in Coldfusion using the following block with no success:

<cfset FileInputStream = CreateObject("java", "java.io.FileInputStream") >
<cfset File = CreateObject("java", "java.io.File")>

<cfset lic = CreateObject("java", "com.aspose.pdf.License")>
<cfset lic.setLicense(FileInputStream.init(File.init("E:\Tomcat\webapps\openbd\Aspose.Pdf.lic")))>


<cfset Document = CreateObject("java", "com.aspose.pdf.Document").init() >
<cfset demo_pdf = Document.init() >

<cfset Section = CreateObject("java", "aspose.pdf.Section").init() >
<cfset Text = CreateObject("java", "aspose.pdf.Text").init() >

<cfset sec1 = section.demo_pdf.getSections().add() >
<cfset sec1.getParagraphs().add(Text.init("Τέσσερα"))>
<cfset demo_pdf.save("E:\Tomcat\webapps\openbd\HelloWorld.pdf")>

The error produced is: "java.lang.NoSuchFieldException" on line:"cfset sec1 = section.demo_pdf.getSections().add()". What am i supposed to do in order to generate PDFs using java aspose PDF lib under openBD CFML engine?

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
  • The easy way to create a pdf with ColdFusion is with the cfdocument tag. Do you have a reason to not use it? – Dan Bracuk May 15 '14 at 16:26
  • 1
    He is using OpenBD, not ColdFusion. That could be the reason for not using `cfdocument`. Also, I would argue that `cfdocument` is not the easiest way to create properly formatted PDFs. @anarchos check out http://wkhtmltopdf.org/ easy to use and apply formatting. – Scott Stroz May 15 '14 at 16:29
  • The reason that i don't use cfdocument is that the PDFs that i generate is not in supported by openBD engine language [greek fonts]. Same issue on Railo. –  May 15 '14 at 17:06
  • @Scott Stroz. How do i use it in conjunction with openBD? –  May 15 '14 at 17:08
  • 2
    First, you would need to build the content in HTML and save that HTML to disk. Next, you use `cfexecute` to call the wkhtml2pdf process to generate the PDF and write it to disk. Next, you would use `cfcontent` to serve up the PDF (and delete it if you want). Finally And optionally, delete the HTML file from disk. Sounds like a lot, but it is pretty easy, actually. – Scott Stroz May 15 '14 at 19:36
  • You _may_ run into the same font issues with wkhtml2pdf, but I am not certain. – Scott Stroz May 15 '14 at 19:37
  • 1
    @Scott Stroz. At a first glance, it seems not to have any issues with the fonts. 1 up! –  May 16 '14 at 05:47

2 Answers2

3

I work as Social Media Developer at Aspose. You need to use "aspose.pdf.Pdf" class instead of "com.aspose.pdf.Document" class. See the following updated sample:

<cfset demo_pdf = CreateObject("java", "aspose.pdf.Pdf").init() >

<cfset section = CreateObject("java", "aspose.pdf.Section").init() >
<cfset text = CreateObject("java", "aspose.pdf.Text").init("Hello World") >

<cfset sec1 = demo_pdf.getSections().add() >
<cfset sec1.getParagraphs().add(text)>
<cfset demo_pdf.save("c:\data\HelloWorld.pdf")>

Update based on comments:

You can add <cfset demo_pdf.setUnicode()> before the save statement to include the TrueType font to be used for your Greek Charaters.

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • @Aslam I accept this answer, but after a trial i figured that aspose library cannot print Greek like: `Κατά τη συζήτηση`. Is there any way to draw Greek characters? –  May 16 '14 at 13:37
  • 1
    You can add before the save statement to include the TrueType font to be used for your Greek Charaters. – Nausherwan Aslam May 16 '14 at 16:29
  • @Aslam. Could you give me an example? How to add TrueType Fonts. –  May 16 '14 at 17:28
0

In reference to your last comment, try the following code:

<cfset demo_pdf = CreateObject("java", "aspose.pdf.Pdf").init() >
<cfset section = CreateObject("java", "aspose.pdf.Section").init() >
<cfset sec1 = demo_pdf.getSections().add() >
<cfset text = CreateObject("java", "aspose.pdf.Text").init("Κατά τη συζήτηση") >
<cfset text.getTextInfo().setFontName("Arial Unicode MS")>
<cfset sec1.getParagraphs().add(text)>
<cfset demo_pdf.setUnicode()>
<cfset demo_pdf.save("c:\HelloWorld.pdf")>