|
@@ -4,6 +4,7 @@ import com.aspose.cells.SaveFormat;
|
|
import com.aspose.words.DocumentBuilder;
|
|
import com.aspose.words.DocumentBuilder;
|
|
import com.itextpdf.text.Image;
|
|
import com.itextpdf.text.Image;
|
|
import com.itextpdf.text.Rectangle;
|
|
import com.itextpdf.text.Rectangle;
|
|
|
|
+import com.itextpdf.text.Utilities;
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
@@ -18,6 +19,10 @@ import org.springblade.resource.vo.NewBladeFile;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
|
+import javax.imageio.ImageReader;
|
|
|
|
+import javax.imageio.stream.FileImageInputStream;
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -45,7 +50,12 @@ public class CommonFileClientImpl implements CommonFileClient {
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
PdfWriter.getInstance(document, bos);
|
|
PdfWriter.getInstance(document, bos);
|
|
document.open();
|
|
document.open();
|
|
- Image image = Image.getInstance(this.InputStreamToBytes(file.getInputStream()));
|
|
|
|
|
|
+ byte[] bytes = IoUtil.readToByteArray(file.getInputStream());
|
|
|
|
+ if (bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70){
|
|
|
|
+ bytes = CommonUtil.webpToPngBytes(file.getInputStream());
|
|
|
|
+ }
|
|
|
|
+ Image image = Image.getInstance(bytes);
|
|
|
|
+
|
|
// 设置页面宽高与图片一致
|
|
// 设置页面宽高与图片一致
|
|
document.setPageSize(new Rectangle(image.getScaledWidth(), image.getScaledHeight()));
|
|
document.setPageSize(new Rectangle(image.getScaledWidth(), image.getScaledHeight()));
|
|
// 图片居中(感觉没啥用)
|
|
// 图片居中(感觉没啥用)
|
|
@@ -78,6 +88,8 @@ public class CommonFileClientImpl implements CommonFileClient {
|
|
return newBladeFile;
|
|
return newBladeFile;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取字节数组
|
|
* 获取字节数组
|
|
*/
|
|
*/
|