0

ソース ファイルからいくつかの画像 (.jpg) とテキストを読み取り、それらを 1 つの PDF に組み立てるプログラムに取り組んでいます。処理はおそらくそれを行うのに最適な言語ではないことは知っていますが、それを行う方法を知っている唯一の言語です。とにかく、処理がセットアップを2回呼び出すという問題があります。size() がセットアップ内の最初の行である場合、この問題は解決されることがわかりましたが、すべてのデータを読み込んで保存し、最も広い画像の幅を見つけてから、それが発生することはありません。複数の画像を含むページに対応できる高さを確認し、ウィンドウの幅と高さを決定する前にテキストを追加します。セットアップを 2 回呼び出さなくてもすべての情報を取得できるように、コードをどのように構成するかについての提案を探しています。私のPDFにすべてのデータの2つのコピーが含まれています。誰にも役立つ場合は、セットアップを含めました。ありがとう!

void setup(){
  font = loadFont("TimesNewRomanPSMT-20.vlw");
  File clientsFolder = new File("C:/Users/[my name]/Documents/Processing/ExerciseProgram/Clients");
  clients = clientsFolder.listFiles();
  for(File x : clients){
    println(x.getName());
  }
  //test files to see if they end in .txt, and have a matching .pdf extension that is newer
  String nextClient = needPdf();

  File nextClientData = new File("C:/Users/[my name]/Documents/Processing/ExerciseProgram/Clients/" + nextClient);
  //println(nextClientData.getName());

  //open the file for reading
  //setup can't throw the exception, and it needs it, so this should take care of it
  try{
    Scanner scan = new Scanner(nextClientData);

    while(scan.hasNextLine() ){
      exercises.add(scan.nextLine());
    }
    //println(exercises.toString());
    printedData = new Exercise[exercises.size()];
    println(exercises.size());
    for(int i = 0; i < exercises.size(); i++){
      printedData[i] = new Exercise((String)exercises.get(i));
    }

    //count the width and height
    int w = 0, h = 0;
    for(Exercise e: printedData){
      if(e.getWidest() > w){
        w = e.getWidest();
      }
      if(e.getTallest() > h){
        h = e.getHeight();
      }
    }

    //and finally we can create the freaking window
    //                                         this cuts the .txt off
    size(w, h, PDF, "C:/Users/[my name]/Desktop/" + nextClient.substring(0, nextClient.length() - 4) + ".pdf");

  }catch (FileNotFoundException e){
    println("Unknown error in PApplet.setup(). Exiting.");
    println(e.getMessage() );
    exit(); 
  }
}
4

2 に答える 2