rakchouh 0 Newbie Poster

Hi,
I am writing the content of a long text file in pdf using PDFbox API in java but only half the page I am able to write please assit me with it asap here is my code:

import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.PDFont;

class WriteToPDF{

public WriteToPDF()
{

    resultArea();
}

public void resultArea()
{
        try
           {    PDDocument doc = null;
                 PDPage page = null;
                 BufferedReader fr1 = new BufferedReader(new FileReader("test.txt"));
                 BufferedReader fr2 = new BufferedReader(new FileReader("test2.txt"));
                          doc = new PDDocument();

                  page = new PDPage();

                  doc.addPage(page);
                  PDFont font = PDType1Font.HELVETICA;

                  PDPageContentStream content = new PDPageContentStream(doc, page, true, true);



            int xpos=20, ypos=760 ;

                     String res1, res2;
                 while((res1=fr1.readLine()) != null  )
                  {     content.beginText();            
                res2=fr2.readLine();
                if(res1.equals(res2))
                {


                          content.moveTextPositionByAmount( xpos,ypos );
                          content.drawString(res1);
                      ypos = ypos - 8;

                }
                else 
                {

                          content.moveTextPositionByAmount( xpos,ypos );
                          content.drawString(res2); 
                       ypos = ypos - 8;


                }
                content.endText();
                  }


                  content.close();
                 doc.save("PDFWithText.pdf");
                 doc.close();

                fr1.close();fr2.close();
               }
        catch(FileNotFoundException e)
            {
                System.out.println("File does not exist. " + e);
         }
      catch(Exception e)
       {
              System.out.println("Some I/O problem. " + e);
        }

}

public static void main(String args[])
  {
        WriteToPDF tsf = new WriteToPDF();

  }
}