pdf generating
parent
10fe7e8a4e
commit
cf9a7f895f
@ -0,0 +1,33 @@
|
|||||||
|
package ru.ulstu.paper.service;
|
||||||
|
|
||||||
|
import de.nixosoft.jlr.JLRGenerator;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.file.service.FileService;
|
||||||
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LatexService {
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
|
public LatexService(FileService fileService) {
|
||||||
|
this.fileService = fileService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] generatePdfFromLatexFile(PaperDto paper) throws IOException {
|
||||||
|
fileService.createLatexAttachs(paper);
|
||||||
|
File tex = fileService.createLatexFile(paper);
|
||||||
|
|
||||||
|
File output = new File(tex.getParentFile().getAbsolutePath() + File.separator);
|
||||||
|
JLRGenerator pdfGen = new JLRGenerator();
|
||||||
|
|
||||||
|
if (!pdfGen.generate(tex, output, tex.getParentFile())) {
|
||||||
|
throw new IOException(pdfGen.getErrorMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Files.readAllBytes(pdfGen.getPDF().toPath());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue