Giter Club home page Giter Club logo

orsonpdf's Introduction

OrsonPDF

Version 1.9.1, by David Gilbert, 6 November 2022.

(C)opyright 2013-2022, by David Gilbert. All rights reserved.

Maven Central

Overview

OrsonPDF is a PDF generation library for the Java(tm) platform that allows you to create content in PDF format using the standard Java2D drawing API (Graphics2D). OrsonPDF is light-weight, fast, and has no dependencies other than the Java runtime (version 8 or later). The home page for the project is:

https://github.com/jfree/orsonpdf

Getting Started

The Javadoc page for the PDFDocument class gives an example of typical usage and, if you are already familiar with the Java2D APIs, then all you need to do is add orsonpdf-1.9.1.jar to your classpath and start coding.

Oracle provides tutorials for Java2D here:

http://docs.oracle.com/javase/tutorial/2d/

There are some demonstration applications included in the JFree Demos project.

Include

OrsonPDF is published to the Central Repository. You can include it in your projects with the following dependency:

<dependency>
    <groupId>com.orsonpdf</groupId>
    <artifactId>orsonpdf</artifactId>
    <version>1.9.1</version>
</dependency>

For developers using the Java Module System, OrsonPDF defines the automatic module name com.orsonpdf.orsonpdf. Alternatively, a new project (https://github.com/jfree/jfreepdf) has been created that supports Java modules directly but requires Java 11 or later.

Build

You can build OrsonPDF from sources using Maven:

mvn clean install

Dual Licensing

OrsonPDF is dual licensed. You can use OrsonPDF under the terms of the GNU General Public License version 3 (GPLv3) or later. If you prefer not to be bound by the terms of the GPLv3, an alternative license is available to JFree sponsors.

OrsonPDF integrates the Ascii85OutputStream class written by Ben Upsavs and distributed freely under the (BSD-style) terms listed in the Ascii85OutputStream-license.txt file.

Change History

Version 1.9.1 (6 November 2022)

  • fix for getPDFPath() method in GraphicsStream (#7)
  • update pom.xml plugin dependencies

Version 1.9 (9 February 2019)

  • fix for drawString() method exception when passing an empty string;
  • fix for drawImage() with null for BufferedImageOp;
  • fix for transform issue with child Graphics2D instance from create();
  • added automatic module name (com.orsonpdf.orsonpdf).

Version 1.8 (30 November 2017)

Version 1.7 (28 September 2015)

  • implemented PDFGraphics2D.create() method;
  • added support for image transparency;
  • fixed broken PDFGraphics2D.drawImage() method;
  • added GPLv3 or later as a license option.

Version 1.6 (31 March 2014)

  • added support for shape outlining with arbitrary Stroke implementations (previously only BasicStroke was recognised);
  • minor Javadoc updates.

Version 1.5 (5 March 2014)

  • added rendering hint DRAW_STRING_TYPE which provides an option to render text as vector graphics, which allows the inclusion of Unicode characters in the output without font embedding;
  • improve support for alpha transparency;
  • minor additions to default font mapping.

Version 1.4 (18 December 2013)

  • fixed invalid XREF table which caused Acrobat Reader to prompt for saving when closing PDFs;
  • added debug mode to generate PDF file without filtering;
  • fixed a bug in the graphics stream generation that resulted in malformed PDF output in some locales.

Version 1.3 (8 November 2013)

  • implemented getDeviceConfiguration();
  • fixed transform bug that could result in malformed PDF output;
  • fixed a bug in the getClipBounds() method when the clip is null;
  • corrected the Producer version info;
  • fixed a bug with the date formatter for the document creation date.

Version 1.2 (12 September 2013)

  • fixed bug in RadialGradientPaint support.

Version 1.1 (3 September 2013)

  • reimplemented drawString(AttributedCharacterIterator, float, float) using TextLayout and modified drawGlyphVector() to fill rather than stroke shapes;
  • added degree elevation to the quadratic segments of Path2D objects to ensure correct output quality;
  • fixed Page so it does not add /XObject to resources if there are no xObjects;
  • fixed bug affecting switch between GradientPaint and Color;
  • fixed clipping bug;
  • moved PDF classes into OrsonPDF project (changing the root package to com.orsonpdf.*);

Version 1.0 (31 July 2013)

  • Initial public release (JFreeGraphics2D).

orsonpdf's People

Contributors

jfree avatar mhschmieder 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

orsonpdf's Issues

Transformation (scaling) issue after g2.create()

After calling Graphics2D tempGraphics = (Graphics2D) g2d.create(); and doing transformations on the tempGraphics object (see method code below), there is some unexpected behaviour.
When drawing again on the original g2d object, the drawing is done at wrong scale (and place).

In other words: the "Transform" of the original Graphics2D object gets changed by its copy.

   private void drawString(Graphics2D g2d, String lb, double mmX, double mmY) {
        float sf = 10; //fontscalefactor
        AffineTransform scaled = AffineTransform.getScaleInstance(1d / sf, 1d / sf);
        Graphics2D tempGraphics = (Graphics2D) g2d.create();
        tempGraphics.transform(scaled);
        tempGraphics.drawString(lb, (float)mmX * sf, (float)mmY * sf);
        tempGraphics.dispose(); // Release system ressources
    }

It seems that PDFGraphics2D.create() passes over the GraphicsStream object gs to the new Graphics object. So the original and new Graphics objects share gs. Maybe this is the reason transformations apply to both objects.

Note: jFreeSvg does not have this issue

Unable to render non-English letters supported by the font

I can't get Orson PDF to display non-English letters contained in the text when not rendering the text as vector graphic. I only get '???' where it should say "ØÆÅ". I have checked that the Font supports this letter using Font#canDisplay() and it is of course installed on the system (checked using Font#getFamily() being not equal to DIALOGUE).

    Font f = new Font("DejaVu Serif", PLAIN, 16);
    graphics2D.setFont(f);
    System.out.println("family" + f.getFamily() + " " + f.getName());
    System.out.println("Can display Ø:" + f.canDisplay('Ø') );

    //vector works
    graphics2D.setRenderingHint(PDFHints.KEY_DRAW_STRING_TYPE, PDFHints.VALUE_DRAW_STRING_TYPE_VECTOR);
    graphics2D.drawString("VECTOR: æøå ØÅÆ", 0, 20);

    //normal text doesn't
    graphics2D.setRenderingHint(PDFHints.KEY_DRAW_STRING_TYPE, PDFHints.VALUE_DRAW_STRING_TYPE_STANDARD);
    graphics2D.drawString("TEXT: æøå ØÅÆ", 300, 20);

JFreeChart ChartPanel renders as Raster rather than Vector

In OrsonPDF Version 1.7 (downloaded from Object Refinery ), I tried to run the demo programs (under src/main/java/com/orsonpdf/demo) to verify that JFreeCharts indeed render as vector format pdfs.

PDFBarChartDemo1 seems to render a very beautiful PDF, so what I did is I copied the createChart() and createDataset() methods from it and put them in SwingUIToPDFDemo. Then I modified the createContent() method, and changed the following line:

tabs.add("Tab 2", new JButton("Second Tab"));

to look as follows:

tabs.add("Tab 2", new ChartPanel(createChart(createDataset())));

When I run the SwingUIToPDFDemo now, on Tab 2 I get the same JFreeChart as I got when running the Bar Chart demo, yet when I press the "Save to PDF" button, the pdf that I get renders the chart as a raster chart rather than a vector chart.

Is there a workaround for this?

Embedding exotic fonts into PDF

Hello,

I have an issue with fonts. Generally I use Dialog font but also some system fonts that are not default Java fonts but this library seems to support only default fonts (12 of 14 in fact). Exotic fonts are replaced by Courier, that is not good for me.

There is a way to embed them automatically ?

In code, The Pages.findOrCreateFontReference() method and its call to FontMApper.mapToBaseFont() seems to be the origin of font selection but I don't know how PDF format works.

Best regards,

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.