Code Monkey home page Code Monkey logo

pdf-processor's Introduction

PDF Processor

PDF Processor reads tests from PDF, gets QR code for that text, and write it to another PDF. It also writes the extracted text in a JSON file.

Create the database

Go to the terminal (command Prompt cmd in Microsoft Windows). Open MySQL client with a user that can create new users.

For example: On a Linux, use the command

$ sudo mysql --password
Note
This connects to MySQL as a root, this is not the recommended way for a production server.

Create a new database

mysql> create database localdb; -- Create the new database
mysql> create user 'user'@'localhost' identified by 'password'; -- Creates the user
mysql> grant all on localdb.* to 'user'@'localhost'; -- Gives all the privileges to the new user on the newly created database

Create the application.properties file

Spring Boot gives you defaults on all things, the default in database is H2, so when you want to change this and use any other database you must define the connection attributes in the application.properties file.

In the sources folder, you create a resource file src/main/resources/application.properties

include::src/main/resources/application.properties

Here, spring.jpa.hibernate.ddl-auto can be none, update, create, create-drop, refer to the Hibernate documentation for details.

  • none This is the default for MySQL, no change to the database structure.

  • update Hibernate changes the database according to the given Entity structures.

  • create Creates the database every time, but don’t drop it when close.

  • create-drop Creates the database then drops it when the SessionFactory closes.

We here begin with create because we don’t have the database structure yet. After the first run, we could switch it to update or none according to program requirements. Use update when you want to make some change to the database structure.

The default for H2 and other embedded databases is create-drop, but for others like MySQL is none

It is good security practice that after your database is in production state, you make this none and revoke all privileges from the MySQL user connected to the Spring application, then give him only SELECT, UPDATE, INSERT, DELETE.

This is coming in details in the end of this guide.

Create a Scheduled Job for your Spring application

src/main/java/xyz/fullstack/development/job/PdfProcessorJob.java

include::src/main/java/xyz/fullstack/development/job/PdfProcessorJob.java
Note
This class contains the Job configuration for Batch jobs (Reader, Processor, Writer)

Make the application executable

Although it is possible to package this service as a traditional WAR file for deployment to an external application server, the simpler approach demonstrated below creates a standalone application. You package everything in a single, executable JAR file, driven by a good old Java main() method. Along the way, you use Spring’s support for embedding the Tomcat servlet container as the HTTP runtime, instead of deploying to an external instance.

src/main/java/xyz/fullstack/development/Application.java

include::src/main/java/xyz/fullstack/development/Application.java

Logging output is displayed. The service should be up and running within a few seconds.

Test the application

Now that the application is running, you can test it.

$ mvn package

Once the source is built,

$ cd target
$ java -jar pdf-processor-1.0.jar

This should start the application and the scheduled job with it.

pdf-processor's People

Contributors

eaingaran avatar

Watchers

 avatar  avatar

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.