package net.gepafin.tendermanagement.util; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.html.simpleparser.HTMLWorker; import com.itextpdf.text.html.simpleparser.StyleSheet; import com.itextpdf.text.Paragraph; import java.io.StringReader; import java.util.List; import org.springframework.stereotype.Component; @Component public class PdfUtils { public static PdfPCell htmlToPdfPCell(String htmlContent, Font font) { PdfPCell cell = new PdfPCell(); // Check if the content is not null or empty if (htmlContent != null && !htmlContent.trim().isEmpty()) { // Wrap plain text in a paragraph tag if it doesn't contain any HTML // Check if the string does not contain any '<' or '>' characters if (!htmlContent.contains("<") || !htmlContent.contains(">")) { htmlContent = "
" + htmlContent + "
"; // Wrap in paragraph tags } try { // Create a list to hold the elements parsed from the HTML List