Apache PDFBox create PDF Form

PDF form is a great option to distribute and accept data from users. PDF form is similar to a Paper form but with lot more convenience. Apache PDFBox provides low-level APIs to create PDF forms with a rich set of controls and to specify rich formatting options. In the previous article, we explored creating custom pages and adding feature-rich content to a PDF, in this article we will create a PDF form.

Continue reading

PDFBox customize page size, adding images and custom fonts

In this article, we will look at some of the features offered by Apache PDFBox. In the real world, documents created using PDF libraries may require an additional feature of setting custom page size. Fortunately, PDFBox comes with API to specify page size as per standard units referred in a day to day business. The page sizes are A0, A1, …, A6, LEGAL, and LETTER.
Continue reading

Java 8 streams API

My experience with querying a collection has always been clumsy. Writing iterative loops, adding nested if conditions and above all the hack of maintaining intermediary collection to store results. On top of that the brutal indicators from SonarQube – cyclomatic complexity. During all this, I felt there is a common pattern for filtering, sorting and there has to be an expressive way to achieve this functionality(someone said more like SQL!!!). With my love towards multiple technologies (Ok I accept I am a polyglot coder), I knew .Net already had an answer to this – LINQ. Simply have a collection and write a query to extract data. Something like below
Continue reading

What is lambda? and why do we need it?

When I started coding GUI application using Java, I realized my code was cluttered with too many anonymous classes. Each time, I had to handle an event the inlined implementation of ActionListener introduced nested and unreadable lines of code. How many of you have written code like below

signUpUserBtn.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){

Continue reading

Java 8 – Method Reference – Is it Magic?

Amongst the notable features in Java8, Method Reference adds Shorthand syntax for a lambda expression. In most cases, Lambda expression does nothing more than just calling a single method. If you find yourself doing that most often, its time to look at Method reference. It can be used to replace entire Lambda expression, let’s have a look at following example
Continue reading

Java 8 – What is functional Interface?

Functional interface is a new addition to Java 8. In simple terms, an interface which has one single abstract method is qualified as Functional interface. The built-in classes in JDK are full of examples of Functional Interfaces(Runnable, Callable, ActionListener). Java 8 formalized such interface definition with @FunctionalInterface annotation. FunctionalInterface is also useful while creating lambda expressions. Those who are not familiar with Lambda expression, it was again a new feature introduced in Java 8. Lambda helps developers to write concise code. Its expressive syntax saves developer’s time. Before Lambda, for every single method declaration of an interface, developers had to create Class. Eventually, an application source code is filled with many small classes which just provide an implementation for one single method. FunctionalInterface and Lambda expressions are considered to be best practice for writing neat code. Lets have a look at how JavaDoc describes FunctionalInterface
Continue reading

Spring boot and docker

Spring boot has eased the life of developer by reducing boilerplate configuration and reduced project bootstrap time by declaring defaults. Those who are already working on Spring projects and are leveraging Spring boot must have realized productivity gains. In addition to that, Maven build script (pom.xml) has been shortened due to single dependencies made available by Spring boot for a specific purpose. For example including spring-boot-jpa-starter dependency in Maven script ensures that all the required dependencies for interacting with a database are available with a single declaration. While there are many benefits of spring boot, one of the major benefits is to run the application quickly with embedded tomcat instead of having need of a separate server. This has definitely shortened the development cycle and developers can now focus more on building solution for business requirements. Being able to easily deploy the application and that too with speed container approach is on the rise. Spring boot application can be easily be bundled along with container solutions like Docker.
Continue reading

PDF operations using Apache PDFBox without stings

PDF is a convenient way of printing the output and sharing the data with application users. Its ability to scale as per display without distorting the contents, is considered to be the strongest feature over other output formats. As per application requirements, it also becomes necessary to generate PDF at runtime. There are many options, available to do so. Either use reporting tools like Jasper and then using reporting API generate the output in PDF OR if you wish to have finer controls over PDF generation use programming API like iText. iText uses AGPL for Open Source, and it can be pretty fatal, if you really don’t understand its legal terms. Contact someone who understands Open Source licenses. Most of the time, developers forget to pay attention to the licensing model. Developers usually don’t understand what Open source really means, most of them feel its free like air they breath and ignorantly fall into the trap of License violation. Usage of any Open Source software without paying attention to License, can result into lawsuit against development company or hefty payments to the governing company of Open source software. Unfortunately the Illiteracy rate is way too high. Why, I am bragging about all of this, simply the reason is – if you are using iText, be ready to either Open Source your software or pay for use (Once again pay attention to details, don’t just buy any license). OK! so is there really any other option, than just paying bucks. Yes, there is and as usual, Apache is here for your rescue – Apache PDFBox.

Continue reading