Aspose Support:
We have purchased Aspose.Pdf for Java. Using your trial version (for evaluation purpose), I have come up with some code to see if it will meet our requirement. The code seems to be working fine but I am writing this to get your input/suggestions/improvements if any to my code. My point here is as you own Aspose API, you can suggest me if there is any other better way to achieve same result which I am achieving through my code now.
My requirement is to read PDF source files from a directory one file at a time. Then for that particular PDF file convert each page to an individual .jpg image by adding blank space in top of page so that there is enough space in top where some other process can put a bar code (Please note here my process need to leave blank space in top only. Bar code needs to be put in blank space by some other process.). Also, please note here source PDF files which we can receive will be very diverse in nature e.g. some may have portrait orientation, some may be landscape, some may be 8.5 x 11 inch letter page size, some may have page size weird as 5.9 x 15.9 inch, some may be properly created, some may be a PDF created by scanning some documents, some may have images too apart from text and etc. In short our source PDFs are varied in nature.
Currently the code I have written has below steps using APIs provided in Aspose.Pdf for Java JAR:
1. Convert an individual PDF page to a .jpg image.
2. Create a new PDF with defined page size 8.5 x 11 in (Letter Size). Set the margin of page in such a way that we are leaving blank space on top. Now add the image created in step 1 to this page and save new PDF. We understand based on original page size there are chances that content of original PDF page will be scaled as the image created from it in step 1 has to fit in the new page size which has some blank space on top too. We are fine with scaling. Using the defined page size will help ensure that all converted documents to be of same size and so absolute blank space left in top (using page margin) for bar code will be uniform for all converted documents.
3. Convert the newly created PDF in step 2 to a .jpg image.
The .jpg created in step 3 is our final converted document.
I am also sharing my code here as file attachment to this post. Please have a look at it. Please let me know if you have any suggestion to improve this approach further using your APIs. As there may be some better APIs available in your package/JAR which I am not using and that may be better way to achieve same result.
Please let me know if you need any additional information. Looking forward for your response. Thanks for your help!
Sumit Jha
CVS Health