How to append data to a existing pdf file using iText Java - 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 ]

Related

Create an excel worksheet based on a predefined excel template

I have an .xls file which I call it model. Now my probleme is that I want to create over 50 .xls file that have that same format of the model. So properly my question is : how do I create a worksheet (excel file) based on an excel template using java? Is there is any way to do it without copying the style between sheets ??
This example does not use a pre defined template but you can go check out my code and morph it into something worth for you.
https://github.com/ernst223/spread-sheet-exporter
So you can maybe code the style in my class and then use my class for all of your excel files
SpreadSheetExporter spreadSheetExporter = new SpreadSheetExporter(List<Object>, "Filename");
File fileExcel = spreadSheetExporter.getExcel();
as you didn't make any apparent effort before asking i will do the same
excel api

Create a DOCX reading data from Oracle database

I have a student database (Oracle 11G), I need to create a module(separate) which will generate a student's details in a well-formatted word document. When I give the student ID, I need all the info(Kind of a biodata) of the student in a docx file which is very presentable. I'm not sure how to start, I was exploring Python-docx and java DOCX4j. I need suggestion how can I achieve this. Is there any tool I can do this
Your help is highly appreciated
You could extract the data from Oracle into an XML format, then use content control data binding in your Word document to bind elements in the XML.
All you need to do is inject the XML into the docx as a custom xml part, and Word will display the results automatically.
docx4j can help you to the inject the XML. If you don't want to rely on Word to display the results, then you can use docx4j to also apply the bindings.
Or you could try simple variable replacement: https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/VariableReplace.java
If you want a simple way to format your Word document directly from Java, you can try pxDoc.
The screenshot below provide an example of code and document generated from an Authors/Books model: whatever the way you request the data from your database, it is easy to render them in a well formatted document.
simple document generation example
Regarding your use case, you could also generate a document for all students at once. In the context of the screenshot example:
for (author:library.authors) {
var filename = 'c:/MyDocuments/'+author.name+'.docx'
document fileName:filename {
/** Content of my document */
}

java read encoded data from database and create pdf file

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

convert a xls file as pdf without poi or jxl

So I summarize my problem. I would like to convert an xls file to PDF, while using java. .
I find two examples
The first is with Openoffice
import officetools.OfficeFile; // from officetools.jar
FileInputStream fis = new FileInputStream(new File("test.doc"));
FileOutputStream fos = new FileOutputStream(new File("test.pdf"));
OfficeFile f = new OfficeFile(fis,"localhost","8100", false);
f.convert(fos,"pdf");
But unfortunately I have to install it :(
I also find this example, two command line with vb (call pdf creator)
DoCmd.OpenReport "repClient", acViewPreview, "NumClient = 2"
DoCmd.OutputTo acOutputReport, "PDF", "d: \ test.pdf"
is there somthing like that on java !!!!
(Note I used for my first solution (jxl, appach poi) but formatting pdf generated is not like when I do save as PDF with Microsoft Excel)
think you in advance
I think you can stream the data from the excel document using
apache POI
library. You can pass this stream of data in
iText library API.
iText library API definitely has a function which writes stream data into PDF file. With iText, you can be sure of pdf formatting as it is widely used in organizations for PDF generation. Infact many reporting tool also use iText to generate PDF reports.

XML/XSLT trasnsformed data export to excel in Java

I have a JSP in which I want to:
make an HTTP request;
get back the XML response;
transform the response using XSL; and
export the transformed data to excel.
But i do not get the entire data in a single HTTP call. Also I have to use two stylesheets for exporting to Excel. The first is for the first page of records, and the other is for all the other pages.
How can one do this in Java?
Thanks
Or use Apache POI, its a powerful API to read and create MS Office documents in Java.
Could you parse the XML into Java objects, then when you have the complete object list simply write the Excel file using JExcelAPI? I've used this for Excel files and it's very simple & useful.

Categories

Resources