What if you do what the error message is suggesting? Change the name
of the module in send_doc_helper.rb to be SendDocHelper instead of
SendDoc, and change
helper :send_doc
include SendDoc
to
helper :send_doc
include SendDocHelper
Fred
I still have to try the suggestion from Fred but I got it to work on
my development machine. I had to jump through some loops, but it does
work.
I can now develop and test a report with iReport and call it from Ruby
on Rails.
If anyone is interested let me know and I will post some additional
information on how I got it to work.
Best regards
Peter De Berdt
@Peter
It's based on http://wiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports
, so it's command line and it's fast enough for me.
Where do you think I should put the Wiki description ?
does jasper reports work on a shared hosting plan?
On the
http://wiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports
page in the example xml code it has an inconsistency ?
'LIST' (opening reference,versus, 'LOOKUP' closing reference)
Would that cause a problem ?
I'm struggling to follow this tutorial. :(
<?xml version="1.0" encoding="UTF-8"?>
<customer_list_result>
......
</customer_lookup_result>
Denis
--
Posted via http://www.ruby-forum.com/.
'The file is damaged and could not be repaired'.
I suspect a typo in Document.rb , and I've looked at it 'till I'm blue
in the face and cannot see it....
Are all the path references correct ? I had to insert a reference to
'app/' into the original tutorial code before the path in
Dir.foreach("/jasper/lib"
else I got a message :
Errno::ENOENT in CustomersController#report
No such file or directory - jasper/lib
Anybody spot a typo below ?
(Win XP = ROR ver 1.7.)
Denis
-----------------------------------------------------------
class Document < ActiveRecord::Base
include Config
def self.generate_report(xml_data, report_design, output_type,
select_criteria)
report_design << '.jasper' if !report_design.match(/\.jasper$/)
interface_classpath=Dir.getwd+"/jasper/bin"
case CONFIG['host']
when /mswin32/
Dir.foreach("/app/jasper/lib") do |file|
interface_classpath << ";#{Dir.getwd}/jasper/lib/"+file if
(file != '.' and file != '..' and file.match(/.jar/))
flash[:notice] = interface_classpath
end
else
Dir.foreach("/app/jasper/lib") do |file|
interface_classpath << ":#{Dir.getwd}/app/jasper/lib/"+file if
(file != '.' and file != '..' and file.match(/.jar/))
end
end
result=nil
IO.popen "java -Djava.awt.headless=true -cp
\"#{interface_classpath}\" XmlJasperInterface -o#{output_type}
-f#{Dir.getwd}/app/reports/#{report_design} -x#{select_criteria}", "w+"
do |pipe|
pipe.write xml_data
pipe.close_write
result = pipe.read
pipe.close
end
return result
end
end
-------------------------------------------------------------------
Thank for your suggestion. I've actually re-installed everything from
ground zero, because I had tried everything to resolve this issue.
In the process I've upgraded to RoR ver 2.0 (I has been at 1.7). That
involved jumping through a few hoops. I re installed iReports 2.0.4 and
JasperReports 2.0.5(very recent release)
I had double checked the lib replication dimension, and they were
identical, save for a version indicator in one file :- Log4J
files...(two). I've used the latest version 1.2.13.
Just for the record....
Directory of C:\InstantRails\rails_apps.......jasper\lib
13/12/2006 10:20 188,671 commons-beanutils-1.7.jar
08/12/2003 20:50 165,119 commons-collections-2.1.jar
15/01/2008 20:32 26,388 commons-logging-1.0.2.jar
01/07/2005 13:21 1,553,403 itext-1.3.1.jar
15/01/2008 20:32 1,922,698 jasperreports-2.0.4.jar
20/12/2005 17:45 294,514 jcommon-1.0.0.jar
15/01/2008 20:32 1,212,369 jdt-compiler-3.1.1.jar
20/12/2005 17:45 1,072,312 jfreechart-1.0.0.jar
04/12/2005 18:00 358,180 log4j-1.2.13.jar
22/08/2007 15:48 909,270 poi-3.0.1-FINAL-20070705.jar
15/07/2004 22:46 1,781,922 xalan.jar
Directory of C:\jasper\iReport-2.0.4\lib
<snip>
15/01/2008 20:32 188,671 commons-beanutils-1.7.jar
15/01/2008 20:32 165,119 commons-collections-2.1.jar
15/01/2008 20:32 26,388 commons-logging-1.0.2.jar
15/01/2008 20:32 18,404 commons-logging-api-1.0.2.jar
15/01/2008 20:32 1,553,403 itext-1.3.1.jar
15/01/2008 20:32 1,922,698 jasperreports-2.0.4.jar
15/01/2008 20:32 1,212,369 jdt-compiler-3.1.1.jar
15/01/2008 20:32 1,072,312 jfreechart-1.0.0.jar
15/01/2008 20:32 352,668 log4j-1.2.8.jar
15/01/2008 20:32 352,291 log4j-1.2.9.jar
15/01/2008 20:32 909,270 poi-3.0.1-FINAL-20070705.jar
15/01/2008 20:32 1,781,922 xalan.jar
Having re-checked everything and still having an Adobe launch with a
corrupt file error, I tried it on another PC. It also has ROR version
2.0 , did NOT have ireports or Jasper installed, save for the files
copied to the ...app/jasper/lib.
Amazing ! It worked :) . Let joy be unconfined.
Now to figure out why that has happened ?
My PC is :- IntelDualCore , 4 Gig Ram, Win XP SR2 , Java version SE
1.6.0_05-b13. InternetExplorer ver 7.0.5730.11
(This PC is dual boot with Vista 64).
The other PC is;- IntelDualCore , 2 Gig Ram, Win XP SR1 , Java version
1.5.03. InternetExplorer ver 6.
The value set returned by Request.env are more detailed on the former...
I tested this by pasting some code into a view in mycookbook.com - as
the simplest available environment.
See http://wiki.rubyonrails.org/rails/pages/VariablesInRequestEnv
I'm still puzzled as to why it should work on one PC and not another.
Since the application was simply copied from one PC to the other as a
folder within the rails_apps directory - with additionally copying the
MySQL data folder.
If i do not resolve this, I could not deploy to any particular PC
without the overhead of checking this aspect for all possible reports to
generated... ?
Any thoughts on why the variance ? Seems like an environment issue ?
Sorry for goingon so long .
Thanks for your interests and contributions here :)
Regards,
Happy St. Patrick's day( tomorrow) from ireland :)
Denis
20/12/2005 17:45 294,514 jcommon-1.0.0.jar IS in ROR lib
04/12/2005 18:00 358,180 log4j-1.2.13.jar IS in ROR lib
15/01/2008 20:32 352,668 log4j-1.2.8.jar IS in ROR lib
15/01/2008 20:32 352,291 log4j-1.2.9.jar IS in ROR lib
15/01/2008 20:32 18,404 commons-logging-api-1.0.2.jar not in ROR lib
Meahwhile the saga continues.....
I've finaly got JasperXMLInterface and Ruby to work - consistently every
time, producing PDF docs. (I did have to amend some of the suggested
code to fix a path error - omission of APP at one point)
Now for the wrinkle..
It was intermittemtly breaking, and it took me a while pin it down.
Reproduce the problem by;
run pdf report - works successfully, save it.
close pdf
close browser
close ruby console
close rails applicatiom dialog box
I -> configure database vis MyPHPAdmin
select Customer table
Insert a record , save , browse
close MyPHP
I -> Rails applications -> Manage Rails applications
Select app,
Start it with Mongrel*(ruby console opens)
select http://localhost:3000/customer_report (should produce a pdf
listing customers)
Adobe Reader displays an error message: There was an error opening the
document. The file is damaged and could not be repaired.
Fix the problem by:
close Adobe Reader
Close browser
close ruby console (=stops server)
close Rails applications dialog box
I -> config database MyPHPAdmin
select database
select table Customer
browse
delete last record
close browser
I -> Rails applications -> Manage Rails applications
Select app,
Start it with Mongrel*(ruby console opens)
select http://localhost:3000/customer_report (should produce a pdf
listing customers)
Adobe Reader opens with the pdf listing - perfect !
Question: Is this normal behaviour ? Would you expect it to be damaged
by the action of opening the database with PHPAdmin ? And what is
damaged exactly ?
It has to be some environment (Win XP?) issue ?
I would welcome comments.
Maybe one should not access the database with PHP ?
(I reminded of the old joke - 'only whan i laugh' - Was that a Len
Deighton book ?)
Regards
Denis
I have also started working on integrating the jasper report and ruby on
rails. I started with creating the report manually in iReport.
I created my XML file data source. Then I tried to create the report.
"Data—> Report query" in iReport was disabled even after i selected my
data source. I don't know why it happens like this. I am not able to
proceed further.
Any guess???
Please help me to find out the issue.
Thanks in advance...
Could it be that you have not yet opened (to create) a new file.
Those buttonsare enabledafter File->New document ?
It does seem a little strange that you can create a data source first
without starting a new document.... :)
Denis
Now I am able to run the report from the XML. But I am getting a blank
PDF. No data inside it.
Any guess why???
When I run the URL in the browser I am getting a small alert message
saying
"The file is damaged and could not be repaired"
Any guess why it is coming???
I had that problem several times and it's difficult to trace.
It means that Adobe Reader is launching put the file created and
delivered to it is malformed, probably due to the XML data stream not
conforming to the data stream presented to iReports when you designed
the report.
Most usually, in my case, it was a malformed XML file, being used as
input.
A:
If the XML input file used to design the report is *in any way*
different from the XML output by the CUSTOMER_LIST method,(I'm assuming
you used the example -your method may be different), it will fail.
B:
The XPATH2 (note the *2*) must be selected for the XPATH query to work
correctly.
(Did your fields display properly when you were designing the report ?)
C:
If the library files (JARS) are not exactly as they were when the
iReport is designed, it *will* fail -(jar version references excluded).
The JARS which you have in the RoR application folder *must* be the ones
copied in from the iReport/JasperReport Lib folder. See my list above.
Also a help to:
Look at the ruby console window as you run the report. Does the output
to it give any indication? In this context, I heavily loaded the
document.rb with debug output (puts...) to help me trace the problem.
viz
---------------------------------------------
class Document < ActiveRecord::Base
include Config
def self.generate_report(xml_data, report_design, output_type,
select_criteria)
puts("Got XML passed as :" + xml_data)
puts("Got output type as:" + output_type)
puts("Got reportpassed as:" + report_design )
puts("Selection criteria is:" + select_criteria)
....
....
# What does Dir.for each do ?????? -this test line reads and lists on
console screen every matching file inc . and .. (.=curDir , .. =parent
Dir)
#Dir.foreach("c:/InstantRails/rails_apps/hats/app/jasper/bin") {|x|
puts("Got " + x) }
NOTE: hats was my appdir name- replace it with yours , if you decide to
insert debug code
-----------------------------------------------------------
Good Luck :)
Denis
Denis
But I got the same problem again. I found out one of the reasons also.
When I created the report design in the iReport UI, the height and width
were some factors for the column headers.
When I run the report in iReport, the PDF was generated successfully.
But when i tried that jasper with my rails application, the file damaged
message was shown. When I adjusted the height and width of the fields in
the report design, I got it working.
It's intersting that the object width/height could be a cause of error.
I did note that it warns you when the objects overlap the boundries by
altering the colour of the object outline.
I wonder would you look at my post of 26.03.2008 16:16 and comment ?
Are you in Linux or Windows ? and do you use PHPadmin.
It still seems strange to me that the PDF file creation can be broken by
using PHP admin.
Regards
Denis
See http://www.judahfrangipane.com/blog/?p=53
Could this be the reason?
quotes from above link - The link does not work for me at present for
some reason.
QUOTE:
In an XML document the first thing before anything else you declare the
type like so:
Correct:
PLAIN TEXTXML:
<?xml version="1.0" encoding="utf-8"?>
Incorrect:
PLAIN TEXTXML:
helloworld<?xml version="1.0" encoding="utf-8"?>
Note: The text formatter that I use adds a space between the less than
sign and first question mark. That should not be there. In your document
do not include the space.
Anything before the first character generates this error. If you do not
see any characters you may have an invisible character. Then you would
have to erase (backspace) up to that first character and retype the xml
declaration or take a similar approach.
END QUOTE:
QUOTE:
Suggestions:
- Copy the text in your file and paste it into Notepad. Notepad strips
or converts non standard codes. It is not fool proof but seems to work
in most cases.
- Create a new file using your standard process. Copy the contents of
your original file and paste them into the new file. The content being
everything minus the beginning and end tags.
END QUOTE:
Denis :)
If your report is blank you most likely did not tick the box in the
connection properties that says :
use the report XPATH expression when filling the report
Regards
Denis
Attachments:
http://www.ruby-forum.com/attachment/1810/test1.xml
become:
/customer_list_result/invoice_customers/customer
in the XPATH2 query window.
Denis
Attachments:
http://www.ruby-forum.com/attachment/1811/test.sql
your email address ?
Denis
I have got some problem. I have integrated the JasperReport with my ROR
application.
When I use "pipe.read" it reads the stream but not fully. As there is a
special character which ruby takes as a EOF character. It's hex value is
"0x1a". When this character is reached, ruby stops reading the stream.
Please give a suggestion to solve this issue.
Thanks in advance...
I noticed a change in the document.rb file on
IntegratingRubyAndJasperReports.
(It is difficult to determine the changes that are made due to the
method of updating the wiki :)
The mode needs to be set as 'w+b' for Windows.
This seems to have improved the stability of my PDF reports.
I thought you might be interested. It COULD be the cause of your error ?
Code fragment follows -note MODE is SET TO "w+b" for Binary mode in
WINDOWS. and passed as 'mode' to the Java call.
Regards
Denis
when /mswin32/
mode = "w+b" #windows requires binary mode
#Dir.foreach("app/jasper/lib") do |file|
Dir.foreach(Dir.getwd+"/app/jasper/lib") do |file|
interface_classpath << ";#{Dir.getwd}/app/jasper/lib/"+file if
(file != '.' and file != '..' and file.match(/.jar/))
end
else
mode = "w+"
Dir.foreach(Dir.getwd+"/app/jasper/lib") do |file|
interface_classpath << ":#{Dir.getwd}/app/jasper/lib/"+file if
(file != '.' and file != '..' and file.match(/.jar/))
end
end
result=nil
# removed--------------
#IO.popen "java -Djava.awt.headless=true -cp
\"#{interface_classpath}\" XmlJasperInterface -o#{output_type}
-f#{Dir.getwd}/app/reports/#{report_design} -x#{select_criteria}", "w+"
do |pipe|
# removed ------------------
# edited -------------------------------
IO.popen "java -Djava.awt.headless=true -cp
\"#{interface_classpath}\" XmlJasperInterface -o#{output_type}
-f#{Dir.getwd}/app/reports/#{report_design} -x#{select_criteria}", mode
do |pipe|
# edited -------------------------------
You're welcome. It feels good to be right now and again :)
Regards
Denis
I've followed your instructions here and at
http://wiki.rubyonrails.com/rails/pages/HowtoIntegrateJasperReports, but
no success, or just partial success, my pdf comes 0 bytes
I'm now trying the command line proposed there to get the report, and I
receive the folloing
Exception in thread "main" java.lang.NoClassDefFoundError:
XmlJasperInterface
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
Caused by: java.lang.ClassNotFoundException: XmlJasperInterface not
found in gnu.gcj.runtime.SystemClassLoader{urls=[],
parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
I guess it's something related to XmlJasperinterface (class not found)
there is another place than <RAILSAPP>/app/jasper/lib where I should to
copy this file?, or maybe define $CLASSPATH environment variable?, or
something I'm missing?
BTW: I'm developing in a FedoraC6, with Apache, also using goldberg
(integrated site design for ruby on rails, due to this, I did some
changes to path's at /app/models/document.rb, but test if its geting the
right files and it is)
in advance, thanks for your time
> I guess it's something related to XmlJasperinterface (class not found)
>
> there is another place than <RAILSAPP>/app/jasper/lib where I should to
> copy this file?, or maybe define $CLASSPATH environment variable?, or
> something I'm missing?
The file should be in /BIN not /LIB
ie. where your appplication is XXXXXX
C:\InstantRails\rails_apps\XXXXXX\app\jasper\bin
Regards
Denis
Thank you a lot Denis for taking time to answer this
I've just did a mistake writing prior post, my XmlJasperinterface.class
file actually is at <RAILSAPP>/app/jasper/bin, and I did also:
export CLASSPATH=<RAILSAPP>/app/jasper/bin
but my result pdf file is still getting 0 bytes
Sorry if did not try achieving this with a pure rubyOnRails application
(without using Goldberg) before post here, I'll try that this afternoon
because I'm suspecting Goldberg may be asking the report for
authentication when it try to get data from
<RAILSAPP>/app/views/XXXXX/customer_list
nevertheless, it's almost sure I have a problem with ruby accesing
XmlJasperinterface, as the message I recevie from command line attempt
states
any comment is welcome, regards Mauricio
Ae you actually getting a PDF file displayed that you can save, with no
data (a blank page?) Or are you getting a corruption when the PDF is
being written ?
The XML selection query used in the Rails code in the line-
send_doc(
render_to_string(:template => ‘accounting/customer_list’, :layout =>
false),
‘/customer_list_result/invoice_customers/customer’,
‘custrep’,
‘CustomerReport’,
’pdf’)
viz. /customer_list_result/invoice_customers/customer
must match the XML quey used when designing the Report to ensure you do
actually select the record/nodes you want to target.
Sorry, I'm not familiar with your development variation :(
Denis
> Ae you actually getting a PDF file displayed that you can save, with no
> data (a blank page?) Or are you getting a corruption when the PDF is
> being written ?
>.
>.
>.
> Sorry, I'm not familiar with your development variation :(
>
> Denis
thank you Denis
I'm receiving a "file" with 0 bytes (absolutely blank page, no source
code), I can't save it
it seems that I first must be sure that java command line works
thank you Karthi, but I'm not using ruby to call XmlJasperInterface,
just the java command line
I was able to define CLASSPATH, so the java call it's working now, but
with same results that before... XmlJasperInterface.class is giving me a
corrupted pdf file, when I try to open it, acrobat says "there was an
error opening this document. A file read error has ocurred"
I reviwed the Xpath and it's the same that I set in the report, also
update all jar files to IReport3.0
thanks anyway
I have success running the java command line on my laptop (windows), but
not in the server (Fedora C6), in this last one I get an empty pdf (0
bytes), it seems that (in XmlJasperInterface.java) jasperPrint object
passed to JasperExportManager is empty or invalid
does anybody has had success doing this work on a linux box?, applied
some changes at XmlJasperInterface?
thanks in advance
at fedora c6, I'm using these files:
poi-3.0.1-FINAL-20070705.jar
jdt-compiler-3.1.1.jar
jcommon-1.0.0.jar
commons-beanutils-1.7.jar
barbecue-1.5-beta1.jar
jasperreports-3.0.0.jar
jfreechart-1.0.3.jar
xalan.jar
commons-collections-2.1.jar
iReport.jar
commons-logging-1.0.2.jar
log4j-1.2.9.jar
iText-2.1.3.jar
and Java Runtime Environment (JRE) 6 Update 7 (fedora c6 default
jre-1.4.2-cgj GNU java doesn't work for me, for upgrading I followed
http://aditya-fedoralinux.blogspot.com/2008/08/installing-sun-java-instead-of-open-jdk.html),
before I upgrade, system gives me some GTK-WARNING message
for running the java command line first I set CLASSPATH adding these 2
lines to /etc/profile (I think there are better ways but this work for
me...)
#CLASSPATH=<RAILSAPP>/app/jasper/bin:<RAILSAPP>/app/jasper/lib/filejar1.jar:<RAILSAPP>/app/jasper/lib/filejar2.jar:<RAILSAPP>/app/jasper/lib/filejarN.jar
#export CLASSPATH
then, to "reload" or something, at prompt
#source /etc/profile
java command line should run
after that, ruby also works...
thank everybody
I'm glad for your success :)
Denis
I'm doing a new fedora intall (c6) and using iText-2.1.7.jar gives me
some error (com.lowagie.text.Image.plainWidth()F), then tried
iText-2.1.3.jar (as defined above), same error, some google and found
http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=39315
, so I set iText-2.0.8.jar, and it works
cheers!
Hi
I am new at ruby/rails. I am trying to develop a complete application.
Now I am building reports using ireport. I have read
http://wiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports this
instruction. But I didn’t understand this. Can you please give me a
guide line by using specific points? Such as :
1. you have to install jasper-rails (gem install jasper-rails)
2. now copy lib files from (…..) to raillsapplicaion/app/jasper/lib
folder
3. add these code to the abc controller file
4. put your *.jasper file to the raillsapplicaion/app/reports folder
5. …….
6. …….
Please help me if possible
mujahid
I am using ireport 3.0.0.
I am getting the datasource from an xml response which is almost ten MB
file.
My problem here is if my input is large , ireport is taking hardly 10
minutes to give the output.
if i use small response as input then there is no problem.
So is there any optimization process are there to overcome these kind of
issues.
Hi years ago you succeeded to cross Jasper and ruby on rails
Did you remember how you did?
are you still able to help me to do so?
Thanks in advance
One day you got it work, and today i try to have it !!!
Do you remember how you did it? or did you find a better solution to use
reports within a rails project
Thanks
Hey hi,
Can u help me with example code how to invoke jasper viewer on client
side in ruby on rails. I am using iReport 4.0.0