Example usage for com.lowagie.text.pdf PdfDestination PdfDestination

List of usage examples for com.lowagie.text.pdf PdfDestination PdfDestination

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfDestination PdfDestination.

Prototype


public PdfDestination(int type, float parameter) 

Source Link

Document

Constructs a new PdfDestination.

Usage

From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java

License:Open Source License

public void initializePage(PdfContentByte currentPage, float height) {
    _currentPage = currentPage;//www.  j  a  va  2  s.  com
    _pageHeight = height;

    _currentPage.saveState();

    _transform = new AffineTransform();
    _transform.scale(1.0d / _dotsPerPoint, 1.0d / _dotsPerPoint);

    _stroke = transformStroke(STROKE_ONE);
    _originalStroke = _stroke;
    _oldStroke = _stroke;

    setStrokeDiff(_stroke, null);

    if (_defaultDestination == null) {
        _defaultDestination = new PdfDestination(PdfDestination.FITH, height);
        _defaultDestination.addPage(_writer.getPageReference(1));
    }

    _linkTargetAreas = new HashSet();
}

From source file:questions.stamppages.BookmarksToTOC1.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*w  w w.  j ava2 s .c  om*/
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        writer.setPageEvent(new ParagraphBookmarkEvents(false));
        document.open();
        BufferedReader reader = new BufferedReader(new FileReader(RESOURCE));
        String line;
        Paragraph p;
        while ((line = reader.readLine()) != null) {
            p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
            document.add(Chunk.NEWLINE);
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    try {
        PdfReader reader = new PdfReader(baos.toByteArray());
        Rectangle rect = reader.getPageSizeWithRotation(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        stamper.insertPage(1, rect);
        ColumnText column = new ColumnText(stamper.getOverContent(1));
        column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        column.addElement(new Paragraph("TABLE OF CONTENTS"));
        List<Map> list = SimpleBookmark.getBookmark(reader);
        Chunk link;
        PdfAction action;
        String info;
        int p = 1;
        float y = 10;
        for (Map<String, String> bookmark : list) {
            link = new Chunk(bookmark.get("Title"));
            info = bookmark.get("Page");
            p = Integer.parseInt(info.substring(0, info.indexOf(' ')));
            y = Float.parseFloat(info.substring(info.lastIndexOf(' ') + 1) + "f");
            action = PdfAction.gotoLocalPage(p, new PdfDestination(PdfDestination.FITH, y),
                    stamper.getWriter());
            link.setAction(action);
            column.addElement(new Paragraph(link));
        }
        column.go();
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:questions.stamppages.ParagraphBookmarkEvents.java

/**
 * Adds an outline for every new Paragraph
 * /*from www  .  j av a  2  s . co  m*/
 * @param writer
 * @param document
 * @param position
 */
public void onParagraph(PdfWriter writer, Document document, float position) {
    n++;
    PdfContentByte cb = writer.getDirectContent();
    PdfOutline root = cb.getRootOutline();
    PdfDestination destination = new PdfDestination(PdfDestination.FITH, position);
    if (named) {
        cb.localDestination("p" + n, destination);
        new PdfOutline(root, PdfAction.gotoLocalPage("p" + n, false), "paragraph " + n);
    } else {
        new PdfOutline(root, destination, "paragraph " + n);
    }
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>fireNewSection</code></h2>
 * //from   ww w .  j a va  2  s.  c  o m
 * <p>
 *  Executed by <code>ReportAccumulator</code> when a new section is 
 *  detected      
 * </p>
 * 
 * @param   ReportAccumulator ac - Source creating the new section. 
 * @param   String newValue - the value of the new section.
 * 
 */
public void fireNewSection(ReportAccumulator ac, String newValue) {
    PdfOutline outLine = new PdfOutline(ac.getParentAccumulator().getOutline(),
            new PdfDestination(PdfDestination.FITH, 50), newValue);
    outLine.setOpen(false);
    ac.setOutline(outLine);
}