package it.mice.voila.runtime.displaytag.pdfexporter;

import it.mice.voila.runtime.displaytag.DisplayTagUtils;

import java.io.IOException;

import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

public class BasicPdfExporter extends AbstractPdfExporter {

	protected void prepareDocumentTitle() throws IOException {
        String title = DisplayTagUtils.getDocumentTitle(model);
        if (title != null) {
            PDRectangle pageSize = new PDRectangle(PDRectangle.A4.getHeight(), PDRectangle.A4.getWidth());
            float pageWidth = pageSize.getWidth();
            float titleFontSize = 12;
            float titleWidth = PDType1Font.HELVETICA_BOLD.getStringWidth(title) / 1000 * titleFontSize;
            float x = (pageWidth - titleWidth) / 2;
            float y = 540; // Adjust y position as needed
            contentStream.beginText();
            contentStream.newLineAtOffset(x, y); // Centered on the page
            contentStream.setFont(PDType1Font.HELVETICA_BOLD, 12);
            contentStream.showText(title);
            contentStream.endText();
//            contentStream.moveTextPositionByAmount(0, -20); // Spacing after title
        }
    }
}
