java read encoded data from database and create pdf file - java

I am reading encoded data from database. When I decode data I get something like
%PDF-1.3
23 Obj
xref
10000000 123n
.
.
.
.
%EOF
I am guessing it's a metadata of PDF file with data. My question is how do I create PDF file out of this with readable data only.
Thanks in advance.

First you need to know what the data in DB represents. I would suggest to connect to the database using a general client. For example, for Oracle - SqlDeveloper, for MS Sql Server - Visual Sql Server, etc
Display the table which has a column of type long, clob or blob and try to save it to a file. Name the file with an extension .pdf. Try to open the saved file and see if it gets open correctly by a pdf reader.
If this is a case, saving it from Java is trivial. For example: http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11120

Related

How to save image from android to java server

I need to upload an image from android app to a java server. I tried to define the type image like a string and to convert the image, that the user can upload from documents or take with camera, into a base64 string. But when i convert this image in base64 and put this inside a string to save it in database, server give me a 500 internal sever error and this error message:
"com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'image' at row 1"
The Db is in Mysql and i use this from java server.
So, how can I save a base64 image to my server? Can I use a different type?
Thank you!
you can use volley library. for more details these links are useful
first_link and second_link

Store base64 encoded string in HBase

I have a very specific requirement of storing PDF data in Hbase columns. The source of Data is Mongo DB, from where the base64 encoded data is read and I will need to bulk upload it to Hbase table.
I realized that in base64 encoded string there are a lot of "\n" character which splits the entire string into parts. Not sure if it is because of this, but when I store the string as it is, using a put :
put.add(Bytes.toBytes(ColFamilyName), Bytes.toBytes(columnName), Bytes.toBytes(data.replaceAll("\n","").toString()));
It is storing only the first line from the entire encoded string. Eg :
If the actual content was something like this :
"JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PAovQ3JlYXRvciAoQXBhY2hlIEZPUCBWZXJzaW9uIDEu
" +
"MSkKL1Byb2R1Y2VyIChBcGFjaGUgRk9QIFZlcnNpb24gMS4xKQovQ3JlYXRpb25EYXRlIChEOjIw\n" +
"MTUwODIyMTIxMjM1KzAzJzAwJykKPj4KZW5kb2JqCjUgMCBvYmoKPDwKICAvTiAzCiAgL0xlbmd0\n" +
It is storing only the first line which is :
JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PAovQ3JlYXRvciAoQXBhY2hlIEZPUCBWZXJzaW9uIDEu
in the column. Even after trying to remove the "\n" manually it is the same output.
Could someone please guide me in the right direction here ?
Currently, I am also working on Base64 encoding. As per my understanding, you should try using
org.apache.hadoop.hbase.util.Base64.encodeBytes(byte[] source, int option)
method where DONT_BREAK_LINES can be used as an option.
Please let me know if this works fine.
Managed to solve it. The issue was when reading the Base64 encoded data from MongoDB Source. Read the data from Mongo DB document DBObject as:
jsonObj.get("receiptContent").toString().replaceAll("\n","")
And stored it as such in Hbase. Even from the Hue HBase UI Browser I can see the PDF content now.

How to append data to a existing pdf file using iText Java

Data is dynamically genarated, i want to write(append to the end of file) this data to a pdf file without loosing the previous data.
Please try this :-
Example [http://itextpdf.com/examples/iia.php?id=123 ]
Example [Appending a data in itext in existing pdf ]

Data inserted from excel sheet into mysql is not displayed on JSP

I have uploaded Excel sheet data (office 2007 version) and it is correctly inserted in MYSQL. When I am fetching it on JSP page it is not displayed and I didn't get any error. While data before uploading excel sheet is properly displayed. And when I delete those data coming from Excel sheet, then it is again OK.
How to overcome this problem?
It could be that via Excel you put text in wrong encoding in MySQL. Then Java would throw an Exception if a byte sequence is illegal. This can be the case if Java expects UTF-8, or the database field contains Excel with UTF-16 (byte pairs). To diagnose this, upload an Excel with pure ASCII. If you see that, UTF-8 is guilty.
To repair, ensure that the database/table/field is UTF-8.

Java Read binary record into String

We are storing uploaded text files in a SQL server data. The field type is image.
The file upload and download correctly, what I want to do now is load the actual text content into a String variable directly from the database record.
Can anyone advise on how to do this please?
Depends on how you read the data from the db. If you get a byte array, you could use new String(bytes);
Btw, why don't you use the CLOB datatype (or the equivalent for your server) for the field? This should normally cause the Java driver to return the String directly.

Categories

Resources