Hi,
I am trying to write a REST service that will convert received HTML document to PDF in java and return back the converted PDF to the calling client. I am getting stuck in sending back the converted PDF to the browser. I have searched all help and examples but couldn’t find anything similar to what i want to do. following code snippet would explain what i want to do
@GET
@Path("/get")
@Produces(“application/pdf”)
public Response convertpdf() {
String savedir="/users//";
String FILE_PATH = "/users/testuser/trac.html";
String basePath = "https://trac.abc.cnn.com";
HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);
// Load HTML file
Document doc = new Document(FILE_PATH, htmloptions);
// Save HTML file
ByteArrayOutputStream output = new ByteArrayOutputStream();
doc.save(output, com.aspose.pdf.SaveFormat.Pdf);
try{
ResponseBuilder response = Response.ok((Object) output.toByteArray());
response.header("Content-Disposition",
"attachment; filename=trac.pdf");
response.type("application/pdf");
return response.build();
}
finally
{
if (doc != null)
doc.dispose();
}
}