package com.qmth.boot.test.tools.pdf;

import com.google.zxing.WriterException;
import com.qmth.boot.tools.models.ByteArray;
import com.qmth.boot.tools.pdf.PdfFormUtil;
import com.qmth.boot.tools.zxing.BarcodeEncoder;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class PdfFormTest {

    @Test
    public void test() throws IOException, WriterException {
        ByteArray template = ByteArray.fromResource("template.pdf");
        ByteArrayOutputStream ous = new ByteArrayOutputStream();
        Map<String, Object> params = new HashMap<>();
        params.put("package_code", "1001");
        params.put("campus", "武汉学习中心");
        params.put("barcode", BarcodeEncoder.encode("1001", 400, 100).toBase64());
        PdfFormUtil.fill(template.value(), ous, params);
        Assert.assertTrue(ous.toByteArray().length > 0);
    }
}
