Example usage for com.lowagie.text PageSize LETTER

List of usage examples for com.lowagie.text PageSize LETTER

Introduction

In this page you can find the example usage for com.lowagie.text PageSize LETTER.

Prototype

Rectangle LETTER

To view the source code for com.lowagie.text PageSize LETTER.

Click Source Link

Document

This is the letter format

Usage

From source file:gov.noaa.pfel.coastwatch.CWUser.java

License:Open Source License

/** 
 * This does most of the work (validate each screen, generate html,
 * and create the files)./*from  w ww.j a v  a2  s  .  c  om*/
 *
 * @param request is a request from a user
 * @param htmlSB 
 * @return true if successful (no exceptions thrown)
 */
public boolean getHTMLForm(HttpServletRequest request, StringBuilder htmlSB, long startTime) {
    boolean succeeded = true;

    try {
        if (oneOf.verbose())
            String2.log("\n************ getHTMLForm");

        IntObject step = new IntObject(1); //the next step number for the user
        IntObject rowNumber = new IntObject(0);

        //do some preliminary work on tRegion since it affects customRegionsImage
        int tRegion = mapScreen().region.indexOf(mapScreen.region.getValue(session));
        if (oneOf.verbose())
            String2.log("tRegion=" + tRegion + "=" + mapScreen.region.getValue(session));
        String customRegionsImage = createCustomRegionsImage(session); //used a few lines below
        boolean displayErrorMessages = false;//an EMA setting; always false

        //validate the 'edit' widget
        int editIndex = edit().getSelectedIndex(session);
        if (editIndex < 0) {
            editIndex = 0;
            edit().setValue(session, edit().getOption(0));
        }

        //show (show = editIndex, but equals -1 if a getXxx button pressed)
        //  Thus, show reflects which screen is shown to the user.
        int show = editIndex;
        String submitter = emaClass().getSubmitterButtonName(request);
        if (submitter.length() > 0) {
            if (mapScreen.submitterIsAGetButton(submitter) || gridScreen.submitterIsAGetButton(submitter)
                    || contourScreen.submitterIsAGetButton(submitter)
                    || vectorScreen.submitterIsAGetButton(submitter)
                    || pointVectorScreen.submitterIsAGetButton(submitter))
                show = -1;
            for (int ps = 0; ps < nPointScreens; ps++)
                if (pointScreen(ps).submitterIsAGetButton(submitter))
                    show = -1;
            for (int ts = 0; ts < nTrajectoryScreens; ts++)
                if (trajectoryScreen(ts).submitterIsAGetButton(submitter))
                    show = -1;
        }

        //display the 'edit' row on the form
        if (show >= 0) {
            //the start of the HTML form and the HTML Table
            htmlSB.append(emaClass().getStartOfHTMLForm());

            //the 'edit' row
            htmlSB.append("    <tr style=\"background-color:#" + oneOf.backgroundColor(0) + ";\">\n"
                    + "      <td>" + edit.getLabel() + "&nbsp;</td>\n" + "      <td style=\"width:90%;\">"
                    + edit.getControl(edit.getValue(session)) + "</td>\n");
        }

        //did user click on the map?    (after 'show' is known)
        //get x,y from query
        String query = request.getQueryString();
        String2.log("Query: " + query);
        if (query != null && query.matches("\\d+,\\d+")) { //digits,digits
            String lastImageFileName = (String) session.getAttribute("lastImageFileName");
            if (lastImageFileName != null) {
                IntArray graphLocation = OneOf.getGraphLocation(lastImageFileName);
                if (graphLocation != null) {
                    double ttMinX = mapScreen.minX.getDouble(session);
                    double ttMaxX = mapScreen.maxX.getDouble(session);
                    double ttMinY = mapScreen.minY.getDouble(session);
                    double ttMaxY = mapScreen.maxY.getDouble(session);

                    int po = query.indexOf(',');
                    int pixelX = String2.parseInt(query.substring(0, po));
                    int pixelY = String2.parseInt(query.substring(po + 1));

                    int originXPixel = graphLocation.get(0);
                    int endXPixel = graphLocation.get(1);
                    int originYPixel = graphLocation.get(2);
                    int endYPixel = graphLocation.get(3);
                    double lon = ttMinX
                            + ((ttMaxX - ttMinX) * (pixelX - originXPixel)) / (endXPixel - originXPixel);
                    double lat = ttMinY
                            + ((ttMaxY - ttMinY) * (pixelY - originYPixel)) / (endYPixel - originYPixel);
                    lon = Math2.roundTo(lon, 3);
                    lat = Math2.roundTo(lat, 3);
                    String2.log("Edit==Grid? " + (show == gridScreen.editOption()) + " clickX=" + pixelX + " y="
                            + pixelY + " -> lon=" + lon + " lat=" + lat + "\n ttMinX=" + ttMinX + " ttMaxX="
                            + ttMaxX + " ttMinY=" + ttMinY + " ttMaxY=" + ttMaxY + "\n originXPixel="
                            + originXPixel + " endXPixel=" + endXPixel + " originYPixel=" + originYPixel
                            + " endYPixel=" + endYPixel);
                    boolean queryOk = lon >= ttMinX && lon <= ttMaxX && lat >= ttMinY && lat <= ttMaxY;
                    if (show == gridScreen.editOption()) {
                        gridScreen.timeSeriesLon.setValue(session, queryOk ? String2.genEFormat6(lon) : "");
                        gridScreen.timeSeriesLat.setValue(session, queryOk ? String2.genEFormat6(lat) : "");
                    } // else if ...
                }
            }
        }

        if (show == mapScreen.editOption()) {//map only visible mapScreen because it works on min/max/X/Y HTML components
            int mapScreenRows = 8;
            htmlSB.append("      <td rowspan=\"" + mapScreenRows + "\" style=\"background-color:#FFFFFF\">\n"
                    + "        <a href=\"" + emaClass.getUrl() + "\"" +
                    //onclick was here
                    ">" + //no \n or space gap before next thing

                    //Don't use ismap=\"ismap\" to call server side processing if client side isn't working.
                    //Now, isMap is used for user clicking on the map in the main image.
                    "<img src=\"" + customRegionsImage + "\" id=\"regionsImage\" \n" + "            alt=\""
                    + oneOf.regionsImageAlt() + "\" title=\"" + oneOf.regionsImageTitle() + "\"\n"
                    + "            width=\"" + oneOf.regionsImageWidth() + "\" height=\""
                    + oneOf.regionsImageHeight() + "\"\n" +
                    /*
                    //CLICK = CHANGE THE CENTER
                    "        onclick=\"javascript:\n" +
                    "          var form = document." + emaClass.getFormName() + ";\n" + 
                    //get eventX/Y where user clicked on the regionsImage (0,0 at upper left)
                    //the problem is that IE and Netscape do it differently
                    //this solution is adapted from 
                    //  http://www.faqts.com/knowledge_base/view.phtml/aid/9386/fid/122
                    //default = center of image (no change)
                    "          eventX = " + ((regionsImageMinXPixel + regionsImageMaxXPixel)/2) + ";\n" +
                    "          eventY = " + ((regionsImageMinYPixel + regionsImageMaxYPixel)/2) + ";\n" +
                    "          if (window.event) {\n" +
                    "            eventX = window.event.offsetX;\n" +
                    "            eventY = window.event.offsetY;\n" +
                    //IE and Opera use this code
                    //"            alert('upper handler: x=' + eventX + ' y=' + eventY);\n" +
                    "          } else if (event.target) {\n" +
                    "            eventX = event.clientX;\n" +
                    "            eventY = event.clientY;\n" +
                    "            var el = event.target;\n" +
                    "            do {\n" +
                    "              eventX -= el.offsetLeft;\n" +
                    "              eventY -= el.offsetTop;\n" +
                    "            } while ((el = el.offsetParent));\n" +
                    //FireFox uses this code            
                    //"            alert('lower handler: x=' + eventX + ' y=' + eventY);\n" +
                    "          }\n" +
                    "          var minXEl = form.minX;\n" +
                    "          var maxXEl = form.maxX;\n" +
                    "          var minYEl = form.minY;\n" +
                    "          var maxYEl = form.maxY;\n" +
                    "          if (!isFinite(minXEl.value)) minXEl.value = " + regionsImageMinXDegrees + ";\n" +
                    "          if (!isFinite(maxXEl.value)) maxXEl.value = " + regionsImageMaxXDegrees + ";\n" +
                    "          if (!isFinite(minYEl.value)) minYEl.value = " + regionsImageMaxYDegrees + ";\n" + //yes, reversed
                    "          if (!isFinite(maxYEl.value)) maxYEl.value = " + regionsImageMinYDegrees + ";\n" +
                    "          var xRange2 = Math.abs(maxXEl.value - minXEl.value) / 2;\n" +
                    "          var yRange2 = Math.abs(maxYEl.value - minYEl.value) / 2;\n" +
                    "          if (xRange2 == 0) xRange2 = 10;\n" +
                    "          if (yRange2 == 0) yRange2 = 10;\n" +
                    "          var centerX = " + regionsImageMinXDegrees + 
                    " + ((eventX - " + regionsImageMinXPixel + ")/" +
                    (regionsImageMaxXPixel - regionsImageMinXPixel) + 
                    ") * " + (regionsImageMaxXDegrees - regionsImageMinXDegrees) + ";\n" +
                    "          var centerY = " + regionsImageMinYDegrees + 
                    " + ((eventY - " + regionsImageMinYPixel + ")/" +
                    (regionsImageMaxYPixel - regionsImageMinYPixel) + 
                    ") * " + (regionsImageMaxYDegrees - regionsImageMinYDegrees) + ";\n" +
                    //Round to the nearest 0.5 (0.25 would probably also work well)   
                    //GMT doesn't handle < 0.25
                    //I wanted round to nearest .1, but *10 /10 leads to bruised numbers
                    "          minXEl.value = Math.round((centerX - xRange2)*2) / 2;\n" +
                    "          maxXEl.value = Math.round((centerX + xRange2)*2) / 2;\n" +
                    "          minYEl.value = Math.round((centerY - yRange2)*2) / 2;\n" +
                    "          maxYEl.value = Math.round((centerY + yRange2)*2) / 2;\n" +
                    "          form.submit();\"\n" +
                    */

                    //end of image tag        end of 'a' tag
                    //CLICK = A REGION       
                    "            usemap=\"#regionCoordinates\"></a>\n" +

                    oneOf.regionCoordinatesMap(emaClass.getFormName())
                    + "        <br><div style=\"text-align:center;\"><small>" + oneOf.regionsImageLabel()
                    + "</small></div></td>\n");

        }

        if (show >= 0) {
            htmlSB.append("    </tr>\n");
            rowNumber.i++;
        }

        //if animation requested, set synchronizeTimes to true
        if (submitter.equals(mapScreen.animationViewIt.getName()))
            mapScreen.synchronizeTimes.setValue(session, "true");

        //validate mapScreen first (region info need by other screens) and add 'show' screen to htmlSB  
        mapScreen.validate(session, show, step, rowNumber, htmlSB);
        double tMinX = mapScreen.minX.getDouble(session);
        double tMaxX = mapScreen.maxX.getDouble(session);
        double tMinY = mapScreen.minY.getDouble(session);
        double tMaxY = mapScreen.maxY.getDouble(session);
        String cWESNString = FileNameUtility.makeWESNString(tMinX, tMaxX, tMinY, tMaxY);

        //validate the editIndex screen first (so timePeriod and centeredTime are known for synchronizing dates)
        String synchTimePeriod = null;
        String synchCenteredTime = null;
        String synchBeginDate = null;
        if (editIndex == gridScreen.editOption()) {
            gridScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY, cWESNString,
                    mapScreen.imageSizeIndex);
            synchTimePeriod = gridScreen.timePeriod.getValue(session);
            synchCenteredTime = gridScreen.centeredTime.getValue(session);
            synchBeginDate = gridScreen.beginTime.getValue(session);
        } else if (editIndex == contourScreen.editOption()) {
            contourScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                    cWESNString, mapScreen.imageSizeIndex);
            synchTimePeriod = contourScreen.timePeriod.getValue(session);
            synchCenteredTime = contourScreen.centeredTime.getValue(session);
        } else if (editIndex == vectorScreen.editOption()) {
            vectorScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                    cWESNString, mapScreen.imageSizeIndex);
            synchTimePeriod = vectorScreen.timePeriod.getValue(session);
            synchCenteredTime = vectorScreen.centeredTime.getValue(session);
        } else if (editIndex == pointVectorScreen.editOption()) {
            pointVectorScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                    cWESNString, mapScreen.imageSizeIndex);
            synchTimePeriod = pointVectorScreen.timePeriod.getValue(session);
            synchCenteredTime = pointVectorScreen.centeredTime.getValue(session);
            synchBeginDate = pointVectorScreen.beginTime.getValue(session);
        } else {
            for (int ps = 0; ps < nPointScreens; ps++) {
                PointScreen tps = pointScreen[ps];
                if (editIndex == tps.editOption()) {
                    tps.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                            cWESNString);
                    synchTimePeriod = tps.timePeriod.getValue(session);
                    synchCenteredTime = tps.centeredTime.getValue(session);
                    synchBeginDate = tps.beginTime.getValue(session);
                }
            }
            for (int ts = 0; ts < nTrajectoryScreens; ts++) {
                TrajectoryScreen tts = trajectoryScreen[ts];
                if (editIndex == tts.editOption()) {
                    tts.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                            cWESNString);
                    //synchTimePeriod   = tts.timePeriod.getValue(session);
                    //synchCenteredTime = tts.endTime.getValue(session);
                    //synchBeginDate    = tts.startTime.getValue(session);
                    //String2.log("synchTimePeriod=" + synchTimePeriod + " synchCenteredTime=" + synchCenteredTime);
                }
            }
        }

        //synchronize the other timePeriods
        if (mapScreen.synchronizeTimesValue && synchTimePeriod != null) {
            if (editIndex != gridScreen.editOption())
                gridScreen.timePeriod.setValue(session, synchTimePeriod);
            //bathymetry has no date
            if (editIndex != contourScreen.editOption())
                contourScreen.timePeriod.setValue(session, synchTimePeriod);
            if (editIndex != vectorScreen.editOption())
                vectorScreen.timePeriod.setValue(session, synchTimePeriod);
            if (editIndex != pointVectorScreen.editOption())
                pointVectorScreen.timePeriod.setValue(session, synchTimePeriod);
            for (int ps = 0; ps < nPointScreens; ps++)
                if (editIndex != pointScreen(ps).editOption())
                    pointScreen(ps).timePeriod.setValue(session, synchTimePeriod);
            //trajectoryScreen currently not involved 
        }
        //synchronize the other centeredTimes
        if (mapScreen.synchronizeTimesValue && synchCenteredTime != null) {
            if (editIndex != gridScreen.editOption())
                gridScreen.centeredTime.setValue(session,
                        synchedTime(gridScreen.centeredTime.getValue(session), synchCenteredTime));
            //bathymetry has no centeredTime
            if (editIndex != contourScreen.editOption())
                contourScreen.centeredTime.setValue(session,
                        synchedTime(contourScreen.centeredTime.getValue(session), synchCenteredTime));
            if (editIndex != vectorScreen.editOption())
                vectorScreen.centeredTime.setValue(session,
                        synchedTime(vectorScreen.centeredTime.getValue(session), synchCenteredTime));
            if (editIndex != pointVectorScreen.editOption())
                pointVectorScreen.centeredTime.setValue(session,
                        synchedTime(pointVectorScreen.centeredTime.getValue(session), synchCenteredTime));
            for (int ps = 0; ps < nPointScreens; ps++)
                if (editIndex != pointScreen(ps).editOption())
                    pointScreen(ps).centeredTime.setValue(session,
                            synchedTime(pointScreen(ps).centeredTime.getValue(session), synchCenteredTime));
            //trajectoryScreen currently not involved
        }
        //synchronize the other beginTimes
        if (mapScreen.synchronizeTimesValue && synchBeginDate != null) {
            if (editIndex != gridScreen.editOption())
                gridScreen.beginTime.setValue(session, synchBeginDate);
            //bathymetry has no beginTime
            //if (editIndex != contourScreen.editOption()) contourScreen.beginTime.setValue(session, synchBeginDate);
            //if (editIndex != vectorScreen.editOption())  vectorScreen.beginTime.setValue(session, synchBeginDate);
            if (editIndex != pointVectorScreen.editOption())
                pointVectorScreen.beginTime.setValue(session, synchBeginDate);
            for (int ps = 0; ps < nPointScreens; ps++)
                if (editIndex != pointScreen(ps).editOption())
                    pointScreen(ps).beginTime.setValue(session, synchBeginDate);
            //trajectoryScreen currently not involved
        }

        //validate all the screens and add 'show' screen to htmlSB  
        if (editIndex != gridScreen.editOption())
            gridScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY, cWESNString,
                    mapScreen.imageSizeIndex);
        if (editIndex != contourScreen.editOption())
            contourScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                    cWESNString, mapScreen.imageSizeIndex);
        if (editIndex != vectorScreen.editOption())
            vectorScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                    cWESNString, mapScreen.imageSizeIndex);
        if (editIndex != pointVectorScreen.editOption())
            pointVectorScreen.validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                    cWESNString, mapScreen.imageSizeIndex);
        for (int ps = 0; ps < nPointScreens; ps++)
            if (editIndex != pointScreen(ps).editOption())
                pointScreen(ps).validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY, tMaxY,
                        cWESNString);
        for (int ts = 0; ts < nTrajectoryScreens; ts++)
            if (editIndex != trajectoryScreen(ts).editOption())
                trajectoryScreen(ts).validate(session, show, step, rowNumber, htmlSB, tMinX, tMaxX, tMinY,
                        tMaxY, cWESNString);

        //make the image;  this sets several instance variables
        ArrayList imageReturn = makeImage(synchCenteredTime);
        String imageFileName = (String) imageReturn.get(0);
        Table sgtMapResultsTable = (Table) imageReturn.get(1);
        int imageWidth2 = ((Integer) imageReturn.get(2)).intValue();
        ArrayList mapGDLs = (ArrayList) imageReturn.get(3);
        ArrayList graphGDLs = (ArrayList) imageReturn.get(4);
        String warning = (String) imageReturn.get(5);

        //store the imageFileName as the lastImageFileName for this user
        session.setAttribute("lastImageFileName", imageFileName);

        //end of table, end of form; display the image 
        if (show >= 0) {

            //display the map's Get options
            //This is a special case, since imageFileName isn't known until other screens are done.
            if (show == mapScreen.editOption())
                mapScreen.displayGetOptions(session, show, step, rowNumber, htmlSB, imageFileName);

            //display submitForm button
            //This isn't beginning of row, just set the color.
            emaClass().setBeginRow("<tr style=\"background-color:#" + oneOf.backgroundColor(3) + "\">");
            //old way
            //but 'noscript' must be between td /td tags to be HTML compliant. 
            htmlSB.append("    <noscript>\n"
                    + submitForm.getTableEntry(submitForm.getValue(session), displayErrorMessages)
                    + "    </noscript>\n");
            //new way
            //This causes thin empty row in table.
            //htmlSB.append(
            //    "    " + emaClass.getBeginRow() + "\n" + 
            //    "      <td><noscript>" + submitForm.getLabel() + "&nbsp;</noscript></td>\n" +
            //    "      <td><noscript>" + submitForm.getControl(submitForm().getValue(session)) + "</noscript></td>\n" +
            //    "    " + emaClass.getEndRow() + "\n");

            //end of form
            htmlSB.append(emaClass().getEndOfHTMLForm(startTime, mapScreen.hiddenInputStillPending));

            //generate the animated gif?  
            if (submitter.equals(mapScreen.animationViewIt.getName())) {
                String tName = createAnimatedGif(session, htmlSB);
                if (tName != null)
                    imageFileName = tName;
            }

            //display the map image (using isMap so gridScreen etc can lead to timeSeries)
            if (show == gridScreen.editOption()) {
                htmlSB.append( //href so isMap knows where to send results
                        "<a href=\"" + emaClass.getUrl() + "\">" + "  <img src=\"" + OneOf.PUBLIC_DIRECTORY
                                + imageFileName + "\"\n" + "      title=\"" + oneOf.clickOnMapToSeeTimeSeries()
                                + "\"\n" + "      ismap=\"ismap\" alt=\"" + oneOf.clickOnMapToSeeTimeSeries()
                                + "\"\n" + "      onclick=\"pleaseWait();\"\n" + "      width=\"" + imageWidth2
                                + "\" height=\"" + mapScreen.imageHeight + "\"></a>\n\n");
            } else {

                //create stationsUseMap innards if there is info (but not first or last line) 
                StringBuilder suMap = new StringBuilder();
                if (sgtMapResultsTable != null && sgtMapResultsTable.nRows() > 0) {
                    //String2.log("sgtMapResultsTable=" + sgtMapResultsTable);
                    //sgtMapResultsTable.isValid(); // for debugging purposes only
                    IntArray minXIA = (IntArray) sgtMapResultsTable.getColumn(0);
                    IntArray maxXIA = (IntArray) sgtMapResultsTable.getColumn(1);
                    IntArray minYIA = (IntArray) sgtMapResultsTable.getColumn(2);
                    IntArray maxYIA = (IntArray) sgtMapResultsTable.getColumn(3);
                    IntArray rowNumberIA = (IntArray) sgtMapResultsTable.getColumn(4);
                    IntArray sourceIA = (IntArray) sgtMapResultsTable.getColumn(5);

                    //combine if duplicate min/max/X/Y
                    //first match found is used -- that is hard to take advantage of that here
                    //note that only markers for current pointScreen are put in <map>
                    //  If it were all pointScreens, it would be unclear which pointScreen to change.
                    //  Or, if change all, then no way to change for just one PointScreen. 
                    //  (And there are other complications about components for other PointScreens
                    //   not being on the html form, so how change.)
                    int tn = minXIA.size();
                    for (int i = 0; i < tn; i++) {
                        //# Pixel 0,0 at upper left
                        //# IE 5.2.3 for Mac OS X insists minX<maxX and minY<maxY
                        int sourceEditOption = sourceIA.array[i];
                        if (sourceEditOption != show) {
                            //not interested if sourceEditOption not visible screen 
                            continue;
                        }
                        if (sourceEditOption == pointVectorScreen.editOption()) {
                            if (pointVectorScreen.plotData) {
                                //String2.log("show=" + show + " i=" + i + " minXIA=" + minXIA.array[i] + " rowNumberIA=" + rowNumberIA.array[i]);
                                suMap.append("  <area shape=\"rect\" coords=\"" + minXIA.array[i] + ","
                                        + minYIA.array[i] + "," + maxXIA.array[i] + "," + maxYIA.array[i]
                                        + "\"\n" + "    title=\"Click to plot the time series for "
                                        + (pointVectorScreen.timeSeriesOptions[rowNumberIA.array[i] + 1]) + //+1 since option 0 is ""
                                        "\"\n" + "    alt=\"Click to plot the time series for "
                                        + (pointVectorScreen.timeSeriesOptions[rowNumberIA.array[i] + 1]) + //+1 since option 0 is ""
                                        "\"\n" + "    href=\"#\" " + // was href=\"javascript:
                                        "onClick=\"" + "document." + emaClass.getFormName()
                                        + ".pointVectorTimeSeries.selectedIndex=" + (rowNumberIA.array[i] + 1) + //+1 since option 0 is ""
                                        ";  document." + emaClass.getFormName() + ".submit();\">\n");
                            }
                        } else {
                            for (int ps = 0; ps < nPointScreens; ps++) {
                                if (sourceEditOption == pointScreen(ps).editOption()
                                        && pointScreen(ps).plotData) {
                                    suMap.append("  <area shape=\"rect\" coords=\"" + minXIA.array[i] + ","
                                            + minYIA.array[i] + "," + maxXIA.array[i] + "," + maxYIA.array[i]
                                            + "\"\n" + "    title=\"Click to plot the time series for "
                                            + (pointScreen(ps).timeSeriesOptions[rowNumberIA.array[i] + 1]) + //+1 since option 0 is ""
                                            "\"\n" + "    alt=\"Click to plot the time series for "
                                            + (pointScreen(ps).timeSeriesOptions[rowNumberIA.array[i] + 1]) + //+1 since option 0 is ""
                                            "\"\n" + "    href=\"#\" " + // was href=\"javascript:
                                            "onClick=\"" + "document." + emaClass.getFormName()
                                            + ".pointTimeSeries" + (ps + 1) + ".selectedIndex="
                                            + (rowNumberIA.array[i] + 1) + //index is +1 since #0 is ""
                                            ";  document." + emaClass.getFormName() + ".submit();\">\n");
                                    break; //we're done looking through pointScreens
                                }
                            }
                        }
                    }
                }

                htmlSB.append("<img src=\"" + OneOf.PUBLIC_DIRECTORY + imageFileName + "\"\n" +
                //"      title=\"" + oneOf.hereIsAlt() + "\"\n" +
                        "      alt=\"" + oneOf.hereIsAlt() + "\""
                        + (suMap.length() == 0 ? "" : " usemap=\"#stationCoordinates\"") + "\n"
                        + "      width=\"" + imageWidth2 + "\" height=\"" + mapScreen.imageHeight + "\">\n\n");
                if (suMap.length() > 0) {
                    htmlSB.append("<map name=\"stationCoordinates\">\n");
                    htmlSB.append(suMap.toString());
                    htmlSB.append("</map>\n");
                }

            }

        }

        //deal with show < 0
        if (show < 0) {
            //backButtonForm is useful in several situations.
            //The link to go back to CWBrowser.jsp often lead to jumble of previous values. [why?]
            //String oBack = "o back to editing the map.";
            //htmlSB.append("<p>Then, <a href=\"CWBrowser.jsp\" title=\"G" + oBack + "\">g" + oBack + "</a>\n");
            //(The browser's Back button goes to the previous page which is fine.)
            //So use a Back button:
            String backButtonForm = emaClass.getStartOfHTMLForm() + "<tr>\n" + "  <td>" + back.getLabel() + "\n"
                    + back.getControl(back.getValue(session)) + "\n" + "  </td>\n" + "  <td>&nbsp;</td>\n" + //to take up horizontal space
                    "</tr>\n" + emaClass.getEndOfHTMLForm(startTime, mapScreen.hiddenInputStillPending) + "\n";

            //deal with 'get' requests
            boolean submitterHandled = true;
            if (submitter.equals(mapScreen.getPdf.getName())) {
                //getPDF
                String pdfFileName = File2.getNameNoExtension(imageFileName) + ".pdf";
                if (File2.touch(oneOf.fullPublicDirectory() + pdfFileName)) {
                    if (oneOf.verbose())
                        String2.log("reuse pdf file: " + pdfFileName);
                } else {
                    //POLICY: because this procedure may be used in more than one thread,
                    //do work on unique temp files names using randomInt, then rename to proper file name.
                    //If procedure fails half way through, there won't be a half-finished file.
                    int randomInt = Math2.random(Integer.MAX_VALUE);

                    int pdfWidth1 = graphGDLs.size() > 0 ? oneOf.pdfLandscapeWidths()[mapScreen.imageSizeIndex]
                            : oneOf.pdfPortraitWidths()[mapScreen.imageSizeIndex];
                    int pdfHeight = graphGDLs.size() > 0 ? oneOf.pdfLandscapeHeights()[mapScreen.imageSizeIndex]
                            : oneOf.pdfPortraitHeights()[mapScreen.imageSizeIndex];
                    int pdfWidth2 = pdfWidth1;
                    int pdfGap = imageGap * 2;
                    if (graphGDLs.size() > 0)
                        pdfWidth2 = pdfWidth2 * 2 + pdfGap;
                    double fontScale = SgtMap.PDF_FONTSCALE;
                    //was 1 + mapScreen.imageSizeIndex/(graphGDLs.size() > 0? 4.0 : 2.0); 

                    //??? The pdf's created here have odd colors,
                    //but the pdf's created in SgtMap.test are fine.
                    //What's the difference???
                    Object oar[] = SgtUtil.createPdf(
                            graphGDLs.size() > 0 ? PageSize.LETTER.rotate() : PageSize.LETTER, pdfWidth2,
                            pdfHeight, oneOf.fullPublicDirectory() + randomInt + ".pdf");
                    Graphics2D g2d = (Graphics2D) oar[0];

                    //makeMap
                    makeMap(oneOf.highResLogoImageFile(), //note highRes      GMT: noaa-420.ras
                            g2d, 0, 0, pdfWidth1, pdfHeight, fontScale, mapGDLs);

                    //make graphs
                    if (graphGDLs.size() > 0)
                        makeGraphs(oneOf.highResLogoImageFile(), g2d, pdfWidth1 + pdfGap, 0, pdfWidth1,
                                pdfHeight, fontScale, graphGDLs);

                    //warning
                    if (warning != null)
                        AttributedString2.drawHtmlText(g2d, warning, pdfWidth2 / 2, fontScale * 10, //x,y
                                oneOf.fontFamily(), fontScale * 10, Color.red, 1);

                    //finish the pdf
                    SgtUtil.closePdf(oar);
                    File2.rename(oneOf.fullPublicDirectory(), randomInt + ".pdf", pdfFileName);

                }

                //tell the user it is available
                htmlSB.append(
                        "<p>Click on this link to view the .pdf file, or right click to download the file:\n"
                                + "<a href=\"" + OneOf.PUBLIC_DIRECTORY + pdfFileName + "\"\n"
                                + "      title=\"" + pdfFileName + "\">" + pdfFileName + "</a>\n" + "\n"
                                + "<p>.pdf files can be viewed and printed with\n"
                                + "<a href=\"https://get.adobe.com/reader/\">Acrobat Reader</a>,\n"
                                + "a free program from Adobe.\n");

                //The link to go back to CWBrowser.jsp often lead to jumble of previous values. [why?]
                //String oBack = "o back to editing the map.";
                //htmlSB.append("<p>Then, <a href=\"CWBrowser.jsp\" title=\"G" + oBack + "\">g" + oBack + "</a>\n");
                //(The browser's Back button goes to the previous page which is fine.)
                //So use a Back button:
                htmlSB.append(backButtonForm);

            } else if (gridScreen.submitterIsAGetButton(submitter)) {
                gridScreen.respondToSubmitter(submitter, htmlSB, backButtonForm);
            } else if (contourScreen.submitterIsAGetButton(submitter)) {
                contourScreen.respondToSubmitter(submitter, htmlSB, backButtonForm);
            } else if (vectorScreen.submitterIsAGetButton(submitter)) {
                vectorScreen.respondToSubmitter(submitter, htmlSB, backButtonForm);
            } else if (pointVectorScreen.submitterIsAGetButton(submitter)) {
                pointVectorScreen.respondToSubmitter(submitter, htmlSB, backButtonForm);
            } else
                submitterHandled = false;

            if (!submitterHandled)
                throw new Exception("Unexpected \"submitter\": " + submitter);
        } //end of show < 0

    } catch (Exception e) {
        succeeded = false;

        //display the error message to the user and print to log 
        String tError = MustBe.throwableToString(e);

        htmlSB.setLength(0);
        htmlSB.append(oneOf.errorMessage1() + "\n" + e.toString() + "\n" + oneOf.errorMessage2() + "\n"
                + emaClass.getStartOfHTMLForm() + "<tr>\n" + "  <td>" +
                //The link to go back to CWBrowser.jsp often lead to jumble of previous values. [why?]
                //String GoBack = "Go back to editing the map.";
                //"<a href=\"CWBrowser.jsp\" title=\"" + GoBack + "\">" + GoBack + "</a>" +
                //(The browser's Back button goes to the previous page which is fine.)
                //So use a Back button:
                back.getLabel() + "\n" + back.getControl(back.getValue(session)) + "\n" + "<br>("
                + resetAll.getLabel() + "\n" + resetAll.getControl(resetAll.getValue(session))
                + "&nbsp;)</td>\n" + "  <td>&nbsp;</td>\n" + //to take up horizontal space
                "</tr>\n" + emaClass.getEndOfHTMLForm(startTime, mapScreen.hiddenInputStillPending) + "\n"
                + "<p>&nbsp;<hr>\n" + "<pre>Details:\n" + "\n" + tError + "</pre>\n");

        //send email
        oneOf.email(oneOf.emailEverythingTo(), String2.ERROR + " in " + oneOf.shortClassName(),
                htmlSB.toString());

    } //end of 'catch'

    if (oneOf.verbose())
        String2.log("************ getHTMLForm done. TOTAL TIME=" + (System.currentTimeMillis() - startTime));

    return succeeded;

}

From source file:gov.utah.dts.det.ccl.documents.templating.templates.AbstractCaseloadTemplate.java

@Override
public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor descriptor)
        throws TemplateException {
    Long specialistId = (Long) context.get("specId");
    if (specialistId == null) {
        throw new TemplateException("Specialist id is required.");
    }/*from ww w  .j  a v a2s  . co m*/

    CaseloadSortBy sortBy = CaseloadSortBy.getDefaultSortBy();
    String sortByStr = (String) context.get("sortBy");
    if (sortByStr != null) {
        sortBy = CaseloadSortBy.valueOf(sortByStr);
    }

    Person specialist = personService.getPerson(specialistId);
    context.put(SPECIALIST_KEY, specialist);

    List<FacilityCaseloadView> caseload = getCaseload(specialistId, sortBy);

    setFileName(context, descriptor);

    try {
        Document document = new Document(PageSize.LETTER.rotate(), MARGIN, MARGIN, MARGIN, MARGIN);
        PdfWriter.getInstance(document, outputStream);

        document.open();

        document.add(new Paragraph(getReportTitle() + " for " + specialist.getFirstAndLastName(), FONT));
        //columns: name, facility id, address, phone, 1st director(s), status, type, capacity (<2)

        PdfPTable table = new PdfPTable(8);
        table.setWidths(new float[] { 23f, 25f, 11f, 13f, 5f, 9f, 7f, 7f });
        table.setWidthPercentage(100);
        table.setSpacingBefore(FONT_SIZE);

        table.getDefaultCell().setPadding(TABLE_CELL_PADDING);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setBorderWidthBottom(.5f);
        table.setHeaderRows(1);

        table.addCell(new Phrase("Facility Name", HEADER_FONT));
        table.addCell(new Phrase("Address", HEADER_FONT));
        table.addCell(new Phrase("Phone", HEADER_FONT));
        table.addCell(new Phrase("1st Director(s)", HEADER_FONT));
        table.addCell(new Phrase("Type", HEADER_FONT));
        table.addCell(new Phrase("Exp Dt", HEADER_FONT));
        table.addCell(new Phrase("Adult Cap", HEADER_FONT));
        table.addCell(new Phrase("Youth Cap", HEADER_FONT));

        boolean hasInProcess = false;

        for (FacilityCaseloadView fcv : caseload) {
            if (fcv.getStatus() == FacilityStatus.REGULATED || fcv.getStatus() == FacilityStatus.IN_PROCESS) {
                StringBuilder name = new StringBuilder();
                if (fcv.getStatus() == FacilityStatus.IN_PROCESS) {
                    hasInProcess = true;
                    name.append("* ");
                }
                name.append(fcv.getName());

                table.addCell(new Phrase(name.toString(), FONT));
                table.addCell(new Phrase(fcv.getLocationAddress().toString(), FONT));
                table.addCell(new Phrase(fcv.getPrimaryPhone().getFormattedPhoneNumber(), FONT));
                table.addCell(new Phrase(fcv.getDirectorNames(), FONT));

                String typeAbbrev = null;
                /*
                               if (fcv.getLicenseType() != null) {
                                  typeAbbrev = applicationService.getApplicationPropertyValue("facility.license.type." + fcv.getLicenseType().getId()+ ".abbrev");
                               }
                */
                table.addCell(new Phrase(typeAbbrev != null ? typeAbbrev : "", FONT));
                //               table.addCell(new Phrase(fcv.getExpirationDate() != null ? DATE_FORMATTER.format(fcv.getExpirationDate()) : "", FONT));
                table.addCell(new Phrase("", FONT));

                //               if (fcv.getAdultTotalSlots() == null) {
                table.addCell(new Phrase(""));
                //               } else {
                //                  table.addCell(new Phrase(fcv.getAdultTotalSlots().toString(), FONT));
                //               }
                //               if (fcv.getYouthTotalSlots() == null) {
                table.addCell(new Phrase(""));
                //               } else {
                //                  table.addCell(new Phrase(fcv.getYouthTotalSlots().toString(), FONT));
                //               }
            }
        }

        document.add(table);
        if (hasInProcess) {
            document.add(new Paragraph(
                    "* - Facility is in the process of becoming a regulated child care facility.", FONT));
        }

        document.close();
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
}

From source file:include.nseer_cookie.printPDF.java

License:Open Source License

public Document print_type_across(String print_type, int print_left, int print_right, int print_top,
        int print_bottom) {

    try {/*www .  j  a v  a 2  s. com*/

        if (print_type.equals("A0"))
            document = new Document(PageSize.A0.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A1"))
            document = new Document(PageSize.A1.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A2"))
            document = new Document(PageSize.A2.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A3"))
            document = new Document(PageSize.A3.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A4"))
            document = new Document(PageSize.A4.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A5"))
            document = new Document(PageSize.A5.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A6"))
            document = new Document(PageSize.A6.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A7"))
            document = new Document(PageSize.A7.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A8"))
            document = new Document(PageSize.A8.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A9"))
            document = new Document(PageSize.A9.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B0"))
            document = new Document(PageSize.B0.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B1"))
            document = new Document(PageSize.B1.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B2"))
            document = new Document(PageSize.B2.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B3"))
            document = new Document(PageSize.B3.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B4"))
            document = new Document(PageSize.B4.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B5"))
            document = new Document(PageSize.B5.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_A"))
            document = new Document(PageSize.ARCH_A.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_B"))
            document = new Document(PageSize.ARCH_B.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_C"))
            document = new Document(PageSize.ARCH_C.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_D"))
            document = new Document(PageSize.ARCH_D.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_E"))
            document = new Document(PageSize.ARCH_E.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("FLSA"))
            document = new Document(PageSize.FLSA.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("FLSE"))
            document = new Document(PageSize.FLSE.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("NOTE"))
            document = new Document(PageSize.NOTE.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("_11X17"))
            document = new Document(PageSize._11X17.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("LETTER"))
            document = new Document(PageSize.LETTER.rotate(), print_left, print_right, print_top, print_bottom);
        if (print_type.equals("HALFLETTER"))
            document = new Document(PageSize.HALFLETTER.rotate(), print_left, print_right, print_top,
                    print_bottom);
        if (print_type.equals("LEDGER"))
            document = new Document(PageSize.LEDGER.rotate(), print_left, print_right, print_top, print_bottom);

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

From source file:include.nseer_cookie.printPDF.java

License:Open Source License

public Document print_type_vertical(String print_type, int print_left, int print_right, int print_top,
        int print_bottom) {

    try {/*from  www.j a  va 2 s  .co m*/
        if (print_type.equals("A0"))
            document = new Document(PageSize.A0, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A1"))
            document = new Document(PageSize.A1, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A2"))
            document = new Document(PageSize.A2, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A3"))
            document = new Document(PageSize.A3, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A4"))
            document = new Document(PageSize.A4, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A5"))
            document = new Document(PageSize.A5, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A6"))
            document = new Document(PageSize.A6, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A7"))
            document = new Document(PageSize.A7, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A8"))
            document = new Document(PageSize.A8, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("A9"))
            document = new Document(PageSize.A9, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B0"))
            document = new Document(PageSize.B0, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B1"))
            document = new Document(PageSize.B1, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B2"))
            document = new Document(PageSize.B2, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B3"))
            document = new Document(PageSize.B3, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B4"))
            document = new Document(PageSize.B4, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("B5"))
            document = new Document(PageSize.B5, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_A"))
            document = new Document(PageSize.ARCH_A, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_B"))
            document = new Document(PageSize.ARCH_B, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_C"))
            document = new Document(PageSize.ARCH_C, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_D"))
            document = new Document(PageSize.ARCH_D, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("ARCH_E"))
            document = new Document(PageSize.ARCH_E, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("FLSA"))
            document = new Document(PageSize.FLSA, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("FLSE"))
            document = new Document(PageSize.FLSE, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("NOTE"))
            document = new Document(PageSize.NOTE, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("_11X17"))
            document = new Document(PageSize._11X17, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("LETTER"))
            document = new Document(PageSize.LETTER, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("HALFLETTER"))
            document = new Document(PageSize.HALFLETTER, print_left, print_right, print_top, print_bottom);
        if (print_type.equals("LEDGER"))
            document = new Document(PageSize.LEDGER, print_left, print_right, print_top, print_bottom);

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

From source file:it.eng.spagobi.engines.exporters.ChartExporter.java

License:Mozilla Public License

/** check if the image has to be turned or resize
 * /*from   w  ww  . jav a  2s  .com*/
 * @param document
 * @param jpg
 * @return if the image has been turned
 */

public void changeLayout(Document pdfDocument, Image jpg, float width, float height) {
    logger.debug("IN");
    // if width is more than 600 and height is not more it suffices to turn the image of the chart
    if (width > MAX_WIDTH && !(height > MAX_WIDTH) && !(width > MAX_HEIGHT)) {
        pdfDocument.setPageSize(PageSize.LETTER.rotate());
        logger.debug("pdf rotation");
    } else {
        // otherwise the chart needs to be scaled (if width > height also turn!)
        // SCALED WITH turning
        if (width > height) {
            pdfDocument.setPageSize(PageSize.LETTER.rotate());
            // calculate wich size is to reduce most:
            float percentageToReduceHeight = 0;
            float percentageToReduceWidth = 0;
            if (height > MAX_WIDTH) {
                percentageToReduceHeight = (height * 100) / MAX_WIDTH;
            }
            if (width > MAX_HEIGHT) {
                percentageToReduceWidth = (width * 100) / MAX_HEIGHT;
            }
            float percToReduce = percentageToReduceHeight > percentageToReduceWidth ? percentageToReduceHeight
                    : percentageToReduceWidth;
            float percToScale = percToReduce - 100;
            //                  float newHeight = height - ((height/100)*percToReduce);
            //            float newWidth = width - ((width/100)*percToReduce);
            logger.debug("pdf scale of percentage " + percToScale);
            jpg.scalePercent(percToScale);

            logger.debug("pdf rotation and scaling");
        } else {
            // SCALED WITHOUT turning
            // calculate wich size is to reduce most:
            float percentageToReduceHeight = 0;
            float percentageToReduceWidth = 0;
            if (height > MAX_HEIGHT) {
                percentageToReduceHeight = (height * 100) / MAX_HEIGHT;
            }
            if (width > MAX_WIDTH) {
                percentageToReduceWidth = (width * 100) / MAX_WIDTH;
            }
            float percToReduce = percentageToReduceHeight > percentageToReduceWidth ? percentageToReduceHeight
                    : percentageToReduceWidth;
            float percToScale = percToReduce - 100;
            //                  float newHeight = height - ((height/100)*percToReduce);
            //            float newWidth = width - ((width/100)*percToReduce);
            logger.debug("pdf scale of percentage " + percToScale);
            jpg.scalePercent(percToScale);
            logger.debug("pdf scaling");
        }
    }
    logger.debug("OUT");
}

From source file:javaaxp.xps2pdf.service.impl.PDFConverterImpl.java

License:Open Source License

@Override
public void covertToPDF(OutputStream ouput) throws XPSError {
    try {/*from  www.  j ava2  s.  c  o  m*/
        int firstPage = fPageController.getXPSAccess().getPageAccess(0).getFirstPageNum();
        int lastPage = fPageController.getXPSAccess().getPageAccess(0).getLastPageNum();

        Document document = new Document();
        document.setPageCount(lastPage - firstPage + 1);
        document.setPageSize(PageSize.LETTER);
        PdfWriter writer = PdfWriter.getInstance(document, ouput);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        for (int i = firstPage; i < 1; i++) {
            System.out.println("Converting page " + i);
            fPageController.setPage(i);
            PdfTemplate tp = cb.createTemplate((float) fPageController.getPage().getWidth(),
                    (float) fPageController.getPage().getHeight());
            Graphics g = tp.createGraphics((float) fPageController.getPage().getWidth(),
                    (float) fPageController.getPage().getHeight());
            JComponent toReturn = fPageViewer.getPageRenderer().getRendererComponent();
            toReturn.paint(g);
            cb.addTemplate(tp, 0, 0);
            document.newPage();
        }
        document.close();
    } catch (DocumentException e) {
        //rethrow
    }
}

From source file:mx.dr.util.report.impl.PdfService.java

License:Open Source License

/**
 * @see mx.dr.util.report.IPdfService#doMultiReport(List, OutputStream)
*//* w w  w.  j  av  a 2 s. c o m*/
public void doMultiReport(List<Object> lista, OutputStream out) throws Exception {
    DRPdfDocument anonDoc = null;
    for (Object o : lista) {
        anonDoc = o.getClass().getAnnotation(DRPdfDocument.class);
        break;
    }
    Document doc = null;
    if (anonDoc != null) {
        doc = new Document(new Rectangle(anonDoc.height(), anonDoc.width()), 0, 0, 0, 0);
    } else {
        doc = new Document(PageSize.LETTER, 0, 0, 0, 0);
    }
    PdfWriter.getInstance(doc, out);
    doc.open();
    Object dto;
    for (int i = 0; i < lista.size(); i++) {
        dto = lista.get(i);
        if (i > 0) {
            doc.newPage();
        }
        estampaEtiqueta(doc, dto, null, null);
    }

    doc.close();
}

From source file:mx.dr.util.report.impl.PdfService.java

License:Open Source License

/**
 * @see mx.dr.util.report.IPdfService#doReport(Object, OutputStream)
 *//*from www  .  ja  v  a  2 s .  c  o m*/
public void doReport(Object dto, OutputStream out) throws Exception {
    DRPdfDocument anonDoc = null;

    anonDoc = dto.getClass().getAnnotation(DRPdfDocument.class);
    Document doc = null;
    if (anonDoc != null) {
        doc = new Document(new Rectangle(anonDoc.height(), anonDoc.width()), 0, 0, 0, 0);
    } else {
        doc = new Document(PageSize.LETTER, 0, 0, 0, 0);
    }

    PdfWriter.getInstance(doc, out);
    doc.open();
    estampaEtiqueta(doc, dto, null, null);
    doc.close();
}

From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java

License:Apache License

private Rectangle getPageSize(boolean landscape) {
    Rectangle pageSize;/*  ww w .  j av  a 2 s .  c o m*/
    if (Locale.US.getCountry().equals(I18N.getCurrentLocale().getCountry())) {
        // Letter size paper is used in the US instead of the ISO standard A4
        pageSize = PageSize.LETTER;
    } else {
        pageSize = PageSize.A4;
    }
    if (landscape) {
        pageSize = pageSize.rotate();
    }
    return pageSize;
}

From source file:net.mitnet.tools.pdf.book.conf.ConfigHelper.java

License:Open Source License

public static Rectangle parsePageSize(CommandLineHelper commandLineHelper) {

    Rectangle pageSize = PdfPageSizeHelper.getDefaultPageSizeByLocale();
    if (commandLineHelper.hasOption(CliOptions.OPTION_PAGE_SIZE)) {
        String pageSizeValue = commandLineHelper.getOptionValue(CliOptions.OPTION_PAGE_SIZE);
        System.out.println("Page Size Option Detected: " + pageSizeValue);
        if (!StringUtils.isEmpty(pageSizeValue)) {
            if (PdfPageValues.PAGE_SIZE_US_LETTER_STRING.equalsIgnoreCase(pageSizeValue)) {
                System.out.println("Setting Page Size to Letter");
                pageSize = PageSize.LETTER;
            }//w w  w  .j a  va 2s  .c  o m
        }
    }
    return pageSize;
}