GithubHelp home page GithubHelp logo

pcorless / icepdf Goto Github PK

View Code? Open in Web Editor NEW
68.0 9.0 20.0 35 MB

PDF Rendering and Viewing API in Java

License: Apache License 2.0

Java 99.97% HTML 0.03%
pdf pdf-viewer pdf-converter pdf-reader pdf-manipulation-utitilies java redaction redactor headless annotation-tool annotations

icepdf's Introduction

ICEpdf

ICEpdf is a pure Java PDF document rendering and viewing solution. ICEpdf can parse and render documents based on the latest PDF standards (Portable Document Format v1.6/Adobe® Acrobat® 7).

ICEpdf is a community-driven project with the goal of supporting and enhancing the ICEpdf library.

Contributing

ICEpdf is an open source project and is always looking for more contributors. To get involved, visit:

Getting Started

Whether you are long time user of the API or a new user, there ton of information on the Wiki pages. Create a pull requests and use the issue tracker, the more help and feedback we get the better we can make the project.

Getting the jars, javadoc and source from maven central

<dependency>
    <groupId>com.github.pcorless.icepdf</groupId>
    <artifactId>icepdf-core</artifactId>
<version>7.2.0</version>
</dependency>
<dependency>
    <groupId>com.github.pcorless.icepdf</groupId>
    <artifactId>icepdf-viewer</artifactId>
    <version>7.2.0</version>
</dependency>

Getting the Code

To get a local copy of the current code, clone it using git:

$ git clone https://github.com/pcorless/icepdf.git
$ cd icepdf

Building ICEpdf

In order to use the library you need to build at least the Core library and if you intend you use the Viewer component you'll also need to build the Viewer library. The project can be built with Gradle or Maven, we have no preference, pick one that makes you happier.

Builds as they are currently configured to target Java 11.

Building With Maven

# core module
~$ mvn -pl :icepdf-core package

# viewer module, -am insures dependencies are build 
~$ mvn -pl :icepdf-viewer -am package

# Viewer jar with all dependences in one self executing jar
~$ mvn -pl :icepdf-viewer -am package -P assembly 

# examples module, -am insures dependencies are build 
~$ mvn -pl :png-capture -am package
# or with full group id. 
~$ mvn -pl org.icepdf.examples:png-capture -am package
~$ java -jar icepdf-viewer-7.0.0-SNAPSHOT-jar-with-dependencies.jar

# Whole project hierarchy can be built with or with full group id. 
~$ mvn package

Building With Gradle

Build the core jar using the following Gradle command

~$ gradle :core:core-awt:assemble

Build the viewer jar using the following Gradle command

~$ gradle :viewer:viewer-awt:assemble

Build the annotation creation example using the following Gradle command

~$ gradle :examples:annotation:creation:assemble

Build the distribution zip and tar archives

# defaultTasks allows for a call to just gradle 
~$ gradle
# or one can use the full task list 
~$ gradle projectReport, sourcesJar, genPomFileForCoreJarPub, genPomFileForViewerJarPub, osDistZip, osDistTar

Using ICEpdf Viewer Component

The org.icepdf.core.ri.common.SwingController class provides convenience methods for the most common UI actions, such as rotating the document, setting the zoom level, etc. The org.icepdf.core.ri.common.SwingViewBuilder class is responsible for creating the PDF Viewer component panel populated with Swing components configured to work with the SwingController.

When using the SwingViewBuilder and SwingController classes, it is usually not necessary to use the Document object directly. The SwingController class does this for you.

The following code snippet illustrates how to build a PDF Viewer component:

String filePath = "somefilepath/myfile.pdf";

// initiate font caching for faster startups
FontPropertiesManager.getInstance().loadOrReadSystemFonts();

// build a controller
SwingController controller = new SwingController();

// Build a SwingViewFactory configured with the controller
SwingViewBuilder factory = new SwingViewBuilder(controller);

// Use the factory to build a JPanel that is pre-configured
//with a complete, active Viewer UI.
JPanel viewerComponentPanel = factory.buildViewerPanel();

// add copy keyboard command
ComponentKeyBinding.install(controller, viewerComponentPanel);

// add interactive mouse link annotation support via callback
controller.getDocumentViewController().setAnnotationCallback(
     new org.icepdf.ri.common.MyAnnotationCallback(
            controller.getDocumentViewController()));

// Create a JFrame to display the panel in
JFrame window = new JFrame("Using the Viewer Component");
window.getContentPane().add(viewerComponentPanel);
window.pack();
window.setVisible(true);

// Open a PDF document to view
controller.openDocument(filePath);

Page Captures

The Document class provides functionality for rendering PDF content into other formats via a Java2D graphics context. As a result, rendering PDF content to other formats is a relatively simple process with very powerful results. ICEpdf also supports Java headless mode when rending PDF content, which can be useful for server side solutions.

Examples of extraction techniques like png, svg, and tiff can be found examples/capture folder. The following is an example of how to save page captures in an SVG format

String filePath = "somefilepath/myfile.pdf";
Document document = new Document();
document.setFile(filePath);

// Get a DOMImplementation
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
org.w3c.dom.Document svgDocument = domImpl.createDocument(null,"svg",null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument);
float userRotation = 0;
float userZoom = 1;
int pageNumber = 0;

PDimension pdfDimension=document.getPageDimension(pageNumber,userRotation,userZoom);
svgGenerator.setSVGCanvasSize(pdfDimension.toDimension());

// paint the page to the Batik svgGenerator graphics context.
document.paintPage(pageNumber,svgGenerator,
    GraphicsRenderingHints.PRINT,
    Page.BOUNDARY_CROPBOX,
    userRotation,
    userZoom);

File file = new File("svgCapture_"+pageNumber+".svg");
// Finally, stream the SVG using UTF-8character byte encoding
Writer fileWriter = new OutputStreamWriter(new FileOutputStream(file),StandardCharsets.UTF_8);
// Enable SVG CSS style attribute
boolean SVG_CSS = true;
svgGenerator.stream(fileWriter,SVG_CSS);

Make sure to take a look at the Wiki for more examples of extracting content.

Learning

Examples

There are a bunch of examples located in the root of the project grouped by common usage scenarios. Similarly, the Wiki contains example information.

API Documentation

Both the Gradle and Maven builds will generate the API documentation for the Core and Viewer libraries.

icepdf's People

Contributors

a-leithner avatar geniot avatar gtache avatar pcorless avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

icepdf's Issues

Remove old examples that are no longer mantained

There are a few older demos that are now longer relevant and/or no longer maintained.

Demos to remove

  • Remove examples/jws/ as JWS is no longer supported by the main browser and newer JDK's.
  • Remove icefaces example as it has not been maintain for quite some time.

Update dependencies

Update builds with latest version for the following libraries.

  • Twelve Monkey image library
  • Jbig2 image library
  • Validate with full QA comparison run.

Annotation references errors

I found a nasty bug with the annotation references. When creating annotations, some already existing references are given by the state manager, which then corrupts the library and the pdf.
To reproduce:

  • Get an unannotated pdf file, with several pages.
  • Create 8 annotations on page 2 (numbers are arbitrary, just need to create and delete several annotations)
  • Delete the first 4 annotations
  • Save the file, open it in a new window
  • Create an annotation on page 1
  • Save the file, open it
  • PDF is corrupted, the annotation created on page 1 also appears on the second page

It's just a supposition, but I think it comes down to trailer.getNumberOfObjects in the StateManager instantiation, which is wrong when some newly created annotations are deleted after some newer annotations are added to the PDF. The deleted annotations are never added to the trailer and the size therefore doesn't take them into account, which means that the references of the newer annotations (or PopupAnnotation) are overwritten.

Writable pbojects

Build out a Writable interface for objects that are written to file. Mainly object, dictionary, xref and trailer. Classes would have an instance of the respective writer.

The writer might look something like this.

Stream extends Dictionary implements Writeable 
  // Has an instance of StreamWriter to do the hand off. 

StreamWriter extends Basewriter implements Writer.

Update build scripts

Update build scripts to latest version of gradle/maven and support openJDK 11+ and JavaFx.

Improve translations

Lots of translations are missing, so it would be good to update them.
FR and DE translations will be updated once (most) of the PRs are merged.

Improve search

At the moment, the search is quite limited. Search input is split, search terms are matched only word-wise, so multi-word search or more complex regexes don't work.

Prettify window header

Having ICEpdf - [pathtofile] is not practical, as the user most of the times can't see in the taskbar what file is opened on an ICEpdf window. Displaying simply the name of the file would be clearer.

Small changes and bugfix

  • Locks annotationComponents on refresh (Somehow got a ConcurrentModificationException)
  • Adds getControllers to WindowManager
  • Changes MarkupAnnotation toString (for better debugging mainly)
  • Fixes AnnotationComparator page sorting

Editable ObjectStreams

Add support for editing existing object stream's child objects. The incremental writer would need to be able to write out the edited object and make sure the xref tables are updated accordingly.

Implement save

It's just a proposition, but I think the default save (and the save button), with Ctrl+S, should save to the same filename. Save As (Ctrl+Shift+S) should obviously stay as is.

Cannot download ICEPdf pro zip file

Hey Patrick, I am unable to download the ICEpdf pro version from the official website. When not logged in, the download button appears but as soons as I log in, the button just disappears. Also I cannot download without logging in. How can I download the pro version?

Reopens Open file dialog if wrong file type has been selected

At the moment, if the user selects a non-pdf file, an error is displayed and the open file dialog closes. It would be more user-friendly for the open file dialog to reopen in this case, as it was surely a misclick from the user and they probably still want to open a file.

NIO object parser

NIO base object parser. Fixes a bunch of issue with our current object parser, especially around re-indexing a file. Also speed things up.

Allow "injecting" SwingController and SwingViewBuilder

Basically, by using Factories and setting them in WindowManager, it would allow creating custom Controllers and ViewBuilders and therefore have a custom implementation of the ICEpdf GUI.
This allows (more or less) completely decoupling the ICEpdf codebase and a potential extension codebase.

API pain point adding annotation to PageViewComponent

Of recent and of late there are users that need to dynamically add annotations to PDF content. The annotation data may have been saved to a DB or a flat file but in either way it needs to be injected back into the view and eventually on the screen or capture.

When working in the viewer, the annotation must be create and then an annotation component must be create so the user can interact with the annotation. This process can be difficult to achieve by the end user of the API. The process requires quite a bit of work an there can be timing issues with the various thread in play.

This ticket is to capture building out an API to streamline this process.

Update about dialog and splash screen

Remove the old splash screen implementation from the Viewer RI as it's kind of pointless and doesn't work that will on JDK > 8.

Also touch up the about dialog and support graphics to reflect the projects new home.

Search Toolbar

A community member has requested that we create a new toolbar for quick search. The menu bar would allow to the user to enter search terms, cursors buttons for next and previous terms. There would also be an advanced menu for changes search settings, similar to the search tab in the utility panel.

set org.icepdf.core.awtFontLoading default value to true

Until I have time to port a new font library, the default value of org.icepdf.core.awtFontLoading should be set to true. Newer version of the JDK can do a pretty good job parsing truetype and open type fonts which will help improve font rendering out of the box.

update build scripts

Mainly update build scripts for Gradle 6.x and touch up maven scripts as well. Also a bunch a clean up to references terminated repositories.

Community documentation

Update icepdf documentation for new home on github.
This mainly includes removal of corporate landmarks and addition of wiki content.

  • Create a readme for the project.
  • Remove svn references from build system, replace with github
  • Check for corporate landmarks
  • Build out the wiki with useful info.

Don't open annotation panel on annotation selection

Currently, selecting an annotation will open the annotation panel, which brings more disturbance than value to the user. If they want to see the tree of annotations, they will open the annotation panel themselves.

Some messages are not being formatted

MessageFormat doesn't like single quotes, therefore some messages, like the exceptions in French, display the non-formatted message (ex: "Une erreur s'est produite lors de l'exécution de la commande en raison de l'exception suivante {0}")

Placing an icon over the pages of PDF

Hey patrick, I have found ICEpdf an amazing tool. What I am really looking for is that I should be able to place an icon or an image over each page of pdf. For instance, suppose I am checking an answer sheet of a student and I want to place a correct icon(✔️) or wrong icon(✖️) at the end of each page and these should be able to be saved along with file.
Is there any inbuilt method in icepdf, I really need it!

Thank you

Potential bugs

I've found some potential bugs when going through the code :

  • Some class extending AbstractWorkerPanel not setting the workerTask when it's created
  • BorderStyle getting BORDER_STYLE_DASH instead of BORDER_DASH_KEY in the constructor
  • initPageAnnotations setting a outside the loop, which means that although a should be null during an iteration, it may still have a value from a previous one

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.