Вот такую ошибку я получил
Код: Выделить всё
2024-09-26 16:17:20.877 ERROR [whatsapp-api-service,64b76bd04750daa2,64b76bd04750daa2] 3200902 --- [http-nio-8002-exec-2] z.c.e.p.s.UUIDAuthenticationFilter : Request processing failed; nested exception is Error downloading transcript, U+1F413 ('.notdef') is not available in the font Helvetica, encoding: WinAnsiEncoding
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is Error downloading transcript, U+1F413 ('.notdef') is not available in the font Helvetica, encoding: WinAnsiEncoding
это код
Код: Выделить всё
private static final List EMOJI_RANGES = Arrays.asList(
new UnicodeRange(0x1F600, 0x1F64F), // Emoticons
new UnicodeRange(0x1F300, 0x1F5FF), // Misc Symbols and Pictographs
new UnicodeRange(0x1F680, 0x1F6FF), // Transport and Map Symbols
new UnicodeRange(0x2600, 0x26FF), // Misc Symbols
new UnicodeRange(0x2700, 0x27BF), // Dingbats
new UnicodeRange(0x1F900, 0x1F9FF), // Supplemental Symbols and Pictographs
new UnicodeRange(0x1FA70, 0x1FAFF), // Symbols and Pictographs Extended-A
new UnicodeRange(0x1F1E6, 0x1F1FF), // Regional Indicator Symbols
new UnicodeRange(0xFE00, 0xFE0F), // Variation Selectors
new UnicodeRange(0x1F000, 0x1F02F), // Mahjong Tiles
new UnicodeRange(0x1F0A0, 0x1F0FF), // Playing Cards
new UnicodeRange(0x1F700, 0x1F77F), // Alchemical Symbols
new UnicodeRange(0x1F780, 0x1F7FF), // Geometric Shapes Extended
new UnicodeRange(0x1F800, 0x1F8FF) // Supplemental Arrows and Symbols
);
Код: Выделить всё
private boolean isEmoji(int codePoint) {
for (UnicodeRange range : EMOJI_RANGES) {
if (range.contains(codePoint)) {
return true;
}
}
return false;
}
Код: Выделить всё
private String removeEmojis(String input) {
StringBuilder result = new StringBuilder();
int length = input.length();
int i = 0;
while (i < length) {
int codePoint = input.codePointAt(i);
if (Character.isSupplementaryCodePoint(codePoint)) {
i += Character.charCount(codePoint);
continue;
}
if (!isEmoji(codePoint)) {
result.append(Character.toChars(codePoint));
}
i += Character.charCount(codePoint);
}
return result.toString();
}
Код: Выделить всё
private byte[] generatePdfTranscript() throws IOException {
if (ticketNumber != null) {
fileName = ticketNumber + "_transcript.pdf";
} else {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
fileName = removeEmojis(customerName) + "_" + LocalDateTime.now().format(formatter) + "_transcript.pdf";
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (PDDocument document = new PDDocument()) {
initializeFonts(document);
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
try (PDPageContentStream initialContentStream = new PDPageContentStream(document, page)) {
float yPosition = page.getMediaBox().getHeight() - MARGIN_Y;
yPosition = setupPdfHeader(initialContentStream, yPosition, document);
yPosition = addTranscriptTitle(initialContentStream, yPosition);
PDPageContentStream currentContentStream = initialContentStream;
for (Message message : messages) {
Pair result = addMessage(document, currentContentStream, message, yPosition - 15);
yPosition = result.getLeft();
if (result.getRight() != currentContentStream) {
if (currentContentStream != initialContentStream) {
currentContentStream.close();
}
currentContentStream = result.getRight();
}
}
if (currentContentStream != initialContentStream) {
currentContentStream.close();
}
}
document.save(byteArrayOutputStream);
}
return byteArrayOutputStream.toByteArray();
}
Код: Выделить всё
private float setupPdfHeader(PDPageContentStream contentStream, float yPosition, PDDocument document) throws IOException {
contentStream.saveGraphicsState();
contentStream.setFont(PDType1Font.HELVETICA_BOLD, FONT_SIZE);
float pageWidth = document.getPage(0).getMediaBox().getWidth();
float headerStartY = yPosition + 10;
float contentWidth = pageWidth - 2 * MARGIN_X;
if (ticketNumber != null) {
yPosition = addTextLine(contentStream, "Ticket Number: " + ticketNumber, yPosition);
yPosition = addTextLine(contentStream, "Date & Time Ticket Issued: " + issuedTime, yPosition);
yPosition = addTextLine(contentStream, "Date & Time Ticket Closed: " + closedTime, yPosition);
} else {
yPosition = addTextLine(contentStream, "No ticket issued", yPosition);
}
if (clientWhatsAppNumber != null) {
yPosition = addTextLine(contentStream, "Service's WhatsApp number: " + clientWhatsAppNumber, yPosition);
}
if (customerWhatsAppNumber != null) {
yPosition = addTextLine(contentStream, "Customer's WhatsApp number: " + customerWhatsAppNumber, yPosition);
}
yPosition = addTextLine(contentStream, "Agent's Name & Surname: " + removeEmojis(agentName), yPosition);
yPosition = addTextLine(contentStream, "Customer's Name & Surname: " + removeEmojis(customerName), yPosition);
float headerHeight = headerStartY - yPosition + FONT_SIZE; // Add FONT_SIZE to give some bottom padding
contentStream.setLineWidth(1f);
contentStream.setStrokingColor(Color.BLACK);
contentStream.addRect(MARGIN_X - 5, yPosition, contentWidth + 10, headerHeight);
contentStream.stroke();
contentStream.restoreGraphicsState();
yPosition -= FONT_SIZE;
return yPosition;
}
private float addTranscriptTitle(PDPageContentStream contentStream, float yPosition) throws IOException {
contentStream.setFont(PDType1Font.HELVETICA_BOLD, FONT_SIZE + 2);
return addTextLine(contentStream, "Ticket Transcript:", yPosition - 20);
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -usernames