Commit 2b96fd74 authored by Joshua Priestley's avatar Joshua Priestley
Browse files

Fixes an issue with downloading PDFs

parent 13d53c0c
Pipeline #173208 passed with stages
in 3 minutes and 12 seconds
...@@ -40,7 +40,7 @@ public class MarkdownResultPage implements Page { ...@@ -40,7 +40,7 @@ public class MarkdownResultPage implements Page {
} }
File getFile() throws IOException { File getFile() throws IOException {
File markdown = File.createTempFile("result", ".md"); File markdown = new File("result.md");
// Header // Header
FileWriter writer = new FileWriter(markdown); FileWriter writer = new FileWriter(markdown);
writer.write("<h1>" + query + "<h1>"); writer.write("<h1>" + query + "<h1>");
...@@ -53,7 +53,7 @@ public class MarkdownResultPage implements Page { ...@@ -53,7 +53,7 @@ public class MarkdownResultPage implements Page {
writer.write("<p>" + answer + "</p>"); writer.write("<p>" + answer + "</p>");
} }
writer.flush(); writer.close();
return markdown; return markdown;
} }
......
...@@ -12,20 +12,21 @@ public class PDFResultPage extends MarkdownResultPage { ...@@ -12,20 +12,21 @@ public class PDFResultPage extends MarkdownResultPage {
@Override @Override
public void writeTo(HttpServletResponse resp) throws IOException { public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("file/markdown");
File markdown = getFile(); File markdown = getFile();
String currentDir = System.getProperty("user.dir");
ProcessBuilder pb = new ProcessBuilder("pandoc", "-s", "-o", resp.setHeader("Content-Disposition", "Inline; filename=" + markdown.getName() + ".pdf");
currentDir + "/result.pdf", markdown.getAbsolutePath());
ProcessBuilder pb = new ProcessBuilder("pandoc", markdown.getAbsolutePath(), "-o", "result.pdf");
Process p = pb.start(); Process p = pb.start();
try { try {
p.waitFor(); p.waitFor();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println(System.getProperty("user.dir"));
File pdf = new File(currentDir + "/result.pdf"); File pdf = new File("result.pdf");
outputStreams(pdf, resp); outputStreams(pdf, resp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment