You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by gb...@apache.org on 2011/12/06 21:19:31 UTC
svn commit: r1211082 [2/3] - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples: ./ fdf/
pdmodel/ persistence/ signature/ util/
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java Tue Dec 6 20:19:29 2011
@@ -1,120 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.io.IOException;
-
-import org.apache.pdfbox.exceptions.COSVisitorException;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
-import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
-
-/**
- * This is an example that creates a simple document
- * with a ttf-font.
- *
- * @author <a href="mailto:m.g.n@gmx.de">Michael Niedermair</a>
- * @version $Revision: 1.2 $
- */
-public class HelloWorldTTF
-{
-
- /**
- * create the second sample document from the PDF file format specification.
- *
- * @param file The file to write the PDF to.
- * @param message The message to write in the file.
- * @param fontfile The ttf-font file.
- *
- * @throws IOException If there is an error writing the data.
- * @throws COSVisitorException If there is an error writing the PDF.
- */
- public void doIt(final String file, final String message,
- final String fontfile) throws IOException, COSVisitorException
- {
-
- // the document
- PDDocument doc = null;
- try
- {
- doc = new PDDocument();
-
- PDPage page = new PDPage();
- doc.addPage(page);
- PDFont font = PDTrueTypeFont.loadTTF(doc, fontfile);
-
- PDPageContentStream contentStream = new PDPageContentStream(doc,
- page);
- contentStream.beginText();
- contentStream.setFont(font, 12);
- contentStream.moveTextPositionByAmount(100, 700);
- contentStream.drawString(message);
- contentStream.endText();
- contentStream.close();
- doc.save(file);
- System.out.println(file + " created!");
- }
- finally
- {
- if (doc != null)
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will create a hello world PDF document
- * with a ttf-font.
- * <br />
- * see usage() for commandline
- *
- * @param args Command line arguments.
- */
- public static void main(String[] args)
- {
-
- HelloWorldTTF app = new HelloWorldTTF();
- try
- {
- if (args.length != 3)
- {
- app.usage();
- }
- else
- {
- app.doIt(args[0], args[1], args[2]);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private void usage()
- {
- System.err.println("usage: " + this.getClass().getName()
- + " <output-file> <Message> <ttf-file>");
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java Tue Dec 6 20:19:29 2011
@@ -1,120 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.io.IOException;
-
-import org.apache.pdfbox.exceptions.COSVisitorException;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
-import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDType1AfmPfbFont;
-
-/**
- * This is an example that creates a simple document
- * with a Type 1 font (afm + pfb).
- *
- * @author <a href="mailto:m.g.n@gmx.de">Michael Niedermair</a>
- * @version $Revision: 1.2 $
- */
-public class HelloWorldType1AfmPfb
-{
-
- /**
- * create the second sample document from the PDF file format specification.
- *
- * @param file The file to write the PDF to.
- * @param message The message to write in the file.
- * @param fontfile The ttf-font file.
- *
- * @throws IOException If there is an error writing the data.
- * @throws COSVisitorException If there is an error writing the PDF.
- */
- public void doIt(final String file, final String message,
- final String fontfile) throws IOException, COSVisitorException
- {
-
- // the document
- PDDocument doc = null;
- try
- {
- doc = new PDDocument();
-
- PDPage page = new PDPage();
- doc.addPage(page);
- PDFont font = new PDType1AfmPfbFont(doc,fontfile);
-
- PDPageContentStream contentStream = new PDPageContentStream(doc,
- page);
- contentStream.beginText();
- contentStream.setFont(font, 12);
- contentStream.moveTextPositionByAmount(100, 700);
- contentStream.drawString(message);
- contentStream.endText();
- contentStream.close();
- doc.save(file);
- System.out.println(file + " created!");
- }
- finally
- {
- if (doc != null)
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will create a hello world PDF document
- * with a ttf-font.
- * <br />
- * see usage() for commandline
- *
- * @param args Command line arguments.
- */
- public static void main(String[] args)
- {
-
- HelloWorldType1AfmPfb app = new HelloWorldType1AfmPfb();
- try
- {
- if (args.length != 3)
- {
- app.usage();
- }
- else
- {
- app.doIt(args[0], args[1], args[2]);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private void usage()
- {
- System.err.println("usage: " + this.getClass().getName()
- + " <output-file> <Message> <afm-file>");
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java Tue Dec 6 20:19:29 2011
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import org.apache.pdfbox.exceptions.COSVisitorException;
-import org.apache.pdfbox.io.RandomAccessFile;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-
-import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
-
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDCcitt;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
-
-
-/**
- * This is an example that creates a simple document.
- *
- * The example is taken from the pdf file format specification.
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.7 $
- */
-public class ImageToPDF
-{
-
- /**
- * create the second sample document from the PDF file format specification.
- *
- * @param file The file to write the PDF to.
- * @param image The filename of the image to put in the PDF.
- *
- * @throws IOException If there is an error writing the data.
- * @throws COSVisitorException If there is an error writing the PDF.
- */
- public void createPDFFromImage( String file, String image) throws IOException, COSVisitorException
- {
- // the document
- PDDocument doc = null;
- try
- {
- doc = new PDDocument();
-
- PDPage page = new PDPage();
- doc.addPage( page );
-
- PDXObjectImage ximage = null;
- if( image.toLowerCase().endsWith( ".jpg" ) )
- {
- ximage = new PDJpeg(doc, new FileInputStream( image ) );
- }
- else if (image.toLowerCase().endsWith(".tif") || image.toLowerCase().endsWith(".tiff"))
- {
- ximage = new PDCcitt(doc, new RandomAccessFile(new File(image),"r"));
- }
- else
- {
- //BufferedImage awtImage = ImageIO.read( new File( image ) );
- //ximage = new PDPixelMap(doc, awtImage);
- throw new IOException( "Image type not supported:" + image );
- }
- PDPageContentStream contentStream = new PDPageContentStream(doc, page);
-
- contentStream.drawImage( ximage, 20, 20 );
-
- contentStream.close();
- doc.save( file );
- }
- finally
- {
- if( doc != null )
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will create a PDF document with a single image on it.
- * <br />
- * see usage() for commandline
- *
- * @param args Command line arguments.
- */
- public static void main(String[] args)
- {
- ImageToPDF app = new ImageToPDF();
- try
- {
- if( args.length != 2 )
- {
- app.usage();
- }
- else
- {
- app.createPDFFromImage( args[0], args[1] );
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private void usage()
- {
- System.err.println( "usage: " + this.getClass().getName() + " <output-file> <image>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java Tue Dec 6 20:19:29 2011
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import org.apache.pdfbox.exceptions.InvalidPasswordException;
-
-import org.apache.pdfbox.pdfparser.PDFParser;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
-import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
-import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-
-/**
- * This is an example on how to access the bookmarks that are part of a pdf document.
- *
- * Usage: java org.apache.pdfbox.examples.pdmodel.PrintBookmarks <input-pdf>
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.2 $
- */
-public class PrintBookmarks
-{
- /**
- * This will print the documents data.
- *
- * @param args The command line arguments.
- *
- * @throws Exception If there is an error parsing the document.
- */
- public static void main( String[] args ) throws Exception
- {
- if( args.length != 1 )
- {
- usage();
- }
- else
- {
- PDDocument document = null;
- FileInputStream file = null;
- try
- {
- file = new FileInputStream( args[0] );
- PDFParser parser = new PDFParser( file );
- parser.parse();
- document = parser.getPDDocument();
- if( document.isEncrypted() )
- {
- try
- {
- document.decrypt( "" );
- }
- catch( InvalidPasswordException e )
- {
- System.err.println( "Error: Document is encrypted with a password." );
- System.exit( 1 );
- }
- }
- PrintBookmarks meta = new PrintBookmarks();
- PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline();
- if( outline != null )
- {
- meta.printBookmark( outline, "" );
- }
- else
- {
- System.out.println( "This document does not contain any bookmarks" );
- }
- }
- finally
- {
- if( file != null )
- {
- file.close();
- }
- if( document != null )
- {
- document.close();
- }
- }
- }
- }
-
- /**
- * This will print the usage for this document.
- */
- private static void usage()
- {
- System.err.println( "Usage: java org.apache.pdfbox.examples.pdmodel.PrintBookmarks <input-pdf>" );
- }
-
- /**
- * This will print the documents bookmarks to System.out.
- *
- * @param bookmark The bookmark to print out.
- * @param indentation A pretty printing parameter
- *
- * @throws IOException If there is an error getting the page count.
- */
- public void printBookmark( PDOutlineNode bookmark, String indentation ) throws IOException
- {
- PDOutlineItem current = bookmark.getFirstChild();
- while( current != null )
- {
- System.out.println( indentation + current.getTitle() );
- printBookmark( current, indentation + " " );
- current = current.getNextSibling();
- }
-
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java Tue Dec 6 20:19:29 2011
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import org.apache.pdfbox.exceptions.InvalidPasswordException;
-
-import org.apache.pdfbox.pdfparser.PDFParser;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
-import org.apache.pdfbox.pdmodel.PDDocumentInformation;
-import org.apache.pdfbox.pdmodel.common.PDMetadata;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import java.text.SimpleDateFormat;
-
-import java.util.Calendar;
-
-/**
- * This is an example on how to get a documents metadata information.
- *
- * Usage: java org.apache.pdfbox.examples.pdmodel.PrintDocumentMetaData <input-pdf>
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.11 $
- */
-public class PrintDocumentMetaData
-{
- /**
- * This will print the documents data.
- *
- * @param args The command line arguments.
- *
- * @throws Exception If there is an error parsing the document.
- */
- public static void main( String[] args ) throws Exception
- {
- if( args.length != 1 )
- {
- usage();
- }
- else
- {
- PDDocument document = null;
- FileInputStream file = null;
- try
- {
- file = new FileInputStream( args[0] );
- PDFParser parser = new PDFParser( file );
- parser.parse();
- document = parser.getPDDocument();
- if( document.isEncrypted() )
- {
- try
- {
- document.decrypt( "" );
- }
- catch( InvalidPasswordException e )
- {
- System.err.println( "Error: Document is encrypted with a password." );
- System.exit( 1 );
- }
- }
- PrintDocumentMetaData meta = new PrintDocumentMetaData();
- meta.printMetadata( document );
- }
- finally
- {
- if( file != null )
- {
- file.close();
- }
- if( document != null )
- {
- document.close();
- }
- }
- }
- }
-
- /**
- * This will print the usage for this document.
- */
- private static void usage()
- {
- System.err.println( "Usage: java org.apache.pdfbox.examples.pdmodel.PrintDocumentMetaData <input-pdf>" );
- }
-
- /**
- * This will print the documents data to System.out.
- *
- * @param document The document to get the metadata from.
- *
- * @throws IOException If there is an error getting the page count.
- */
- public void printMetadata( PDDocument document ) throws IOException
- {
- PDDocumentInformation info = document.getDocumentInformation();
- PDDocumentCatalog cat = document.getDocumentCatalog();
- PDMetadata metadata = cat.getMetadata();
- System.out.println( "Page Count=" + document.getNumberOfPages() );
- System.out.println( "Title=" + info.getTitle() );
- System.out.println( "Author=" + info.getAuthor() );
- System.out.println( "Subject=" + info.getSubject() );
- System.out.println( "Keywords=" + info.getKeywords() );
- System.out.println( "Creator=" + info.getCreator() );
- System.out.println( "Producer=" + info.getProducer() );
- System.out.println( "Creation Date=" + formatDate( info.getCreationDate() ) );
- System.out.println( "Modification Date=" + formatDate( info.getModificationDate() ) );
- System.out.println( "Trapped=" + info.getTrapped() );
- if( metadata != null )
- {
- System.out.println( "Metadata=" + metadata.getInputStreamAsString() );
- }
- }
-
- /**
- * This will format a date object.
- *
- * @param date The date to format.
- *
- * @return A string representation of the date.
- */
- private String formatDate( Calendar date )
- {
- String retval = null;
- if( date != null )
- {
- SimpleDateFormat formatter = new SimpleDateFormat();
- retval = formatter.format( date.getTime() );
- }
-
- return retval;
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java Tue Dec 6 20:19:29 2011
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.awt.geom.Rectangle2D;
-import java.util.List;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.pdmodel.interactive.action.type.PDAction;
-import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionURI;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
-import org.apache.pdfbox.util.PDFTextStripperByArea;
-
-
-/**
- * This is an example of how to access a URL in a PDF document.
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.3 $
- */
-public class PrintURLs
-{
- /**
- * Constructor.
- */
- private PrintURLs()
- {
- //utility class
- }
-
- /**
- * This will create a hello world PDF document.
- * <br />
- * see usage() for commandline
- *
- * @param args Command line arguments.
- *
- * @throws Exception If there is an error extracting the URLs.
- */
- public static void main(String[] args) throws Exception
- {
- PDDocument doc = null;
- try
- {
- if( args.length != 1 )
- {
- usage();
- }
- else
- {
- doc = PDDocument.load( args[0] );
- List allPages = doc.getDocumentCatalog().getAllPages();
- for( int i=0; i<allPages.size(); i++ )
- {
- PDFTextStripperByArea stripper = new PDFTextStripperByArea();
- PDPage page = (PDPage)allPages.get( i );
- List annotations = page.getAnnotations();
- //first setup text extraction regions
- for( int j=0; j<annotations.size(); j++ )
- {
- PDAnnotation annot = (PDAnnotation)annotations.get( j );
- if( annot instanceof PDAnnotationLink )
- {
- PDAnnotationLink link = (PDAnnotationLink)annot;
- PDRectangle rect = link.getRectangle();
- //need to reposition link rectangle to match text space
- float x = rect.getLowerLeftX();
- float y = rect.getUpperRightY();
- float width = rect.getWidth();
- float height = rect.getHeight();
- int rotation = page.findRotation();
- if( rotation == 0 )
- {
- PDRectangle pageSize = page.findMediaBox();
- y = pageSize.getHeight() - y;
- }
- else if( rotation == 90 )
- {
- //do nothing
- }
-
- Rectangle2D.Float awtRect = new Rectangle2D.Float( x,y,width,height );
- stripper.addRegion( "" + j, awtRect );
- }
- }
-
- stripper.extractRegions( page );
-
- for( int j=0; j<annotations.size(); j++ )
- {
- PDAnnotation annot = (PDAnnotation)annotations.get( j );
- if( annot instanceof PDAnnotationLink )
- {
- PDAnnotationLink link = (PDAnnotationLink)annot;
- PDAction action = link.getAction();
- String urlText = stripper.getTextForRegion( "" + j );
- if( action instanceof PDActionURI )
- {
- PDActionURI uri = (PDActionURI)action;
- System.out.println( "Page " + (i+1) +":'" + urlText + "'=" + uri.getURI() );
- }
- }
- }
- }
- }
- }
- finally
- {
- if( doc != null )
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private static void usage()
- {
- System.err.println( "usage: " + PrintURLs.class.getName() + " <input-file>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java Tue Dec 6 20:19:29 2011
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-
-import java.io.IOException;
-
-/**
- * This is an example on how to remove pages from a PDF document.
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.5 $
- */
-public class RemoveFirstPage
-{
- private RemoveFirstPage()
- {
- //utility class, should not be instantiated.
- }
-
- /**
- * This will print the documents data.
- *
- * @param args The command line arguments.
- *
- * @throws Exception If there is an error parsing the document.
- */
- public static void main( String[] args ) throws Exception
- {
- if( args.length != 2 )
- {
- usage();
- }
- else
- {
- PDDocument document = null;
- try
- {
- document = PDDocument.load( args[0] );
- if( document.isEncrypted() )
- {
- throw new IOException( "Encrypted documents are not supported for this example" );
- }
- if( document.getNumberOfPages() <= 1 )
- {
- throw new IOException( "Error: A PDF document must have at least one page, " +
- "cannot remove the last page!");
- }
- document.removePage( 0 );
- document.save( args[1] );
- }
- finally
- {
- if( document != null )
- {
- document.close();
- }
- }
- }
- }
-
- /**
- * This will print the usage for this document.
- */
- private static void usage()
- {
- System.err.println( "Usage: java org.apache.pdfbox.examples.pdmodel.RemoveFirstPage <input-pdf> <output-pdf>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceString.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceString.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceString.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceString.java Tue Dec 6 20:19:29 2011
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-
-import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSString;
-import org.apache.pdfbox.exceptions.COSVisitorException;
-
-import org.apache.pdfbox.pdfparser.PDFStreamParser;
-import org.apache.pdfbox.pdfwriter.ContentStreamWriter;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-
-import org.apache.pdfbox.pdmodel.common.PDStream;
-
-import org.apache.pdfbox.util.PDFOperator;
-
-
-/**
- * This is an example that will replace a string in a PDF with a new one.
- *
- * The example is taken from the pdf file format specification.
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.3 $
- */
-public class ReplaceString
-{
- /**
- * Constructor.
- */
- public ReplaceString()
- {
- super();
- }
-
- /**
- * Locate a string in a PDF and replace it with a new string.
- *
- * @param inputFile The PDF to open.
- * @param outputFile The PDF to write to.
- * @param strToFind The string to find in the PDF document.
- * @param message The message to write in the file.
- *
- * @throws IOException If there is an error writing the data.
- * @throws COSVisitorException If there is an error writing the PDF.
- */
- public void doIt( String inputFile, String outputFile, String strToFind, String message)
- throws IOException, COSVisitorException
- {
- // the document
- PDDocument doc = null;
- try
- {
- doc = PDDocument.load( inputFile );
- List pages = doc.getDocumentCatalog().getAllPages();
- for( int i=0; i<pages.size(); i++ )
- {
- PDPage page = (PDPage)pages.get( i );
- PDStream contents = page.getContents();
- PDFStreamParser parser = new PDFStreamParser(contents.getStream() );
- parser.parse();
- List tokens = parser.getTokens();
- for( int j=0; j<tokens.size(); j++ )
- {
- Object next = tokens.get( j );
- if( next instanceof PDFOperator )
- {
- PDFOperator op = (PDFOperator)next;
- //Tj and TJ are the two operators that display
- //strings in a PDF
- if( op.getOperation().equals( "Tj" ) )
- {
- //Tj takes one operator and that is the string
- //to display so lets update that operator
- COSString previous = (COSString)tokens.get( j-1 );
- String string = previous.getString();
- string = string.replaceFirst( strToFind, message );
- previous.reset();
- previous.append( string.getBytes("ISO-8859-1") );
- }
- else if( op.getOperation().equals( "TJ" ) )
- {
- COSArray previous = (COSArray)tokens.get( j-1 );
- for( int k=0; k<previous.size(); k++ )
- {
- Object arrElement = previous.getObject( k );
- if( arrElement instanceof COSString )
- {
- COSString cosString = (COSString)arrElement;
- String string = cosString.getString();
- string = string.replaceFirst( strToFind, message );
- cosString.reset();
- cosString.append( string.getBytes("ISO-8859-1") );
- }
- }
- }
- }
- }
- //now that the tokens are updated we will replace the
- //page content stream.
- PDStream updatedStream = new PDStream(doc);
- OutputStream out = updatedStream.createOutputStream();
- ContentStreamWriter tokenWriter = new ContentStreamWriter(out);
- tokenWriter.writeTokens( tokens );
- page.setContents( updatedStream );
- }
- doc.save( outputFile );
- }
- finally
- {
- if( doc != null )
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will open a PDF and replace a string if it finds it.
- * <br />
- * see usage() for commandline
- *
- * @param args Command line arguments.
- */
- public static void main(String[] args)
- {
- ReplaceString app = new ReplaceString();
- try
- {
- if( args.length != 4 )
- {
- app.usage();
- }
- else
- {
- app.doIt( args[0], args[1], args[2], args[3] );
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private void usage()
- {
- System.err.println( "usage: " + this.getClass().getName() +
- " <input-file> <output-file> <search-string> <Message>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java Tue Dec 6 20:19:29 2011
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.util.List;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-
-import org.apache.pdfbox.pdmodel.interactive.action.type.PDAction;
-import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionURI;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
-
-
-/**
- * This is an example of how to replace a URL in a PDF document. This
- * will only replace the URL that the text refers to and not the text
- * itself.
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.2 $
- */
-public class ReplaceURLs
-{
- /**
- * Constructor.
- */
- private ReplaceURLs()
- {
- //utility class
- }
-
- /**
- * This will read in a document and replace all of the urls with
- * http://www.pdfbox.org.
- * <br />
- * see usage() for commandline
- *
- * @param args Command line arguments.
- *
- * @throws Exception If there is an error during the process.
- */
- public static void main(String[] args) throws Exception
- {
- PDDocument doc = null;
- try
- {
- if( args.length != 2 )
- {
- usage();
- }
- else
- {
- doc = PDDocument.load( args[0] );
- List allPages = doc.getDocumentCatalog().getAllPages();
- for( int i=0; i<allPages.size(); i++ )
- {
- PDPage page = (PDPage)allPages.get( i );
- List annotations = page.getAnnotations();
-
- for( int j=0; j<annotations.size(); j++ )
- {
- PDAnnotation annot = (PDAnnotation)annotations.get( j );
- if( annot instanceof PDAnnotationLink )
- {
- PDAnnotationLink link = (PDAnnotationLink)annot;
- PDAction action = link.getAction();
- if( action instanceof PDActionURI )
- {
- PDActionURI uri = (PDActionURI)action;
- String oldURI = uri.getURI();
- String newURI = "http://www.pdfbox.org";
- System.out.println( "Page " + (i+1) +": Replacing " + oldURI + " with " + newURI );
- uri.setURI( newURI );
- }
- }
- }
- }
- doc.save( args[1] );
- }
- }
- finally
- {
- if( doc != null )
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private static void usage()
- {
- System.err.println( "usage: " + ReplaceURLs.class.getName() + " <input-file> <output-file>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java Tue Dec 6 20:19:29 2011
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This is an example on how to add annotations to pages of a PDF document.
- *
- * @author Paul King
- * @version $Revision: 1.1 $
- */
-public class RubberStamp
-{
- private RubberStamp()
- {
- //utility class, should not be instantiated.
- }
-
- /**
- * This will print the documents data.
- *
- * @param args The command line arguments.
- *
- * @throws Exception If there is an error parsing the document.
- */
- public static void main( String[] args ) throws Exception
- {
- if( args.length != 2 )
- {
- usage();
- }
- else
- {
- PDDocument document = null;
- try
- {
- document = PDDocument.load( args[0] );
- if( document.isEncrypted() )
- {
- throw new IOException( "Encrypted documents are not supported for this example" );
- }
- List allpages = new ArrayList();
- document.getDocumentCatalog().getPages().getAllKids(allpages);
-
- for (int i=0; i < allpages.size(); i++)
- {
- PDPage apage = (PDPage) allpages.get(i);
- List annotations = apage.getAnnotations();
-
- PDAnnotationRubberStamp rs = new PDAnnotationRubberStamp();
- rs.setName(PDAnnotationRubberStamp.NAME_TOP_SECRET);
- rs.setRectangle(new PDRectangle(100,100));
- rs.setContents("A top secret note");
-
- annotations.add(rs);
- }
-
- document.save( args[1] );
- }
- finally
- {
- if( document != null )
- {
- document.close();
- }
- }
- }
- }
-
- /**
- * This will print the usage for this document.
- */
- private static void usage()
- {
- System.err.println( "Usage: java org.apache.pdfbox.examples.pdmodel.RubberStamp <input-pdf> <output-pdf>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java Tue Dec 6 20:19:29 2011
@@ -1,197 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.exceptions.COSVisitorException;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.PDResources;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
-import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
-import org.apache.pdfbox.util.MapUtil;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * This is an example on how to add a rubber stamp with an image to pages of a PDF document.
- *
- * @version $Revision: 1.0 $
- */
-public class RubberStampWithImage
-{
-
- private static final String SAVE_GRAPHICS_STATE = "q\n";
- private static final String RESTORE_GRAPHICS_STATE = "Q\n";
- private static final String CONCATENATE_MATRIX = "cm\n";
- private static final String XOBJECT_DO = "Do\n";
- private static final String SPACE = " ";
-
- private static NumberFormat formatDecimal = NumberFormat.getNumberInstance( Locale.US );
-
- /**
- * Add a rubber stamp with an jpg image to every page of the given document.
- * @param args the command line arguments
- * @throws IOException an exception is thrown if something went wrong
- */
- public void doIt( String[] args ) throws IOException
- {
- if( args.length != 3 )
- {
- usage();
- }
- else
- {
- PDDocument document = null;
- try
- {
- document = PDDocument.load( args[0] );
- if( document.isEncrypted() )
- {
- throw new IOException( "Encrypted documents are not supported for this example" );
- }
- List allpages = new ArrayList();
- document.getDocumentCatalog().getPages().getAllKids(allpages);
- int numberOfPages = allpages.size();
-
- for (int i=0; i < numberOfPages; i++)
- {
- PDPage apage = (PDPage) allpages.get(i);
- List annotations = apage.getAnnotations();
- PDAnnotationRubberStamp rubberStamp = new PDAnnotationRubberStamp();
- rubberStamp.setName(PDAnnotationRubberStamp.NAME_TOP_SECRET);
- rubberStamp.setRectangle(new PDRectangle(100,100));
- rubberStamp.setContents("A top secret note");
-
- // Create a PDXObjectImage with the given jpg
- FileInputStream fin = new FileInputStream( args[2] );
- PDJpeg mypic = new PDJpeg(document,fin);
-
- //Define and set the target rectangle
- PDRectangle myrect = new PDRectangle();
- myrect.setUpperRightX(275);
- myrect.setUpperRightY(575);
- myrect.setLowerLeftX(250);
- myrect.setLowerLeftY(550);
-
- // Create a PDXObjectForm
- PDStream formstream = new PDStream(document);
- OutputStream os = formstream.createOutputStream();
- PDXObjectForm form = new PDXObjectForm(formstream);
- form.setResources(new PDResources());
- form.setBBox(myrect);
- form.setFormType(1);
- // adjust the image to the target rectangle and add it to the stream
- drawXObject(mypic, form.getResources(), os, 250, 550, 25, 25);
- os.close();
-
- PDAppearanceStream myDic = new PDAppearanceStream(form.getCOSStream());
- PDAppearanceDictionary appearance = new PDAppearanceDictionary(new COSDictionary());
- appearance.setNormalAppearance(myDic);
- rubberStamp.setAppearance(appearance);
- rubberStamp.setRectangle(myrect);
-
- //Add the new RubberStamp to the document
- annotations.add(rubberStamp);
-
- }
- document.save( args[1] );
- }
- catch(COSVisitorException exception)
- {
- System.err.println("An error occured during saving the document.");
- System.err.println("Exception:"+exception);
- }
- finally
- {
- if( document != null )
- {
- document.close();
- }
- }
- }
- }
-
- private void drawXObject( PDXObjectImage xobject, PDResources resources, OutputStream os,
- float x, float y, float width, float height ) throws IOException
- {
- // This is similar to PDPageContentStream.drawXObject()
- String xObjectPrefix = "Im";
- String objMapping = MapUtil.getNextUniqueKey( resources.getImages(), xObjectPrefix );
- resources.getXObjects().put( objMapping, xobject );
-
- appendRawCommands( os, SAVE_GRAPHICS_STATE );
- appendRawCommands( os, formatDecimal.format( width ) );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, formatDecimal.format( 0 ) );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, formatDecimal.format( 0 ) );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, formatDecimal.format( height ) );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, formatDecimal.format( x ) );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, formatDecimal.format( y ) );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, CONCATENATE_MATRIX );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, "/" );
- appendRawCommands( os, objMapping );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, XOBJECT_DO );
- appendRawCommands( os, SPACE );
- appendRawCommands( os, RESTORE_GRAPHICS_STATE );
- }
-
- private void appendRawCommands(OutputStream os, String commands) throws IOException
- {
- os.write( commands.getBytes("ISO-8859-1"));
- }
-
- /**
- * This creates an instance of RubberStampWithImage.
- *
- * @param args The command line arguments.
- *
- * @throws Exception If there is an error parsing the document.
- */
- public static void main( String[] args ) throws Exception
- {
- RubberStampWithImage rubberStamp = new RubberStampWithImage();
- rubberStamp.doIt(args);
- }
-
- /**
- * This will print the usage for this example.
- */
- private void usage()
- {
- System.err.println( "Usage: java "+getClass().getName()+" <input-pdf> <output-pdf> <jpeg-filename>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java Tue Dec 6 20:19:29 2011
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.awt.Color;
-import java.io.IOException;
-
-import org.apache.pdfbox.exceptions.COSVisitorException;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-
-import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
-
-/**
- * This is an example that creates a simple document.
- *
- * The example is taken from the pdf file format specification.
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.2 $
- */
-public class ShowColorBoxes
-{
- /**
- * Constructor.
- */
- public ShowColorBoxes()
- {
- super();
- }
-
- /**
- * create the second sample document from the PDF file format specification.
- *
- * @param file The file to write the PDF to.
- *
- * @throws IOException If there is an error writing the data.
- * @throws COSVisitorException If there is an error writing the PDF.
- */
- public void doIt( String file) throws IOException, COSVisitorException
- {
- // the document
- PDDocument doc = null;
- try
- {
- doc = new PDDocument();
-
- PDPage page = new PDPage();
- doc.addPage( page );
-
- PDPageContentStream contentStream = new PDPageContentStream(doc, page);
- //first fill the entire background with cyan
- contentStream.setNonStrokingColor( Color.CYAN );
- contentStream.fillRect( 0,0, page.findMediaBox().getWidth(), page.findMediaBox().getHeight() );
-
- //then draw a red box in the lower left hand corner
- contentStream.setNonStrokingColor( Color.RED );
- contentStream.fillRect( 10, 10, 100, 100 );
-
- contentStream.close();
- doc.save( file );
- }
- finally
- {
- if( doc != null )
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will create a hello world PDF document.
- * <br />
- * see usage() for commandline
- *
- * @param args Command line arguments.
- */
- public static void main(String[] args)
- {
- ShowColorBoxes app = new ShowColorBoxes();
- try
- {
- if( args.length != 1 )
- {
- app.usage();
- }
- else
- {
- app.doIt( args[0] );
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private void usage()
- {
- System.err.println( "usage: " + this.getClass().getName() + " <output-file>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java Tue Dec 6 20:19:29 2011
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.pdmodel;
-
-import java.io.IOException;
-
-import org.apache.pdfbox.exceptions.COSVisitorException;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
-import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDType1Font;
-
-
-/**
- * This is an example of how to use a text matrix.
- * @version $Revision: 1.0 $
- */
-public class UsingTextMatrix
-{
- /**
- * Constructor.
- */
- public UsingTextMatrix()
- {
- super();
- }
-
- /**
- * creates a sample document with some text using a text matrix.
- *
- * @param message The message to write in the file.
- * @param outfile The resulting PDF.
- *
- * @throws IOException If there is an error writing the data.
- * @throws COSVisitorException If there is an error writing the PDF.
- */
- public void doIt( String message, String outfile ) throws IOException, COSVisitorException
- {
- // the document
- PDDocument doc = null;
- try
- {
- doc = new PDDocument();
-
- // Page 1
- PDFont font = PDType1Font.HELVETICA;
- PDPage page = new PDPage();
- page.setMediaBox(PDPage.PAGE_SIZE_A4);
- doc.addPage(page);
- float fontSize = 12.0f;
-
- PDRectangle pageSize = page.findMediaBox();
- float centeredXPosition = (pageSize.getWidth() - fontSize/1000f)/2f;
- float stringWidth = font.getStringWidth( message );
- float centeredYPosition = (pageSize.getHeight() - (stringWidth*fontSize)/1000f)/3f;
-
- PDPageContentStream contentStream = new PDPageContentStream(doc, page, false, false);
- contentStream.setFont( font, fontSize );
- contentStream.beginText();
- // counterclockwise rotation
- for (int i=0;i<8;i++)
- {
- contentStream.setTextRotation(i*Math.PI*0.25, centeredXPosition,
- pageSize.getHeight()-centeredYPosition);
- contentStream.drawString( message + " " + i);
- }
- // clockwise rotation
- for (int i=0;i<8;i++)
- {
- contentStream.setTextRotation(-i*Math.PI*0.25, centeredXPosition, centeredYPosition);
- contentStream.drawString( message + " " + i);
- }
-
- contentStream.endText();
- contentStream.close();
-
- // Page 2
- page = new PDPage();
- page.setMediaBox(PDPage.PAGE_SIZE_A4);
- doc.addPage(page);
- fontSize = 1.0f;
-
- contentStream = new PDPageContentStream(doc, page, false, false);
- contentStream.setFont( font, fontSize );
- contentStream.beginText();
-
- // text scaling
- for (int i=0;i<10;i++)
- {
- contentStream.setTextScaling(12+(i*6), 12+(i*6), 100, 100+i*50);
- contentStream.drawString( message + " " +i);
- }
- contentStream.endText();
- contentStream.close();
-
- // Page 3
- page = new PDPage();
- page.setMediaBox(PDPage.PAGE_SIZE_A4);
- doc.addPage(page);
- fontSize = 1.0f;
-
- contentStream = new PDPageContentStream(doc, page, false, false);
- contentStream.setFont( font, fontSize );
- contentStream.beginText();
-
- int i = 0;
- // text scaling combined with rotation
- contentStream.setTextMatrix(12, 0, 0, 12, centeredXPosition, centeredYPosition*1.5);
- contentStream.drawString( message + " " +i++);
-
- contentStream.setTextMatrix(0, 18, -18, 0, centeredXPosition, centeredYPosition*1.5);
- contentStream.drawString( message + " " +i++);
-
- contentStream.setTextMatrix(-24, 0, 0, -24, centeredXPosition, centeredYPosition*1.5);
- contentStream.drawString( message + " " +i++);
-
- contentStream.setTextMatrix(0, -30, 30, 0, centeredXPosition, centeredYPosition*1.5);
- contentStream.drawString( message + " " +i++);
-
- contentStream.endText();
- contentStream.close();
-
- doc.save( outfile );
- }
- finally
- {
- if( doc != null )
- {
- doc.close();
- }
- }
- }
-
- /**
- * This will create a PDF document with some examples how to use a text matrix.
- *
- * @param args Command line arguments.
- */
- public static void main(String[] args)
- {
- UsingTextMatrix app = new UsingTextMatrix();
- try
- {
- if( args.length != 2 )
- {
- app.usage();
- }
- else
- {
- app.doIt( args[0], args[1] );
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private void usage()
- {
- System.err.println( "usage: " + this.getClass().getName() + " <Message> <output-file>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/package.html
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/package.html?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/package.html (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/package.html Tue Dec 6 20:19:29 2011
@@ -1,25 +0,0 @@
-<!--
- ! Licensed to the Apache Software Foundation (ASF) under one or more
- ! contributor license agreements. See the NOTICE file distributed with
- ! this work for additional information regarding copyright ownership.
- ! The ASF licenses this file to You under the Apache License, Version 2.0
- ! (the "License"); you may not use this file except in compliance with
- ! the License. You may obtain a copy of the License at
- !
- ! http://www.apache.org/licenses/LICENSE-2.0
- !
- ! Unless required by applicable law or agreed to in writing, software
- ! distributed under the License is distributed on an "AS IS" BASIS,
- ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ! See the License for the specific language governing permissions and
- ! limitations under the License.
- !-->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-
-</head>
-<body>
-These examples show how to use the classes in the PDModel package.
-</body>
-</html>
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/CopyDoc.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/CopyDoc.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/CopyDoc.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/CopyDoc.java Tue Dec 6 20:19:29 2011
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.persistence;
-
-import java.io.IOException;
-
-import org.apache.pdfbox.cos.COSDocument;
-
-
-
-import org.apache.pdfbox.pdfparser.PDFParser;
-
-import org.apache.pdfbox.pdfwriter.COSWriter;
-import org.apache.pdfbox.exceptions.COSVisitorException;
-
-/**
- * This is an example used to copy a documents contents from a source doc to destination doc
- * via an in-memory document representation.
- *
- * @author Michael Traut
- * @version $Revision: 1.7 $
- */
-public class CopyDoc
-{
- /**
- * Constructor.
- */
- public CopyDoc()
- {
- super();
- }
-
- /**
- * This will perform the document copy.
- *
- * @param in The filename used for input.
- * @param out The filename used for output.
- *
- * @throws IOException If there is an error parsing the document.
- * @throws COSVisitorException If there is an error while copying the document.
- */
- public void doIt(String in, String out) throws IOException, COSVisitorException
- {
- java.io.InputStream is = null;
- java.io.OutputStream os = null;
- COSWriter writer = null;
- try
- {
- is = new java.io.FileInputStream(in);
- PDFParser parser = new PDFParser(is);
- parser.parse();
-
- COSDocument doc = parser.getDocument();
-
- os = new java.io.FileOutputStream(out);
- writer = new COSWriter(os);
-
- writer.write(doc);
-
- }
- finally
- {
- if( is != null )
- {
- is.close();
- }
- if( os != null )
- {
- os.close();
- }
- if( writer != null )
- {
- writer.close();
- }
- }
- }
-
- /**
- * This will copy a PDF document.
- * <br />
- * see usage() for commandline
- *
- * @param args command line arguments
- */
- public static void main(String[] args)
- {
- CopyDoc app = new CopyDoc();
- try
- {
- if( args.length != 2 )
- {
- app.usage();
- }
- else
- {
- app.doIt( args[0], args[1]);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * This will print out a message telling how to use this example.
- */
- private void usage()
- {
- System.err.println( "usage: " + this.getClass().getName() + " <input-file> <output-file>" );
- }
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/package.html
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/package.html?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/package.html (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/persistence/package.html Tue Dec 6 20:19:29 2011
@@ -1,25 +0,0 @@
-<!--
- ! Licensed to the Apache Software Foundation (ASF) under one or more
- ! contributor license agreements. See the NOTICE file distributed with
- ! this work for additional information regarding copyright ownership.
- ! The ASF licenses this file to You under the Apache License, Version 2.0
- ! (the "License"); you may not use this file except in compliance with
- ! the License. You may obtain a copy of the License at
- !
- ! http://www.apache.org/licenses/LICENSE-2.0
- !
- ! Unless required by applicable law or agreed to in writing, software
- ! distributed under the License is distributed on an "AS IS" BASIS,
- ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ! See the License for the specific language governing permissions and
- ! limitations under the License.
- !-->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-
-</head>
-<body>
-These examples will show how to use the persistence features of the PDFBox.
-</body>
-</html>
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java Tue Dec 6 20:19:29 2011
@@ -1,160 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.signature;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-
-import java.security.cert.CertificateFactory;
-
-import java.util.Collection;
-
-import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.cos.COSString;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-
-/**
- * This will read a document from the filesystem, decrypt it and do something with the signature.
- *
- * usage: java org.apache.pdfbox.examples.signature.ShowSignature <password> <inputfile>
- *
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.9 $
- */
-public class ShowSignature
-{
-
- private ShowSignature()
- {
- }
- /**
- * This is the entry point for the application.
- *
- * @param args The command-line arguments.
- *
- * @throws Exception If there is an error reading the file.
- */
- public static void main( String[] args ) throws Exception
- {
- ShowSignature show = new ShowSignature();
- show.showSignature( args );
- }
-
- private void showSignature( String[] args ) throws Exception
- {
- if( args.length != 2 )
- {
- usage();
- }
- else
- {
- String password = args[0];
- String infile = args[1];
- PDDocument document = null;
- try
- {
- document = PDDocument.load( infile );
-
- if( document.isEncrypted() )
- {
- document.decrypt( password );
- }
- else
- {
- System.err.println( "Warning: Document is not encrypted." );
- }
-
- COSDictionary trailer = document.getDocument().getTrailer();
- COSDictionary root = (COSDictionary)trailer.getDictionaryObject( COSName.ROOT );
- COSDictionary acroForm = (COSDictionary)root.getDictionaryObject( COSName.ACRO_FORM );
- COSArray fields = (COSArray)acroForm.getDictionaryObject( COSName.FIELDS );
- for( int i=0; i<fields.size(); i++ )
- {
- COSDictionary field = (COSDictionary)fields.getObject( i );
- String type = field.getNameAsString( "FT" );
- if( "Sig".equals( type ) )
- {
- COSDictionary cert = (COSDictionary)field.getDictionaryObject( COSName.V );
- if( cert != null )
- {
- System.out.println( "Certificate found" );
- System.out.println( "Name=" + cert.getDictionaryObject( COSName.NAME ) );
- System.out.println( "Modified=" + cert.getDictionaryObject( COSName.getPDFName( "M" ) ) );
- COSName subFilter = (COSName)cert.getDictionaryObject( COSName.getPDFName( "SubFilter" ) );
- if( subFilter != null )
- {
- if( subFilter.getName().equals( "adbe.x509.rsa_sha1" ) )
- {
- COSString certString = (COSString)cert.getDictionaryObject(
- COSName.getPDFName( "Cert" ) );
- byte[] certData = certString.getBytes();
- CertificateFactory factory = CertificateFactory.getInstance( "X.509" );
- ByteArrayInputStream certStream = new ByteArrayInputStream( certData );
- Collection certs = factory.generateCertificates( certStream );
- System.out.println( "certs=" + certs );
- }
- else if( subFilter.getName().equals( "adbe.pkcs7.sha1" ) )
- {
- COSString certString = (COSString)cert.getDictionaryObject(
- COSName.CONTENTS );
- byte[] certData = certString.getBytes();
- CertificateFactory factory = CertificateFactory.getInstance( "X.509" );
- ByteArrayInputStream certStream = new ByteArrayInputStream( certData );
- Collection certs = factory.generateCertificates( certStream );
- System.out.println( "certs=" + certs );
- }
- else
- {
- System.err.println( "Unknown certificate type:" + subFilter );
- }
- }
- else
- {
- throw new IOException( "Missing subfilter for cert dictionary" );
- }
- }
- else
- {
- System.out.println( "Signature found, but no certificate" );
- }
- }
- }
- }
- finally
- {
- if( document != null )
- {
- document.close();
- }
- }
- }
- }
-
- /**
- * This will print a usage message.
- */
- private static void usage()
- {
- System.err.println( "usage: java org.apache.pdfbox.examples.signature.ShowSignature " +
- "<password> <inputfile>" );
- }
-
-}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/package.html
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/package.html?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/package.html (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/signature/package.html Tue Dec 6 20:19:29 2011
@@ -1,25 +0,0 @@
-<!--
- ! Licensed to the Apache Software Foundation (ASF) under one or more
- ! contributor license agreements. See the NOTICE file distributed with
- ! this work for additional information regarding copyright ownership.
- ! The ASF licenses this file to You under the Apache License, Version 2.0
- ! (the "License"); you may not use this file except in compliance with
- ! the License. You may obtain a copy of the License at
- !
- ! http://www.apache.org/licenses/LICENSE-2.0
- !
- ! Unless required by applicable law or agreed to in writing, software
- ! distributed under the License is distributed on an "AS IS" BASIS,
- ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ! See the License for the specific language governing permissions and
- ! limitations under the License.
- !-->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-
-</head>
-<body>
-These examples will show how to gain access to the PDF signature.
-</body>
-</html>
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java?rev=1211082&r1=1211081&r2=1211082&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java Tue Dec 6 20:19:29 2011
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.examples.util;
-
-import org.apache.pdfbox.exceptions.InvalidPasswordException;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.util.PDFTextStripperByArea;
-
-import java.awt.Rectangle;
-
-import java.util.List;
-
-/**
- * This is an example on how to extract text from a specific area on the PDF document.
- *
- * Usage: java org.apache.pdfbox.examples.util.ExtractTextByArea <input-pdf>
- *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.2 $
- */
-public class ExtractTextByArea
-{
- private ExtractTextByArea()
- {
- //utility class and should not be constructed.
- }
-
-
- /**
- * This will print the documents text in a certain area.
- *
- * @param args The command line arguments.
- *
- * @throws Exception If there is an error parsing the document.
- */
- public static void main( String[] args ) throws Exception
- {
- if( args.length != 1 )
- {
- usage();
- }
- else
- {
- PDDocument document = null;
- try
- {
- document = PDDocument.load( args[0] );
- if( document.isEncrypted() )
- {
- try
- {
- document.decrypt( "" );
- }
- catch( InvalidPasswordException e )
- {
- System.err.println( "Error: Document is encrypted with a password." );
- System.exit( 1 );
- }
- }
- PDFTextStripperByArea stripper = new PDFTextStripperByArea();
- stripper.setSortByPosition( true );
- Rectangle rect = new Rectangle( 10, 280, 275, 60 );
- stripper.addRegion( "class1", rect );
- List allPages = document.getDocumentCatalog().getAllPages();
- PDPage firstPage = (PDPage)allPages.get( 0 );
- stripper.extractRegions( firstPage );
- System.out.println( "Text in the area:" + rect );
- System.out.println( stripper.getTextForRegion( "class1" ) );
-
- }
- finally
- {
- if( document != null )
- {
- document.close();
- }
- }
- }
- }
-
- /**
- * This will print the usage for this document.
- */
- private static void usage()
- {
- System.err.println( "Usage: java org.apache.pdfbox.examples.util.ExtractTextByArea <input-pdf>" );
- }
-
-}