Remove Direct Logger and Use Lombok @Slf4j
This commit is contained in:
@@ -30,18 +30,16 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
||||
import org.apache.pdfbox.rendering.ImageType;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.apache.pdfbox.text.PDFTextStripper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import io.github.pixee.security.Filenames;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import stirling.software.SPDF.service.CustomPDDocumentFactory;
|
||||
|
||||
@Slf4j
|
||||
public class PdfUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PdfUtils.class);
|
||||
|
||||
public static PDRectangle textToPageSize(String size) {
|
||||
switch (size.toUpperCase()) {
|
||||
case "A0":
|
||||
@@ -310,7 +308,7 @@ public class PdfUtils {
|
||||
}
|
||||
|
||||
// Log that the image was successfully written to the byte array
|
||||
logger.info("Image successfully written to byte array");
|
||||
log.info("Image successfully written to byte array");
|
||||
} else {
|
||||
// Zip the images and return as byte array
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
@@ -330,13 +328,13 @@ public class PdfUtils {
|
||||
}
|
||||
}
|
||||
// Log that the images were successfully written to the byte array
|
||||
logger.info("Images successfully written to byte array as a zip");
|
||||
log.info("Images successfully written to byte array as a zip");
|
||||
}
|
||||
}
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
// Log an error message if there is an issue converting the PDF to an image
|
||||
logger.error("Error converting PDF to image", e);
|
||||
log.error("Error converting PDF to image", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -421,7 +419,7 @@ public class PdfUtils {
|
||||
}
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
doc.save(byteArrayOutputStream);
|
||||
logger.info("PDF successfully saved to byte array");
|
||||
log.info("PDF successfully saved to byte array");
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -471,7 +469,7 @@ public class PdfUtils {
|
||||
image.getHeight() * scaleFactor);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Error adding image to PDF", e);
|
||||
log.error("Error adding image to PDF", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -498,20 +496,20 @@ public class PdfUtils {
|
||||
PDImageXObject image = PDImageXObject.createFromByteArray(document, imageBytes, "");
|
||||
// Draw the image onto the page at the specified x and y coordinates
|
||||
contentStream.drawImage(image, x, y);
|
||||
logger.info("Image successfully overlayed onto PDF");
|
||||
log.info("Image successfully overlayed onto PDF");
|
||||
if (!everyPage && i == 0) {
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Log an error message if there is an issue overlaying the image onto the PDF
|
||||
logger.error("Error overlaying image onto PDF", e);
|
||||
log.error("Error overlaying image onto PDF", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
// Create a ByteArrayOutputStream to save the PDF to
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
document.save(baos);
|
||||
logger.info("PDF successfully saved to byte array");
|
||||
log.info("PDF successfully saved to byte array");
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user