/
elisaveta
/
tasks
Обзор
Документация
Войти
/
elisaveta
/
tasks
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/com/example/taskmanager/utils/TaskPDFExporter.java
79 строк
2 KB
lisssoxhaa
nitial commit
13 апр 2025, 15:48
13 апр 2025, 15:48
64973e1
Код
Авторство
О чём код?
package com.example.taskmanager.utils; import com.example.taskmanager.model.Task; import com.lowagie.text.*; import com.lowagie.text.pdf.*; import jakarta.servlet.http.HttpServletResponse; import java.awt.Color; import java.io.IOException; import java.util.List; public class TaskPDFExporter { private List<Task> taskList; public TaskPDFExporter(List<Task> taskList) { this.taskList = taskList; } public void export(HttpServletResponse response) throws IOException { Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); Font font = FontFactory.getFont(FontFactory.HELVETICA_BOLD); font.setSize(18); font.setColor(Color.BLACK); Paragraph title = new Paragraph("Список задач", font); title.setAlignment(Paragraph.ALIGN_CENTER); document.add(title); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100f); table.setSpacingBefore(10); writeTableHeader(table); writeTableData(table); document.add(table); document.close(); } private void writeTableHeader(PdfPTable table) { PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(Color.LIGHT_GRAY); cell.setPadding(5); Font font = FontFactory.getFont(FontFactory.HELVETICA); font.setColor(Color.BLACK); cell.setPhrase(new Phrase("Заголовок", font)); table.addCell(cell); cell.setPhrase(new Phrase("Описание", font)); table.addCell(cell); cell.setPhrase(new Phrase("Статус", font)); table.addCell(cell); cell.setPhrase(new Phrase("Приоритет", font)); table.addCell(cell); cell.setPhrase(new Phrase("Категория", font)); table.addCell(cell); } private void writeTableData(PdfPTable table) { for (Task task : taskList) { table.addCell(task.getTitle()); table.addCell(task.getDescription()); table.addCell(task.getStatus().toString()); // исправлено table.addCell(task.getPriority().toString()); // исправлено table.addCell(task.getCategory()); } } }