package com.css.simulation.resource.server.infra.util;

import com.css.simulation.resource.server.app.impl.SimulationProjectServiceImpl;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.events.PdfPageEventForwarder;
import lombok.SneakyThrows;

public class PdfBuilder extends PdfPageEventForwarder {


    @SneakyThrows
    @Override
    public void onEndPage(PdfWriter writer, Document document) {

        Image image = Image.getInstance("classpath:icon/ym_new.png");
        PdfContentByte directContent = writer.getDirectContent();

        BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);
        Font font = new Font(baseFont, 12, Font.NORMAL);

        Phrase elements = new Phrase("", font);
        elements.add(new Chunk(image, 30, -30));

        ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT,
                elements, Element.ALIGN_LEFT,  document.top(0), 0);


    }

    @SneakyThrows
    @Override
    public void onStartPage(PdfWriter writer, Document document) {
        new SimulationProjectServiceImpl().lineFeed(document, 4, 2);;
    }
}
