<commit_before>package cz.kamenitxan.labelprinter;

import cz.kamenitxan.labelprinter.models.Manufacturer;
import cz.kamenitxan.labelprinter.models.Product;
import org.apache.pdfbox.contentstream.PDContentStream;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font;

import java.awt.*;
import java.io.*;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.util.Matrix;


public class PdfGenerator {
    public static final float pageWidth = 843;
    public static final float pageHeight = 596;
    public static final PDRectangle PAGE_SIZE_A4 = new PDRectangle( pageHeight, pageWidth );
    
    public static final float lamdaImageWidth = 90;
    public static final float lamdaImageHeight  = 196;
    public static final float labelImageWidth = 15;
    public static final float labelImageHeight  = 67;
    
    

    public static void generatePdf(Product product, ArrayList<Manufacturer> manufacturers){
        for (Manufacturer manufacturer : manufacturers) {
            PDDocument document = new PDDocument();

            PDPage page = new PDPage(PAGE_SIZE_A4);
            document.addPage(page);

            page.setRotation(90);

            PDPageContentStream contentStream;

            try {
                contentStream = new PDPageContentStream(document, page);
                Main.class.getResource("OpenSans-Regular.ttf").getPath();
                PDType0Font font = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\OpenSans-Regular.ttf"));
                PDType0Font boldFont = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\OpenSans-Bold.ttf"));
                //obrazky
                PDImageXObject lamdaImage = PDImageXObject.createFromFile("img/lamda.jpg", document);
                PDImageXObject labelImage = PDImageXObject.createFromFile("img/label.jpg", document);
                if (!System.getProperty("os.name").equals("Mac OS X")) {
                    font = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\src\\cz\\kamenitxan\\labelprinter\\OpenSans-Regular.ttf"));
                    boldFont = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\src\\cz\\kamenitxan\\labelprinter\\OpenSans-Bold.ttf"));
                    lamdaImage = PDImageXObject.createFromFile("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\lamda.jpg", document);
                    labelImage = PDImageXObject.createFromFile("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\label.jpg", document);
                }

                float firstH = 0;
                float secondH = pageHeight/3;
                float thirdH = 2*secondH;

                //barevne obdelniky
                paintRectangle(firstH, contentStream, getProductColor(product.color));
                paintRectangle(secondH, contentStream, getProductColor(product.color));
                paintRectangle(thirdH, contentStream, getProductColor(product.color));


                contentStream.drawImage(lamdaImage, 0, ((pageWidth / 3) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(lamdaImage, 0, ((4 * (pageWidth / 5)) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(labelImage, ((pageHeight / 3) - labelImageWidth - 5), ((pageWidth / 3) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);
                contentStream.drawImage(labelImage, ((pageHeight / 3) - labelImageWidth - 5), ((4 * (pageWidth / 5)) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);

                contentStream.drawImage(lamdaImage, pageHeight / 3, ((pageWidth / 3) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(lamdaImage, pageHeight / 3, ((4 * (pageWidth / 5)) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(labelImage, ((2 * (pageHeight / 3)) - labelImageWidth - 5), ((pageWidth / 3) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);
                contentStream.drawImage(labelImage, ((2 * (pageHeight / 3)) - labelImageWidth - 5), ((4 * (pageWidth / 5)) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);<commit_msg>zmena souboru<commit_after>package cz.kamenitxan.labelprinter;

import cz.kamenitxan.labelprinter.models.Manufacturer;
import cz.kamenitxan.labelprinter.models.Product;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.util.Matrix;

import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;


public class PdfGenerator {
    public static final float pageWidth = 843;
    public static final float pageHeight = 596;
    public static final PDRectangle PAGE_SIZE_A4 = new PDRectangle( pageHeight, pageWidth );
    
    public static final float lamdaImageWidth = 90;
    public static final float lamdaImageHeight  = 196;
    public static final float labelImageWidth = 15;
    public static final float labelImageHeight  = 67;
    
    

    public static void generatePdf(Product product, ArrayList<Manufacturer> manufacturers){
        for (Manufacturer manufacturer : manufacturers) {
            PDDocument document = new PDDocument();

            PDPage page = new PDPage(PAGE_SIZE_A4);
            document.addPage(page);

            page.setRotation(90);

            PDPageContentStream contentStream;

            try {
                contentStream = new PDPageContentStream(document, page);
                //Main.class.getResource("OpenSans-Regular.ttf").getPath();
                //PDType0Font font = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\OpenSans-Regular.ttf"));
                //PDType0Font boldFont = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\OpenSans-Bold.ttf"));
                PDType0Font font = PDType0Font.load(document, new File("img/OpenSans-Regular.ttf"));
                PDType0Font boldFont = PDType0Font.load(document, new File("img/OpenSans-Bold.ttf"));
                //obrazky
                PDImageXObject lamdaImage = PDImageXObject.createFromFile("img/lamda.jpg", document);
                PDImageXObject labelImage = PDImageXObject.createFromFile("img/label.jpg", document);
                /*if (!System.getProperty("os.name").equals("Mac OS X")) {
                    font = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\src\\cz\\kamenitxan\\labelprinter\\OpenSans-Regular.ttf"));
                    boldFont = PDType0Font.load(document, new File("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\src\\cz\\kamenitxan\\labelprinter\\OpenSans-Bold.ttf"));
                    lamdaImage = PDImageXObject.createFromFile("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\lamda.jpg", document);
                    labelImage = PDImageXObject.createFromFile("C:\\Users\\Kateřina\\Documents\\GitHub\\Label-printer\\img\\label.jpg", document);
                }*/

                float firstH = 0;
                float secondH = pageHeight/3;
                float thirdH = 2*secondH;

                //barevne obdelniky
                paintRectangle(firstH, contentStream, getProductColor(product.color));
                paintRectangle(secondH, contentStream, getProductColor(product.color));
                paintRectangle(thirdH, contentStream, getProductColor(product.color));


                contentStream.drawImage(lamdaImage, 0, ((pageWidth / 3) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(lamdaImage, 0, ((4 * (pageWidth / 5)) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(labelImage, ((pageHeight / 3) - labelImageWidth - 5), ((pageWidth / 3) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);
                contentStream.drawImage(labelImage, ((pageHeight / 3) - labelImageWidth - 5), ((4 * (pageWidth / 5)) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);

                contentStream.drawImage(lamdaImage, pageHeight / 3, ((pageWidth / 3) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(lamdaImage, pageHeight / 3, ((4 * (pageWidth / 5)) - (lamdaImageHeight / 2)), lamdaImageWidth, lamdaImageHeight);
                contentStream.drawImage(labelImage, ((2 * (pageHeight / 3)) - labelImageWidth - 5), ((pageWidth / 3) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);
                contentStream.drawImage(labelImage, ((2 * (pageHeight / 3)) - labelImageWidth - 5), ((4 * (pageWidth / 5)) - (labelImageHeight / 2)), labelImageWidth, labelImageHeight);
{'fraction_non_alphanumeric': 0.1224213377787039, 'fraction_numerical': 0.013544488435090644, 'mean_word_length': 2.9879518072289155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '407956', 'n_tokens_mistral': 2969, 'n_tokens_neox': 2739, 'n_words': 510}