//package rich;
//
//import com.dayou.BaseApplication;
//import com.dayou.controller.BaseController;
//import com.dayou.enums.UnitEnum;
//import com.dayou.utils.FileUploadUtils;
//import com.dayou.utils.PersonalUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
//import org.apache.poi.util.Units;
//import org.apache.poi.xwpf.usermodel.*;
//import org.apache.xmlbeans.XmlException;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
//import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
//import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
//import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.context.ResourceLoaderAware;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.ResourceLoader;
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//
//import java.io.*;
//import java.util.List;
//
//import static com.dayou.common.Constants.DOCX;
//
///**
// * 类说明：
// *
// * @author: wucl
// * @since: 2024/4/1
// * created with IntelliJ IDEA.
// */
//@Slf4j
//@SpringBootTest(classes = BaseApplication.class)
//@RunWith(SpringJUnit4ClassRunner.class)
//public class DocxTest extends BaseController implements ResourceLoaderAware {
//
//    private ResourceLoader resourceLoader;
//
//    @Test
//    public void genStamp(){
//        try {
//            InputStream inputStream = new FileInputStream("G:\\upload\\2024\\03\\29\\2024030016结果报告.docx");
//            Resource resource = resourceLoader.getResource("classpath:static/image/stamp.png");
//            PersonalUtils.addPublicStamp(inputStream,resource,"G:\\upload\\2024\\04\\01\\2024030016结果报告.docx");
//        } catch (FileNotFoundException e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//    @Override
//    public void setResourceLoader(ResourceLoader resourceLoader) {
//            this.resourceLoader = resourceLoader;
//    }
//
//    /**
//     * @param ctGraphicalObject 图片数据
//     * @param deskFileName      图片描述
//     * @param width             宽
//     * @param height            高
//     * @param leftOffset        水平偏移 left
//     * @param topOffset         垂直偏移 top
//     * @param behind            文字上方，文字下方
//     * @return
//     * @throws Exception
//     */
//    public static CTAnchor getAnchorWithGraphic(CTGraphicalObject ctGraphicalObject,
//                                                String deskFileName, int width, int height,
//                                                int leftOffset, int topOffset, boolean behind) {
//        System.out.println(">>width>>"+width+"; >>height>>>>"+height);
//        String anchorXML =
//                "<wp:anchor xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" "
//                        + "simplePos=\"0\" relativeHeight=\"0\" behindDoc=\"" + ((behind) ? 1 : 0) + "\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
//                        + "<wp:simplePos x=\"0\" y=\"0\"/>"
//                        + "<wp:positionH relativeFrom=\"column\">"
//                        + "<wp:posOffset>" + leftOffset + "</wp:posOffset>"
//                        + "</wp:positionH>"
//                        + "<wp:positionV relativeFrom=\"paragraph\">"
//                        + "<wp:posOffset>" + topOffset + "</wp:posOffset>" +
//                        "</wp:positionV>"
//                        + "<wp:extent cx=\"" + width + "\" cy=\"" + height + "\"/>"
//                        + "<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>"
//                        + "<wp:wrapNone/>"
//                        + "<wp:docPr id=\"1\" name=\"Drawing 0\" descr=\"" + deskFileName + "\"/><wp:cNvGraphicFramePr/>"
//                        + "</wp:anchor>";
//
//        CTDrawing drawing = null;
//        try {
//            drawing = CTDrawing.Factory.parse(anchorXML);
//        } catch (XmlException e) {
//            e.printStackTrace();
//        }
//        CTAnchor anchor = drawing.getAnchorArray(0);
//        anchor.setGraphic(ctGraphicalObject);
//        return anchor;
//    }
//
//}
