Git Product home page Git Product logo

docraptor-java's Introduction

DocRaptor Java Native Client Library

This is a maven package for using DocRaptor API to convert HTML to PDF and XLSX.

Installation

To install the API client library to your local Maven repository, simply execute:

mvn install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn deploy

After the client library is installed/deployed, you can use it in your Maven project by adding the following to your pom.xml:

<dependency>
  <groupId>com.docraptor</groupId>
  <artifactId>docraptor</artifactId>
  <version>3.2.0</version>
</dependency>

Basic Usage

import java.io.*;
import java.net.*;
import com.docraptor.*;

public class Sync {
  public static void main(String[] args) throws Exception {
    DocApi docraptor = new DocApi();
    ApiClient client = docraptor.getApiClient();
    client.setUsername("YOUR_API_KEY_HERE"); // this key works for test documents
    //client.setDebugging(true);

    Doc doc = new Doc();
    doc.setTest(true);                                                   // test documents are free but watermarked
    doc.setDocumentContent("<html><body>Hello World</body></html>");     // supply content directly
    // doc.setDocumentUrl("http://docraptor.com/examples/invoice.html"); // or use a url
    doc.setDocumentType(Doc.DocumentTypeEnum.PDF);                       // PDF or XLS or XLSX
    doc.setName("docraptor-java.pdf");                                   // help you find a document later
    doc.setJavascript(true);                                             // enable JavaScript processing
    // prince_options = new PrinceOptions();
    // doc.setPrinceOptions(prince_options);
    // prince_options.setMedia("screen");                                // use screen styles instead of print styles
    // prince_options.setBaseurl("http://hello.com")                     // pretend URL when using document_content
    docraptor.createDoc(doc);
  }
}

Next Steps

  • Optionally store and get a URL for your converted document with document hosting
  • View more code examples with error handling, asynchronous creation, file saving, and document hosting.
  • Perfect your document styling with our style and formatting reference, and API reference. Easily add headers and footers, page breaks, page numbers, table of contents, and much more!

More Help

Stuck? We're experts at turning HTML into PDFs so please email us if you run into trouble.

Development

The majority of the code in this repo is generated using openapi-generator on docraptor.yaml. You can modify this file and regenerate the client using script/generate_language.

If dependencies change in the generated code then the pom.xml will need regenerated by swagger which it only does if the file doesn't exist. To regenerate it:

  • delete the pom.xml
  • run script/generate_language
  • an additional maven plugin is used to deploy the library to the nexus repository which regenerating the pom.xml file removes. To replace it add the following plugin in the <project><build><plugins> section:
    <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>1.6</version>
        <extensions>true</extensions>
        <configuration>
            <serverId>ossrh</serverId>
            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
            <autoReleaseAfterClose>true</autoReleaseAfterClose>
        </configuration>
    </plugin>
    

Release Process

If you haven't released before, please see the release setup guide.

  1. Pull latest master
  2. Merge feature branch(es) into master
  3. script/test
  4. Increment version:
  • generator-config.json
  • README.md
  1. Run script/generate_language to update generated version numbers:
  • build.gradle
  • pom.xml
  • src/main/java/com/docraptor/ApiClient.java
  1. Update CHANGELOG.md
  2. Commit "Release vX.Y.Z"
  3. Push to GitHub
  4. Tag version: git tag 'vX.Y.Z' && git push --tags
  5. script/release
  6. Verify package release at Central (takes anywhere from minutes to days)
  7. Open https://github.com/DocRaptor/docraptor-java/tags and make a new release for the version. Use the git tag as the name, CHANGELOG entries as the description, and attach target/docraptor-* to the release
  8. Refresh documentation on docraptor.com

Version Policy

This library follows Semantic Versioning 2.0.0.

docraptor-java's People

Contributors

davidronk avatar esquivalient avatar jamespaden avatar janxious avatar jason-o-matic avatar jqr avatar mediocretes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

docraptor-java's Issues

Add binary corruption test

It's easy for generated clients to return accidentally utf8 encoded data, which ends up corrupting PDF/XLS/XLSX files. Let's add a test to ensure this can never happen.

ignore_console_messages is included on every request

ignore_console_messages, which defaults to true as of Pipeline 7, is included on every Java agent request as false. This causes console messages to unexpectedly fail documents. My expectation would be that ignore_console_messages isn't included in the request unless explicitly defined.

As a workaround, ignore_console_messages can simply be set to true.

Using vulnerable Jackson library

The project is using Jackson 2.4.2.

http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2017-7525
CVSS Score: 9.8
A deserialization flaw was discovered in the jackson-databind, versions before 2.6.7.1, 2.7.9.1 and 2.8.9, which could allow an unauthenticated user to perform code execution by sending the maliciously crafted input to the readValue method of the ObjectMapper.

Explanation
jackson-databind is vulnerable to Remote Code Execution (RCE). The createBeanDeserializer() function in the BeanDeserializerFactory class allows untrusted Java objects to be deserialized. A remote attacker can exploit this by uploading a malicious serialized object that will result in RCE if the application attempts to deserialize it.

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.