|
@@ -13,11 +13,11 @@ import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
|
|
|
import com.itextpdf.text.pdf.parser.RenderListener;
|
|
|
import com.itextpdf.text.pdf.parser.TextRenderInfo;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
+
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
@@ -27,23 +27,6 @@ public class PdfAddContextUtils {
|
|
|
|
|
|
public static void addContextByTitle(String src, String dest, String title, String context, int fontSize) throws IOException, DocumentException {
|
|
|
|
|
|
- File pdfFile = new File(src);
|
|
|
- byte[] pdfData = new byte[(int) pdfFile.length()];
|
|
|
- FileInputStream inputStream = null;
|
|
|
- try {
|
|
|
- inputStream = new FileInputStream(pdfFile);
|
|
|
- inputStream.read(pdfData);
|
|
|
- } catch (IOException e) {
|
|
|
- throw e;
|
|
|
- } finally {
|
|
|
- if (inputStream != null) {
|
|
|
- try {
|
|
|
- inputStream.close();
|
|
|
- } catch (IOException e) {
|
|
|
- inputStream.close();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
// 读取PDF文件
|
|
|
PdfReader reader = new PdfReader(src);
|
|
|
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
|
|
@@ -66,14 +49,13 @@ public class PdfAddContextUtils {
|
|
|
public static String getExcelFullTitle(org.apache.poi.ss.usermodel.Workbook workbook, String title) {
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
sheet.setForceFormulaRecalculation(true);
|
|
|
- int rowNum = sheet.getLastRowNum();
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
Row row = sheet.getRow(i);
|
|
|
if (row != null) {
|
|
|
short cellNum = row.getLastCellNum();
|
|
|
for (int j = 0; j < cellNum; j++) {
|
|
|
Cell cell = row.getCell(j);
|
|
|
- if (cell != null) {
|
|
|
+ if (cell != null && cell.getCellTypeEnum() == CellType.STRING) {
|
|
|
String cellValue = cell.getStringCellValue();
|
|
|
if (cellValue != null && !cellValue.isEmpty()) {
|
|
|
if (containsAllCharactersInOrder(cellValue, title)) {
|