Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

PDF - Variable Column Widths

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PDF - Variable Column Widths

    I have been able to accomplish almost everything that I needed so far when creating my first PDF report using your book. You have provided an excellent set of tools to get started. But there is one thing that is causing me some problems: How do you specify variable column widths when setting up a new table.

    The following instruction will create a table with two columns:
    airTable = new_PdfPTable(2);

    How do I specify that the first column must be twice as large as the second column?

    I know that you can specify relative column widths when creating a table, but I can't figure out how to pass the values as parameters.

    Thanks in advance for any clues you can provide.

  • #2
    If you want to set one of the columns to be twice as large as the others, you can use setColSpan. You can see in the PDF table example that the header is setting the column span to 4

    PdfPCell_setColSpan(airCell: 4);

    For your example, you can set the first column to have a column span of 2:

    PdfPCell_setColSpan(airCell: 2);



    For your particular example, you could change the size of the table to be a width of 3, instead of 2, and make the first column span to be 2 and leave the third column at 1.

    Let me know if this is what you are looking for.

    Thanks,
    Tom
    Last edited by T.Snyder; 05-03-2010, 12:06 PM. Reason: 3/2 Example

    Comment


    • #3
      Thanks for the reply. This works for the example that I described. But would there be a way to create a table specifying the width for each column, using the following constructor:

      PdfPTable
      public PdfPTable(float[] relativeWidths)

      Constructs a PdfPTable with the relative column widths.

      Parameters:
      relativeWidths - the relative column widths

      Comment


      • #4
        Before I start answering this question, I would like to indicate to anyone who is new to this topic and interested in researching this, that this is an advanced topic and it is normally not this involved

        So your question is not so much how do you set the columns, because you already found the
        answer to that in the JavaDocs for iText, but the question is how do you pass an array of
        primitives into a Java constructor through JNI from Java.

        You know, I really wanted to put that into the book, but I couldn't come up with a practical
        example of using it. But, now I do! Thanks.

        Setting the Table Column is the easy part, You could pass in the relative columns widths to
        the constructor, as you have already indicated, or you can just use the setWidths method of the PdfPTable class.

        You'll have to get into some JNI stuff to create the array of primitives. Let me put
        together some code for you that you could try out. But, for now to get started, here is
        some code I have done with an integer array that will get you started:

        For the variable:

        D airIntArray S like(jIntArray)
        D airWidth S like(jInt)

        To create the primitive array and assign the values, this example has argWidths as an RPG
        array:

        airIntArray = NewIntArray(JNIEnv_P: size);
        airWidth = argWidths(1);
        SetIntArrayRegion(JNIEnv_P: airIntArray: 0: 1:
        airWidth);
        airWidth = argWidths(2);
        SetIntArrayRegion(JNIEnv_P: airIntArray: 1: 1:
        airWidth);
        airWidth = argWidths(3);
        SetIntArrayRegion(JNIEnv_P: airIntArray: 2: 1:
        airWidth);
        airWidth = argWidths(4);
        SetIntArrayRegion(JNIEnv_P: airIntArray: 3: 1:
        airWidth);

        To call the setWidths method of PdfPTable with an Integer Array

        //
        // Create Conversion Descriptor for CCSID conversions
        // EBCDIC->ASCII conversion
        toCCSID = 1208;
        cd = Air_openConverter(toCCSID);
        ebcdicString = 'com/lowagie/text/pdf/PdfPTable';
        asciiPdfPTable = Air_convert(cd: %trim(ebcdicString));
        ebcdicString = 'setWidths';
        asciiSetWidths = Air_convert(cd: %trim(ebcdicString));
        ebcdicString = '([I)V';
        asciiSignature = Air_convert(cd: %trim(ebcdicString));
        // Get the PdfPTable_setWidths Method and call it.
        tableClass = FindClass(JNIEnv_P:%trim(asciiPdfPTable));
        if (Air_isJVMError());
        displayString = 'FindClass Error';
        DSPLY displayString;
        else;
        endif;
        // Get the setWidths Method ID using the CLASS
        setWidthsId = GetMethodID(JNIENV_p:tableClass
        :%trim(asciiSetWidths)
        :%trim(asciiSignature));
        if (Air_isJVMError());
        displayString = 'GetMethodID Error';
        DSPLY displayString;
        else;
        endif;
        // Call the PdfPTable setWidths Method
        CallPdfPTableSetWidths(JNIEnv_P:argTable:
        setWidthsID:airIntArray);
        if (Air_isJVMError());
        displayString = 'PdfPTableSetWidths Error';
        DSPLY displayString;
        else;
        endif;

        For your example, you would need to change the call to the setWidths method to utilize the
        object constructor. You will need to use <init> with that.

        This isn't exactly your answer, but it may have all the pieces you need to get it to work.
        I was thinking of setting up some kind of a wiki on my website http:\\www.2wolvesout.com to
        provide a resource for the book. Let me know if you get it working with the constructor,
        otherwise I'll try to get you an example of passing the primitive array to the constructor
        when I can. I didn't want to hold you up waiting for an exact answer, but hopefully this helps.

        Enjoy,
        Tom
        Last edited by T.Snyder; 05-05-2010, 11:47 AM. Reason: HTML Encoding for init

        Comment

        Working...
        X