Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:55:16+00:00 2026-06-14T22:55:16+00:00

I’m developing an itext project with java. Basicly, in my project, i put 2

  • 0

I’m developing an itext project with java. Basicly, in my project, i put 2 logos on every page dynamicly(one logo on the top of the each pages and one address image on the bottom of the pages). But, when i want to add a table on the page, if the table has so many rows, on the certain point, the rows of the table becomes on the addres image, but i want the rows wrap to another page, so the rows of the table and the address image do not mix.

Here’s the picture what i want to explain:

http://img801.imageshack.us/img801/8074/tablejj.jpg

Thanks for your help.

Here’s my main fonc.:

public static void main(String[] args) {

    EventQueue.invokeLater(new Runnable() {

        public void run() {
            try {

                final denem2321 frame = new denem2321();
                frame.setVisible(true);

                // ///////////////

                frame.getMntmNewMenuItem_1().addActionListener(
                        new ActionListener() {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                final Teklif frame1 = new Teklif(list
                                        .getSelectedItem(), contactName
                                        .get(list.getSelectedItem()),
                                        hashMapReferansNameAndUrl);

                                frame1.setVisible(true);
                                JOptionPane.showMessageDialog(
                                        frame,
                                        list.getSelectedItem()
                                                + " firması için bir teklif hazırlayınız");

                                String imageUrl = "/Users/nofear/workspace/deneme23/pics/a4-ust.png";
                                String imageUrlAlt = "pics/a4-alt.png";


                                try {
                                    imageust = Image
                                            .getInstance(imageUrl);
                                } catch (BadElementException e3) {
                                    // TODO Auto-generated catch block
                                    e3.printStackTrace();
                                } catch (MalformedURLException e3) {
                                    // TODO Auto-generated catch block
                                    e3.printStackTrace();
                                } catch (IOException e3) {
                                    // TODO Auto-generated catch block
                                    e3.printStackTrace();
                                }


                                try {
                                    imageAlt = Image
                                            .getInstance(imageUrlAlt);
                                } catch (BadElementException e3) {
                                    // TODO Auto-generated catch block
                                    e3.printStackTrace();
                                } catch (MalformedURLException e3) {
                                    // TODO Auto-generated catch block
                                    e3.printStackTrace();
                                } catch (IOException e3) {
                                    // TODO Auto-generated catch block
                                    e3.printStackTrace();
                                }


                                imageust.setAbsolutePosition(
                                        0f,
                                        document.getPageSize()
                                                .getHeight()
                                                - imageust
                                                        .getHeight()-15
                                                );
                                imageAlt.setAbsolutePosition(
                                        0f, 0);






                                System.out
                                        .println("HEIGTG"
                                                + (document
                                                        .getPageSize()
                                                        .getHeight() - imageust
                                                        .getHeight()));





                                frame1.getButtonAl().addActionListener(
                                        new ActionListener() {

                                            @Override
                                            public void actionPerformed(
                                                    ActionEvent arg0) {

                                                try {
                                                    final PdfWriter writer = PdfWriter
                                                            .getInstance(
                                                                    document,
                                                                    new FileOutputStream(
                                                                            "output.pdf"));
                                                    document.open();



                                                    final PdfContentByte cb = writer
                                                            .getDirectContent();

                                                    writer.setPageEvent(new PdfPageEvent() {

                                                        @Override
                                                        public void onStartPage(PdfWriter arg0, Document arg1) {



                                                        }

                                                        @Override
                                                        public void onSectionEnd(PdfWriter arg0, Document arg1, float arg2) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onSection(PdfWriter arg0, Document arg1, float arg2, int arg3,
                                                                Paragraph arg4) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onParagraphEnd(PdfWriter arg0, Document arg1, float arg2) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onParagraph(PdfWriter arg0, Document arg1, float arg2) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onOpenDocument(PdfWriter arg0, Document arg1) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onGenericTag(PdfWriter arg0, Document arg1, Rectangle arg2,
                                                                String arg3) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onEndPage(PdfWriter arg0, Document arg1) {

                                                            try {
                                                                cb.addImage(imageust);
                                                                cb.addImage(imageAlt);
                                                            } catch (DocumentException e) {
                                                                // TODO Auto-generated catch block
                                                                e.printStackTrace();
                                                            }

                                                        }

                                                        @Override
                                                        public void onCloseDocument(PdfWriter arg0, Document arg1) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onChapterEnd(PdfWriter arg0, Document arg1, float arg2) {
                                                            // TODO Auto-generated method stub

                                                        }

                                                        @Override
                                                        public void onChapter(PdfWriter arg0, Document arg1, float arg2,
                                                                Paragraph arg3) {
                                                            // TODO Auto-generated method stub

                                                        }
                                                    });




                                                    // now draw a line below
                                                    // the headline
                                                    cb.setLineWidth(1f);


                                                    cb.stroke();

                                                    // ////////////////////////////////////

                                                    try {
                                                        bfArial = BaseFont
                                                                .createFont(
                                                                        "C:/Windows/Fonts/arial.ttf",
                                                                        "Cp1254",
                                                                        BaseFont.NOT_EMBEDDED);
                                                    } catch (DocumentException e1) {
                                                        // TODO
                                                        // Auto-generated
                                                        // catch block
                                                        e1.printStackTrace();
                                                    } catch (IOException e1) {
                                                        // TODO
                                                        // Auto-generated
                                                        // catch block
                                                        e1.printStackTrace();
                                                    }



                                                    Font baslikFont = new Font(
                                                            bfArial, 24,
                                                            Font.BOLD);

                                                    Font pdfBaslikFont = new Font(
                                                            bfArial, 16,
                                                            Font.NORMAL);

                                                    Font pdfTarihFont = new Font(
                                                            bfArial, 12,
                                                            Font.NORMAL);

                                                    Font altBaslik = new Font(
                                                            bfArial, 12,
                                                            Font.BOLD);

                                                    Font normalWritingFont = new Font(
                                                            bfArial, 12,
                                                            Font.NORMAL);



                                                    final ColumnText ct = new ColumnText(
                                                            cb);


                                                    Calendar currentDate = Calendar
                                                            .getInstance();
                                                    SimpleDateFormat formatter = new SimpleDateFormat(
                                                            "yyyy/MMM/dd");
                                                    String dateNow = formatter
                                                            .format(currentDate
                                                                    .getTime());


                                                    Phrase firmaBaslik = new Phrase(frame1.getTextField_teklifHazirlananFirmaAdi().getText(),
                                                            baslikFont);

                                                    Phrase pdfAltBaslik = new Phrase("WEB SİTESİ TASARIM ve PROGRAMLAMA ANLAŞMASI",pdfBaslikFont);

                                                    Phrase tarih = new Phrase(dateNow, pdfTarihFont);

                                                    Phrase alanAdlari = new Phrase("Sitenin Yayınlanacağı Alan Adları: ",altBaslik);
                                                    Phrase alanAdlarIcerik = new Phrase(frame1.getTextArea_alanAdlari().getText(),normalWritingFont);

                                                    Phrase webHosting = new Phrase("\n\nWebhosting & Yayınlama: ",altBaslik);
                                                    Phrase weHostingIcerik = new Phrase(frame1.getTextArea_webHosting().getText(),normalWritingFont);

                                                    Phrase siteDil = new Phrase("\n\nSitenin Dili: ",altBaslik);
                                                    Phrase siteDilIcerik = new Phrase(frame1.getTextArea_dil().getText(),normalWritingFont);

                                                    Phrase amac = new Phrase("\n\nAmaç: ",altBaslik);
                                                    Phrase amacIcerik = new Phrase(frame1.getTextArea_amac().getText(),normalWritingFont);

                                                    Phrase kullilanProgs = new Phrase("\n\nKullanılacak Programlar: ",altBaslik);
                                                    Phrase kullanilanProgsIcerik = new Phrase(frame1.getTextArea_kullanilacakProgramlar().getText(),normalWritingFont);

                                                    ct.setSimpleColumn(
                                                            firmaBaslik,
                                                            60,
                                                            750, /* width */
                                                            document.getPageSize()
                                                                    .getWidth() - 40,
                                                            30,
                                                            25,
                                                            Element.ALIGN_CENTER);
                                                    ct.go();

                                                    ct.setSimpleColumn(
                                                            pdfAltBaslik,
                                                            60,
                                                            650, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            25,
                                                            Element.ALIGN_CENTER);
                                                    ct.go();

                                                    ct.setSimpleColumn(
                                                            tarih,
                                                            60,
                                                            625, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            25,
                                                            Element.ALIGN_CENTER);
                                                    ct.go();



                                                    ct.setSimpleColumn(
                                                            alanAdlari ,
                                                            60,
                                                            550, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            25,
                                                            Element.ALIGN_LEFT);
                                                    ct.setSimpleColumn(
                                                            alanAdlarIcerik ,
                                                            60,
                                                            550, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            webHosting ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            25,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            weHostingIcerik ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            siteDil ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            siteDilIcerik ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            amac ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            amacIcerik ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            kullilanProgs ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);

                                                    ct.setSimpleColumn(
                                                            kullanilanProgsIcerik ,
                                                            60,
                                                            525, /* width */
                                                            document.getPageSize()
                                                            .getWidth() - 40,
                                                            30,
                                                            13,
                                                            Element.ALIGN_LEFT);


                                                    ct.go();


                                                    PdfPTable table = new PdfPTable(
                                                            2)          ;                                           
                                                    table.setTotalWidth(document
                                                            .getPageSize()
                                                            .getWidth() - 5);
                                                    table.getDefaultCell()
                                                            .setPadding(2);
                                                    table.getDefaultCell()
                                                            .setBorderWidth(1);
                                                    table.getDefaultCell()
                                                            .setHorizontalAlignment(
                                                                    Element.ALIGN_CENTER);

                                                    float[] columnWidths = {
                                                            10f, 2f, };

                                                    try {
                                                        table.setWidths(columnWidths);
                                                    } catch (DocumentException e) {
                                                        // TODO Auto-generated
                                                        // catch block
                                                        e.printStackTrace();
                                                    }
                                                    // table.setSpacingBefore(5f);

                                                    // Code 2
                                                    table.getDefaultCell()
                                                            .setGrayFill(0.9f);

                                                    table.addCell("WEB TASARIM VE PROGRAMLAMA");

                                                    table.addCell("TUTAR");
                                                    table.getDefaultCell()
                                                            .setBackgroundColor(
                                                                    new BaseColor(
                                                                            255,
                                                                            255,
                                                                            255));




                                                    document.add(table);
                                                    document.newPage();
                                                    document.add(new Paragraph("Yeni Sayfa"));





                                                } catch (Exception e) {
                                                } finally {
                                                    document.close();

                                                }

                                            }
                                        });


                            }
                        });





            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:55:18+00:00Added an answer on June 14, 2026 at 10:55 pm

    This is a non-question. iText breaks tables automatically when they don’t fit the current page, and forwards the remaining part to the next page.

    You’re adding headers and footers using page events, which is OK, but:

    1. you should define the margings of the Document object so that they take into account the height of the images you’re adding as header / footer.
    2. you’re not really adding much in your table object, but I see you using ColumnText with absolute positions that don’t seem to take into account any margins.

    In any case: your code is not well-written. You should clean it up. For instance: the way you define the page event is madness. You should use PdfPageEventHelper. I’m pretty sure nobody else but me will take a closer look at your code in its current state. Clean it up!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.