Commit 06b62da3 authored by Pamelpreet Jhinger's avatar Pamelpreet Jhinger
Browse files

added -f, markdown flags, removed unnecessary code

parent 4821f247
Pipeline #64973 passed with stages
in 1 minute and 52 seconds
......@@ -29,59 +29,30 @@ public class PDFResultPage implements Page {
String pdfname = query + ".pdf";
resp.setHeader("Content-Disposition", "inline;filename=\"" + pdfname + "\"");
resp.setHeader("Expires", "0");
resp.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
resp.setHeader("Pragma", "public");
File md = File.createTempFile(query, ".md");
md.deleteOnExit();
FileWriter fw = new FileWriter(md);
fw.write("#" + query + "\n");
fw.write(answer);
fw.close();
System.out.println("md file size = " + md.length());
File pdf = File.createTempFile(query, ".pdf");
pdf.deleteOnExit();
System.out.println("pdf size BEFORE = " + pdf.length());
/*new ProcessBuilder("bash", "-c", "pandoc", "-s", md.getAbsolutePath(),
"--pdf-engine=xelatex", "-o", pdf.getAbsolutePath());*/
ProcessBuilder processBuilder =
new ProcessBuilder("/usr/bin/bash", "-c", "/usr/bin/pandoc -s " + md.getAbsolutePath() +
" --pdf-engine=xelatex -o " + pdf.getAbsolutePath());
new ProcessBuilder("pandoc", md.getAbsolutePath(),
"-f", "markdown", "-o", pdf.getAbsolutePath());
try {
Process process = processBuilder.start();
process.waitFor();
System.out.println("finished the pandoc");
System.out.println("process exit code: " + process.exitValue());
System.out.println("" + process.getErrorStream().readAllBytes());
} catch (InterruptedException | IOException e) {
e.printStackTrace();
System.out.println("caught an exception");
}
System.out.println("pdf size AFTER = " + pdf.length());
/*File file = new File("/homes/pj2017/Downloads/eg.pdf");
FileInputStream fis = new FileInputStream(file);
byte[] bytes = fis.readAllBytes();*/
FileInputStream pdfInputStream = new FileInputStream(pdf);
byte[] bytes = pdfInputStream.readAllBytes();
resp.setContentLength(bytes.length);
OutputStream servletOutputStream = resp.getOutputStream();
servletOutputStream.write(bytes);
//System.out.println("size = " + Integer.toHexString(bytes.length));
//System.out.println(bytes);
// delete file?
// flush/close?
/* ideas
* specify pdf engine (conversion)
* work out if files are actually being built
* */
servletOutputStream.write(pdfInputStream.readAllBytes());
}
}
}
\ No newline at end of file
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