This commit is contained in:
root
2025-10-05 17:00:40 +05:00
parent a523d66e51
commit 29811f0860
@@ -6,6 +6,8 @@ import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfWriter;
import kz.konturai.parser.dto.DeepResearchResponse;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.time.LocalDateTime;
@@ -21,6 +23,8 @@ import java.io.InputStream;
@Service
public class ResearchPdfService {
private static final Logger logger = LoggerFactory.getLogger(ResearchPdfService.class);
// --- Шрифты с поддержкой кириллицы ---
private final BaseFont baseFont;
private final Font titleFont;
@@ -86,6 +90,20 @@ public class ResearchPdfService {
}
public byte[] generatePdfReport(String query, DeepResearchResponse researchResponse) {
try {
String mainContent = researchResponse == null ? null : researchResponse.getMainContent();
java.util.List<String> urls = researchResponse == null ? null : researchResponse.getVisitedUrls();
int contentLength = mainContent == null ? 0 : mainContent.length();
int urlCount = urls == null ? 0 : urls.size();
logger.info("PDF input (legacy): query='{}', contentLength={}, visitedUrlsCount={}", query, contentLength,
urlCount);
if (logger.isDebugEnabled()) {
logger.debug("PDF input (legacy) full content:\n{}", mainContent);
logger.debug("PDF input (legacy) visitedUrls: {}", urls);
}
} catch (Exception logEx) {
// do not fail generation due to logging issue
}
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
Document document = new Document(PageSize.A4, 36, 36, 36, 54); // Добавлены отступы
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
@@ -111,6 +129,18 @@ public class ResearchPdfService {
}
public byte[] generatePdfReport(String query, String synthesizedMarkdown, java.util.List<String> visitedUrls) {
try {
int contentLength = synthesizedMarkdown == null ? 0 : synthesizedMarkdown.length();
int urlCount = visitedUrls == null ? 0 : visitedUrls.size();
logger.info("PDF input (synthesized): query='{}', contentLength={}, visitedUrlsCount={}", query,
contentLength, urlCount);
if (logger.isDebugEnabled()) {
logger.debug("PDF input (synthesized) full content:\n{}", synthesizedMarkdown);
logger.debug("PDF input (synthesized) visitedUrls: {}", visitedUrls);
}
} catch (Exception logEx) {
// do not fail generation due to logging issue
}
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
Document document = new Document(PageSize.A4, 36, 36, 36, 54);
PdfWriter writer = PdfWriter.getInstance(document, outputStream);