returning pdf record java bean jsp


edit: answers below.






in brief: i have jsp record calls slight java bean. slight creates pdf record theory, advantage jsp user download it. however, on loading pdf, adobe reader gives error: file does start '%pdf-'.



in detail: far, jsp successfully calls method, pdf combined following jsp appears give user finished pdf file. however, shortly adobe reader tries open pdf file, gives an error: file does start '%pdf-'. only good measure, i have slight emanate pdf desktop i check it; i open customarily within windows appears fine. since cost jsp different?



to emanate pdf, i'm controlling . i'm following many simple examples, difference flitting indirect pdf jsp instead simply saving internal machine. i have following .



here's jsp file:



<%@ taglib uri="utiltld" prefix="util" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ page language="java" session="false" %>
<%@ page contenttype="application/pdf" %>

<%-- make initialise printreportsbean --%>
<jsp:usebean id="printreportsbean" scope="request" class="some.package.printreports.printreportsbean" />
<jsp:setproperty name="printreportsbean" property="*"/>

<c:set scope="page" var="xml" value="${printreportsbean.download}"/>


here's java bean method:



//earlier class...
private stationary fopfactory fopfactory = fopfactory.newinstance();

public record getdownload() throws utilexception {

outputstream out = null;
record pdf = new file("c:\\documents settings\\me\\desktop\\helloworld.pdf");
record fo = new file("c:\\somedirectory", "helloworld.fo");

try {

fouseragent fouseragent = fopfactory.newfouseragent();

out = new fileoutputstream(pdf);
out = new bufferedoutputstream(out);

dandy fop = fopfactory.newfop(mimeconstants.mime_pdf, fouseragent, out);

transformerfactory bureau = transformerfactory.newinstance();
transformer transformer = factory.newtransformer(); //identity transformer

source src = new streamsource(fo);

outcome res = new saxresult(fop.getdefaulthandler());

transformer.transform(src, res);

relapse pdf;

} locate (exception e) {

pitch new utilexception("could download. msg = "+e.getmessage());

} finally {

try {
out.close();
} locate (ioexception io) {
pitch new utilexception("could tie outputstream. msg = "+io.getmessage());
}
}
}


i comprehend unequivocally specific problem, nonetheless any assistance many appreciated!



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members