I'm using the rails plugin acts_as_flying_saucer to generate a pdf, but the pdf doesn't work: i can save it ok, but when i try to open it i get this error message:
Unable to open document
File type SOR File (text/plain) is not supported
Here's my set up. I'm using rails 2.3.4 and the latest version of the acts_as_flying_saucer plugin. I have this route:
map.all_help '/help/all.:format', :controller => "help", :action => "all"
which goes to this controller action:
class HelpController < ApplicationController
acts_as_flying_saucer
def all
respond_to do |format|
format.html {
render :action => "all", :layout => "help_pdf"
}
format.js
format.pdf {
render_pdf :template => 'help/all.html.erb',
:layout => "help_pdf",
:send_file => { :filename => "my-filename.pdf", :type => "application/pdf"}
}
end
end
end
and i also have this mime type defined:
Mime::Type.register "application/pdf", :pdf
When i go to the page, /help/all.pdf, it generates a 0 byte pdf (which i can save ok) and i get the error message from the top of this post when i try to open it.
Going to the standard web page version of the page (/help/all) works fine. I thought maybe my java vm wasn't set up but it seems to be fine:
max-laptop:millionaire[subjects]$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
I'm out of ideas at this point...grateful for any advice! max
EDIT: Just noticed that a bunch of error output is in my mongrel-running tab:
ERROR: 'Premature end of file.'
Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: Premature end of file.
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:205)
at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:102)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:106)
at Xhtml2Pdf.main(Xhtml2Pdf.java:19)
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: Premature end of file.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:719)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
at org.xhtmlrenderer.resource.XMLResource$XMLRes开发者_高级运维ourceBuilder.createXMLResource(XMLResource.java:189)
... 5 more
Caused by: org.xml.sax.SAXParseException: Premature end of file.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:636)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707)
... 7 more
I'm wondering now if there's something wrong with the page i'm trying to convert to pdf. I ran the html version of the page past the w3c validator and the page validates ok. So now i'm stumped again...
EDIT 2: i think i'm getting closer now: looking in my log, i see
Rendering help/all.html.erb
html file: /tmp/ff4c8ff01d544500ea4bfea43e6108c1.html
Sending X-Sendfile header /tmp/ff4c8ff01d544500ea4bfea43e6108c1.pdf
So, i'd expect /tmp/ff4c8ff01d544500ea4bfea43e6108c1.html to have the html version of my page in it, but it's just a four line empty text file. No wonder flying saucer can't convert it. I don't know why it's saving an empty html file though.
EDIT 3: here's the html i'm currently trying to convert
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Help for Millionaire For Schools</title>
</head>
<body class="pdf">
<div id="bgeffect"></div>
<div id="pageWrapper" class="mainHelpPages">
<div id="helpContent">
<div id="helpPane">
<div class="inner">
<p>Welcome to my pdf</p>
</div>
</div>
</div>
</div>
</body>
</html>
Didn't you solve this problem a year ago by setting x_sendfile
to false?
I solved this, it turned out to be really simple (and dumb). The problem was this: i was pointing to the layout i wanted to use in the normal railsy way,
:layout => "help_pdf",
But, it looks like you have to spell out the full file name: when i changed it to this, it worked:
:layout => "help_pdf.html.erb",
ARRRGGHHH!!!!!! Ah well at least it's working now. Thanks a lot John for having a look.
max
精彩评论