Java Code Examples for com.lowagie.text.pdf.PdfAction#gotoLocalPage()

The following examples show how to use com.lowagie.text.pdf.PdfAction#gotoLocalPage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a document with some goto actions.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	Document remote = new Document();

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Actions.pdf"));
	PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
	// step 3:
	document.open();
	remote.open();
	// step 4: we add some content
	PdfAction action = PdfAction.gotoLocalPage(2, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), writer);
	writer.setOpenAction(action);
	document.add(new Paragraph("Page 1"));
	document.newPage();
	document.add(new Paragraph("Page 2"));
	document.add(new Chunk("goto page 1").setAction(PdfAction.gotoLocalPage(1, new PdfDestination(
			PdfDestination.FITH, 500), writer)));
	document.add(Chunk.NEWLINE);
	document.add(new Chunk("goto another document").setAction(PdfAction.gotoRemotePage("remote.pdf", "test", false,
			true)));
	remote.add(new Paragraph("Some remote document"));
	remote.newPage();
	Paragraph p = new Paragraph("This paragraph contains a ");
	p.add(new Chunk("local destination").setLocalDestination("test"));
	remote.add(p);

	// step 5: we close the document
	document.close();
	remote.close();
}
 
Example 2
Source File: PDFPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a PdfAction.
 *
 * @param hyperlink
 *            the hyperlink.
 * @param bookmark
 *            the bookmark.
 * @param target
 *            if target equals "_blank", the target will be opened in a new
 *            window, else the target will be opened in the current window.
 * @return the created PdfAction.
 */
private PdfAction createPdfAction( String hyperlink, String bookmark,
		String target, int type )
{
	// patch from Ales Novy
	if ( "_top".equalsIgnoreCase( target )
			|| "_parent".equalsIgnoreCase( target )
			|| "_blank".equalsIgnoreCase( target )
			|| "_self".equalsIgnoreCase( target ) )
	// Opens the target in a new window.
	{
		if ( hyperlink == null )
			hyperlink = "";
		boolean isUrl = hyperlink.startsWith( "http" );
		if ( !isUrl )
		{
			Matcher matcher = PAGE_LINK_PATTERN.matcher( hyperlink );
			if ( matcher.find( ) )
			{
				String fileName = matcher.group( 1 );
				String pageNumber = matcher.group( matcher.groupCount( ) );
				return new PdfAction( fileName,
						Integer.valueOf( pageNumber ) );
			}
		}
		return new PdfAction( hyperlink );
	}
	else

	// Opens the target in the current window.
	{
		if ( type == IHyperlinkAction.ACTION_BOOKMARK )
		{
			return PdfAction.gotoLocalPage( bookmark, false );
		}
		else
		{
			return PdfAction.gotoRemotePage( hyperlink, bookmark, false,
					false );
		}
	}
}