Cookbook

The Cookbook for PDFBox is a collection of source code samples to help using PDFBox. The samples are a growing collection of individual topics covering a wide range of PDF applications. In addition the Tutorials cover some of the most common applications of PDFBox.

Document creation

Sample Description
CreateBlankPDF This small sample shows how to create a new PDF document using PDFBox.
HelloWorld This small sample shows how to create a new document and print the text "Hello World" using one of the PDF base fonts.
HelloWorldTTF This small sample shows how to create a new document and print the text "Hello World" using a TrueType Font.
HelloWorldType1AfmPfb This is an example that creates a simple document with a Type 1 font (afm + pfb).
ImageToPDF This is an example that creates a simple document from an image.
ShowColorBoxes This is an example that creates a simple document with different boxes.

Working with metadata

Sample Description
PrintDocumentMetaData This is an example on how to get a documents metadata information.
AddMetadataFromDocInfo This is an example on how to add metadata to a document.
ExtractMetadata This is an example on how to extract metadata from a PDF document.

Dealing with forms

Sample Description
PrintFields Shows how to print all the fields from a PDF document
SetField Shows how to set the value of a form field in a PDF document

Using the PDModel

Sample Description
AddImageToPDF This is an example that reads a PDF document and adds an image to it.
AddJavascript This is an example of how to set some JavaScript in the document.
AddMessageToEachPage This is an example of how to add a message to every page in a PDF document.
Annotation This is an example on how to add annotations to pages of a PDF document.
CreateBookmarks This is an example on how to add bookmarks to a PDF document.
EmbeddedFiles This is an example that creates a simple document and embeds a file into it..
GoToSecondBookmarkOnOpen This is an example on how to an action to go to the second page when the PDF is opened.
PrintBookmarks This is an example on how to access the bookmarks that are part of a pdf document.
PrintURLs This is an example of how to access a URL in a PDF document.
RemoveFirstPage This is an example on how to remove pages from a PDF document.
ReplaceString This is an example that will replace a string in a PDF with a new one.
ReplaceURLs This is an example of how to replace a URL in a PDF document.
RubberStamp This is an example on how to add annotations to pages of a PDF document.
RubberStampWithImage This is an example on how to add a rubber stamp with an image to pages of a PDF document.
UsingTextMatrix This is an example of how to use a text matrix.

PDFBox persistence features

Sample Description
CopyDoc This is an example used to copy a documents contents from a source doc to destination doc via an in-memory document representation
PrintFields Shows how to load a PDF document and write with all streams decoded.

Working with signatures

Sample Description
ShowSignature This examples will show how to gain access to the PDF signature

Text and Image locations

Sample Description
ExtractTextByArea This is an example on how to extract text from a specific area on the PDF document.
PrintImageLocations This is an example on how to get the x/y coordinates of image locations.
PrintTextLocations This is an example on how to get some x/y coordinates of text.
RemoveAllText This is an example on how to remove all text from PDF document.