Fix font & pdf conversion method
This commit is contained in:
parent
72ff399bcd
commit
3f045eaf53
|
@ -8,10 +8,11 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
|||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||
import org.apache.pdfbox.pdmodel.font.PDType0Font;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -48,6 +49,17 @@ public class WeatherEntry {
|
|||
public static void saveToPdf() throws IOException {
|
||||
// zapis do txt
|
||||
String txtFile = "src/weather-results/temp/temp.txt";
|
||||
|
||||
Path parentFolderPath = Paths.get("src/weather-results/temp");
|
||||
File folder = parentFolderPath.toFile();
|
||||
if (!folder.exists()) {
|
||||
try {
|
||||
Files.createDirectories(parentFolderPath);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Brak folderu `src/weather-results/temp`. Tworzenie folderu nie powiodlo sie.");
|
||||
}
|
||||
}
|
||||
|
||||
try (FileWriter writer = new FileWriter(txtFile)) {
|
||||
for (WeatherEntry entry : allEntries) {
|
||||
writer.write(entry.toString() + System.lineSeparator());
|
||||
|
@ -63,7 +75,7 @@ public class WeatherEntry {
|
|||
try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
|
||||
List<String> lines = Files.readAllLines(Paths.get(txtFile));
|
||||
|
||||
PDFont font = PDType0Font.load(document, new File("C:\\Users\\user\\IdeaProjects\\PRA2024\\AbhayaLibre-Regular.ttf"));
|
||||
PDFont font = PDType0Font.load(document, new File("AbhayaLibre-Regular.ttf"));
|
||||
int yPosition = 700;
|
||||
for (String line : lines) {
|
||||
contentStream.beginText();
|
||||
|
@ -98,7 +110,7 @@ public class WeatherEntry {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("Pogoda w %s:\n%s, temperatura: %.2f C; cisnienie: %d hPa; wilgotnosc: %d%%\n",
|
||||
return String.format("Pogoda w %s:\n%s, temperatura: %.2f C; ciśnienie: %d hPa; wilgotność: %d%%\n",
|
||||
miasto, pogoda, temperatura, cisnienie, wilgotnosc);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue