package com.knecon.fforesight.service.layoutparser.server;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.base.Strings;
import com.pdftron.pdf.PDFNet;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class PDFNetInitializer {

    @Value("${pdftron.license:}")
    private String pdftronLicense;


    @Bean
    @SneakyThrows
    public void init() {

        if (Strings.isNullOrEmpty(pdftronLicense)) {
            throw new IllegalArgumentException("PDFTRON_LICENSE not set!");
        }
        log.info("Initializing Native Libraries");
        log.info("Setting pdftron license: {}", pdftronLicense);
        PDFNet.setTempPath("/tmp/pdftron");
        PDFNet.initialize(pdftronLicense);
    }

}
