|
|
@@ -28,8 +28,10 @@ import org.springframework.util.FileCopyUtils;
|
|
|
import com.fasterxml.jackson.core.JsonParseException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
+import es.uv.saic.shared.domain.InstanciaTasca;
|
|
|
import es.uv.saic.shared.domain.Plantilla;
|
|
|
import es.uv.saic.shared.domain.PlantillaComentario;
|
|
|
import es.uv.saic.shared.domain.PlantillaConversation;
|
|
|
@@ -106,11 +108,34 @@ public class PlantillaService {
|
|
|
|
|
|
|
|
|
public String savePDF(String content, BigInteger idtascai) throws IOException, InterruptedException {
|
|
|
+ InstanciaTascaDTO instanciaTasca = tc.findInstanciaTascaById(idtascai);
|
|
|
+
|
|
|
+ Plantilla plantilla = this.findEvidencia(Integer.parseInt(instanciaTasca.getTasca().getCodiEvidencia()),
|
|
|
+ instanciaTasca.getInstancia().getTitulacio(), instanciaTasca.getInstancia().getTambit());
|
|
|
+
|
|
|
+ String width = "297mm";
|
|
|
+ String height = "210mm";
|
|
|
+
|
|
|
+ if (plantilla.getOpcions() != null && !plantilla.getOpcions().trim().isEmpty()) {
|
|
|
+ try {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ JsonNode rootNode = mapper.readTree(plantilla.getOpcions());
|
|
|
+ JsonNode orientacionNode = rootNode.get("orientacion");
|
|
|
+
|
|
|
+ if (orientacionNode != null && "vertical".equalsIgnoreCase(orientacionNode.asText())) {
|
|
|
+ width = "210mm";
|
|
|
+ height = "297mm";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("Error al parsear el JSON de opciones: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
content = content.replace("<p><!-- pagebreak --></p>", "<p class=\"pagebreak\"><!-- pagebreak --></p>");
|
|
|
Document d = Jsoup.parse(content, "UTF8");
|
|
|
d.head().append("<style>"
|
|
|
- + "@page{size: 297mm 210mm;} "
|
|
|
- + "html{ max-width:297mm; max-height:210mm; margin:0; padding:0; transform:scale(0.925); transform-origin:left top; } "
|
|
|
++ "@page{size: " + width + " " + height + ";} "
|
|
|
+ + "html{ max-width:" + width + "; max-height:" + height + "; margin:0; padding:0; transform:scale(0.925); transform-origin:left top; } "
|
|
|
+ "table { padding:2px !important; }"
|
|
|
+ "th, td { padding:2px !important; }"
|
|
|
+ ".pagebreak { page-break-before:always; }"
|