Writing a PDF in Eclipse with Processing

Hi,

I'm new with processing and getting into the Java worlds. I have created a sketch in processing (To create a pdf report loading result from a txt file). Now I'm planing to do the same but with a UI in Eclipse. I managed to create the two classes in eclipse and I can se the final result in the screen. The problem is when I want to create the PDF file.

I have checked the link: https://forum.processing.org/two/discussion/10272/using-creategraphics-in-eclipse

Made some changes to my code but still getting an error. I'm getting familiar with Java and Processing :) .

This is the code that works

FIRST CLASS

package lab1.reports;
import processing.core.*;

public class ReportResult {

    //variables
    PApplet p;
    PGraphics pdf;

    float xInicial;
    float xPos;
    float yPos;
    float result;
    float scale;
    float margin = 32;
    float limit;
    float scaleResult;
    String textTest;
    String textUnit;
    String textResult;
    String name;
    String rid;
    String birthDay;
    String dateTaking; 
    String date;
    String fileName ="Treningsstatus.pdf";

    //Creating constructor
    public ReportResult(PApplet _p, float _xtemp, float _ytemp){
        p = _p;
        xInicial = _xtemp;
        yPos = _ytemp;
       // pdf = p.createGraphics(595, 841, PConstants.PDF, fileName);
    }


    //Calculate Simple
    public void calculateSingle(float resultTemp, float scaleTemp, float limiTemp){
        result = resultTemp;
        scaleResult = scaleTemp;
        limit = limiTemp;

        xPos = (margin + xInicial) +(result * scaleResult);

        if(result > limit){
            xPos = margin + xInicial + 260;
        }
    }

    //Calculate Complex
    public void calculateComplex(float resultTemp, float inicialScale, float scaleTemp, float limitTemp ){
      result = resultTemp;
      scaleResult = result - inicialScale;
      scale = scaleTemp;
      limit = limitTemp;

      xPos = (margin + xInicial) + (scaleResult * scale);

      if (result > limit){
          xPos = margin + xInicial + 260;
      }
    }

    //Display result point
    public void displayResultText(String textTestTemp, String textUnitTemp){
        textTest = textTestTemp;
        textUnit = textUnitTemp;

        //Ellipse result
        p.noStroke();
        p.fill(56, 72, 96);
        p.ellipse(xPos, yPos, 5, 5);

        //Test Text
        p.textMode(4);
        //p.textFont(f);
        p.textAlign(37);
        textResult = textTest + ": " + result + " " + textUnit;
        p.text(textResult, margin+ xInicial, yPos - 8);
    }

    //Display result number
    public void displayResultNumber(float resultTemp, float xP, float yP){
        xPos = xP;
        yPos = yP;
        result = resultTemp;

        //Test Text
        //p.textFont(g);
        p.textAlign(3, 3);
        p.text(result, xPos, yPos);
    }

    //Patient Information
    public void patientInfo(String nameTemp, String ridTemp, String birthDayTemp, String dateTemp, String todayTemp){
        name = nameTemp;
        rid = ridTemp;
        dateTaking = dateTemp;
        birthDay = birthDayTemp;
        date = todayTemp;

        //Text cofiguration
        p.fill(56,72,96);
        p.textMode(4);
        //p.textFont(f);
        p.textAlign(3,3);

        //Patient Name
        p.text(name, 95, 90);

        //Patient Birthday
        p.text(birthDay, 223, 90);

        //Patient RID
        p.text(rid, 343, 90);

        //Patient sample taking and report
        p.textAlign(37);
        p.text(dateTaking, 485, 79);
        p.text(date, 485, 92,5);
    }

//    public void getSvgFile(PShape svgFile, int x, int y, int width, int height){
//        pdf.shape(svgFile, 0, 0, width, height);
//    }
//    
//    public void startDraw(){
//        pdf.beginDraw();
//    }
//    
//    public void finishDraw(){
//        pdf.endDraw();
//    }
//    
//    public void savePDF(){
//        pdf.save("report.jpg");
//    }
//    

}

SECOND CLASS - MAIN SKETCH

package lab1.reports;

//Import processing Libraries
import processing.core.*;

//Extend class to PApplet to use processing Libraries
public class TreningsStatus extends PApplet{

    //GLOBAL VARIABLES
    PShape ernBars1, ernBars2, ernBars3, ernBars4;
    PGraphics pdf;


    //OBJECTS
    ReportResult patient;
    ReportResult kalsium;
    ReportResult magnesiumSerum;
    ReportResult magnesiumFullblood;
    ReportResult vitaminD;
    ReportResult ferretin;
    ReportResult hemoglobin;
    ReportResult asat;
    ReportResult kreatinin;
    ReportResult urinstoff;
    ReportResult testosteron;
    ReportResult estrogen;
    ReportResult kolesterol;
    ReportResult crp;
    ReportResult kreatininKinase;
    ReportResult hba1c;
    ReportResult svgFile;

    //Create the main class
    public static void main(String[] args) {
        //PApplet.main(new String[] {report.FirstSketch.sketch.class.getName()});
        PApplet.main(new String[] {lab1.reports.TreningsStatus.class.getName()});
    }


    //Override class settings
    @Override
    public void settings(){
        //Document size        
        size(595, 841);
    }

    //Override class setup
    @Override
    public void setup(){
        background(255,255,255);

        //Fonts
        //f = createFont("Myriad", 50);
        //g = createFont("Myriad", 18);


        //Base vectors
        ernBars1 = loadShape("Treningsstatus-01.svg");
        ernBars2 = loadShape("Treningsstatus-02.svg");
        ernBars3 = loadShape("Treningsstatus-03.svg");
        ernBars4 = loadShape("Treningsstatus-04.svg");

        //pdf = createGraphics(595, 841, PDF, "TreningsStatus.pdf");
        //pdf.beginDraw();

        svgFile = new ReportResult(this, 0, 0);

        //Patient information
        patient = new ReportResult(this, 0, 0);

        //Page No1
        kalsium = new ReportResult(this, 0,181.5f);
        magnesiumSerum = new ReportResult(this, 270, 181.5f);
        magnesiumFullblood = new ReportResult(this, 270, 222);
        vitaminD = new ReportResult(this, 0, 222);
        ferretin = new ReportResult(this, 0, 0);
        hemoglobin = new ReportResult(this, 0, 0);
        asat = new ReportResult(this, 0, 0);
        kreatinin = new ReportResult(this, 0, 0);
        urinstoff = new ReportResult(this, 0, 480);
        testosteron = new ReportResult(this, 0, 0);
        estrogen = new ReportResult(this, 0, 0);
    }


    //Override class draw
    @Override
    public void draw(){
    shape(ernBars1, 0, 0, width , height);
    //svgFile.getSvgFile(ernBars1, 0, Y, width, height);


     patient.patientInfo("Jaime Castrillo", "39094698", "26.09.85", "02.02.16", "01.02.15");

     //Kalsium 
     kalsium.calculateSingle(1.5f, 65, 4);
     kalsium.displayResultText("Kalsium", "mmol/L");

     //Magnesium i serum
     magnesiumSerum.calculateSingle(1.11f, 117.11711f, 2.22f);
     magnesiumSerum.displayResultText("Magnesium i serum", "mmol/L");

     //Magnesium i fullblod
     magnesiumFullblood.calculateComplex(36, 28, 16.25f, 44);
     magnesiumFullblood.displayResultText("Magnesium i fullblod", "mg/L");

     //VitaminD
     vitaminD.calculateSingle(58, 0.7428f, 450);
     vitaminD.displayResultText("Vitamin D", "nmol/L");

     //Ferretin
     ferretin.displayResultNumber(25, 336, 261);

     //Hemåoglobin
     hemoglobin.displayResultNumber(150, 65, 263);

     //ASAT
     asat.displayResultNumber(30, 65, 435);

     //Kreatinin 
     kreatinin.displayResultNumber(56, 336, 436);

     //Urinstoff
     urinstoff.calculateSingle(4.1f, 15.8536f, 16.4f);
     urinstoff.displayResultText("Urinstoff", "mmol/L");

     //Testosteron
     testosteron.displayResultNumber(1.3f, 65, 652);

     //Estrogen
     estrogen.displayResultNumber(613, 336, 651);

    }
}
Tagged:

Answers

Sign In or Register to comment.