skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

  • Home
 
  • RSS
  • Twitter
Showing posts with label PDF Generation Example. Show all posts
Showing posts with label PDF Generation Example. Show all posts
Monday, October 22, 2012

Jasper report as pdf

Posted by Raju Gupta at 8:00 PM – 0 comments
 
prints the report in pdf format.

//import it in the java file

import net.sf.jasperreports.engine.JasperExportManager;
// a function ehich calls the jasper to generate the report
private String generatePldbbyCC(ParameterReportCriteria prcObject, Map reportMap) throws Exception {
 JasperPrint jasperPrint = null;
 JRFileVirtualizer virtualizer = null;
 String destFileLoc = null;
 File sourceFile = null;
 File destFile = null;
 ESpecDAOController control = new ESpecDAOController();
 // puts the parameters to jasper.
 parameters.put(Constants.COMPETITIVE_CATEGORIES, prcObject.getSelectedCompCategs()); 
 parameters.put("REPORT_CONNECTION", control.getMasterConnection());
 parameters.put(EspecConstants.CURR_TIME, "Exported: " + new SimpleDateFormat("M/d/yyyy 'at' hh:mm:ss a").format(DateUtil.getCurrentDateTime()));

 PropertiesVO templatePath = setJasperpath();

 virtualizer = new JRFileVirtualizer(1, templatePath.getValue());

 parameters.put(SUBREPORT_DIR, templatePath.getValue());

 parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);

 try {

  jasperPrint = JasperFillManager.fillReport(templatePath.getValue() + "/sample.jasper", parameters, control.getMasterConnection());

 } else {
  //get the file with extension as pdf
  destFile = new File(templatePath.getValue(), jasperPrint.getName() + "_" + prcObject.getProcessId() + ".pdf");

 } 

 destFileLoc = destFile.toString();
 //exports the report as pdf.
 JasperExportManager.exportReportToPdfFile(jasperPrint,destFileLoc);


[ Read More ]
Read more...
Monday, September 17, 2012

PDF Utility Code

Posted by Admin at 11:59 AM – 0 comments
 

Through this code one can merge any number f pdf files to single pdf file. Also it can convert string of any size to pdf.



/*
For running this code we need iText.jar which is free and can be downloaded from internet.
*/

public boolean simpleTxtToPDF(String text){
  
//text String can be of any size
   
File targetFolder = new File("C:/pdfFolder1");  // destination folder in which pdf file will be created
String newPdfFileName = "newPpdfFile.pdf";   // final generated pdf file
  
try{
 Document document = new Document(PageSize.A4, 36, 72, 108, 180); // creating empty pdf document
 PdfWriter.getInstance(document,new FileOutputStream(targetFolder+"/"+newPdfFileName));
 document.open();  // opening the document
 document.add(new Paragraph(text));  // adding text
 document.close();  // clsing the document
}
catch(Exception e){
 // print the stack trace to console
 e.printStackTrace();
 }
}
 


public File mergePdfs(File pdfFolder, ArrayList inputPdfFilesName, String outputPdfFile){
  
/* where
 * pdfFolder = its an local folder which contains pdf files to be merged(i.e C:/pdfFolder)
 * inputPdfFilesName = this is an array list which contains names of all the files(like file1.pdf, file2.pdf etc) and these    files must exist in pdfFolder
 * outputPdfFile = this is an output file name i.e outputPdfFile.pdf
 */

File outPutFile = null;
try{
 int pageOffset = 0;
 ArrayList master = new ArrayList();
 int f = 0;
 Document document = null;
 PdfCopy  writer = null;
 int filesCount = inputPdfFilesName.size();
 while (f < filesCount) {                   
  PdfReader reader = new PdfReader(pdfFolder+"\\"+inputPdfFilesName.get(f));
  reader.consolidateNamedDestinations();
  int n = reader.getNumberOfPages();
  List bookmarks = SimpleBookmark.
  getBookmark(reader);
  if (bookmarks != null) {
   if (pageOffset != 0)
    SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
   master.addAll(bookmarks);
  }
  pageOffset += n;
  if (f == 0) {                      
   document = new Document(reader.getPageSizeWithRotation(1));                  
   writer = new PdfCopy(document, new FileOutputStream(pdfFolder + "\\" + outputPdfFile));                       document.open();     
  }
  PdfImportedPage page;
  for (int i = 0; i < n; ) {
   ++i;
   page = writer.getImportedPage(reader, i);
   writer.addPage(page);
  }
  PRAcroForm form = reader.getAcroForm();
  if (form != null)
  writer.copyAcroForm(reader);
  f++;
 }
 if (!master.isEmpty())
  writer.setOutlines(master);
 document.close();
}
catch(Exception e)
{
  e.printStackTrace();
}

outPutFile = new File(pdfFolder + "\\" + outputPdfFile);
return outPutFile;
}




[ Read More ]
Read more...
Friday, September 14, 2012

Use PdfContentByte to generate PDF reports

Posted by Admin at 12:35 PM – 0 comments
 

Its a sample PDF code that helps you generate a PDF document using PdfContentByte. Most of the code changes are self explainatory.


import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.pdf.ColumnText;


public class PharmacyReportGenerator {

 private static final String FILE_EXTENSION = "demographics.pdf";
 static Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
 static Font smallfont = new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL);
 static Font boldFont = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);
 static Font titleFont = new Font(Font.FontFamily.HELVETICA, 16f, Font.BOLD, BaseColor.GRAY);
 static final String ADDRESS_STRING = "Big Pharmacy#85748 - \n\n BIG PHARMACY STORE # 12980 \n\n 200 STREET FAMOUS \n\n SACRAMENTO, CA 17319-0000 \n\n (656)993-2782";
 static final String TITLE_TEXT = "Customer Verification Form";
 static final String SUB_TITLE_TEXT = "Please review the information listed below and update the fields if necessary and return to pharmacy.";
 static final String MULTIPLE_INSURANCES = "PLEASE CHECK THE INSURANCES";
 
 
 
 public void generateDemographicsReport() {
  try {
   Document document = new Document(PageSize.A4.rotate());
   PharmacyReportGenerator report = new PharmacyReportGenerator();
   String fileName = AppParam.BOATEMPDIR()+customerNumber+FILE_EXTENSION;
   PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
   document.open();
   PdfContentByte cb = writer.getDirectContent();
   document.add(report.addTitleTable());
   addHorizontalSeperatorLine(cb, 485f);
   report.addPersonalInformationSection(cb);
   String fullName = DataDefunkifier.formatPersonName(demographicsData.getLName(), demographicsData.getFName(), null);
   report.printTextValueFromSystem(cb, 154, 454, fullName);
   report.printTextValueFromSystem(cb, 154, 440, demographicsData.getAddress1());
   report.printTextValueFromSystem(cb, 155, 424, demographicsData.getAddress2());
   report.printTextValueFromSystem(cb, 155, 410, demographicsData.getState());
   report.printTextValueFromSystem(cb, 155, 394, demographicsData.getZipCode());
   report.printTextValueFromSystem(cb, 155, 380, demographicsData.getPhnNbr());
   report.printTextValueFromSystem(cb, 155, 364, demographicsData.getEmailId());
   report.printTextValueFromSystem(cb, 155, 350, demographicsData.getDOB());
   report.printTextValueFromSystem(cb, 155, 334, demographicsData.getSexCde());
   report.printTextValueFromSystem(cb, 155, 320, demographicsData.getPcpName());
   addHorizontalSeperatorLine(cb, 312f);
   report.addAllergiesSection(cb, demographicsData.getAllergies());
   addHorizontalSeperatorLine(cb, 274f);
   report.addConditionsSection(cb, demographicsData.getConditions());
   addHorizontalSeperatorLine(cb, 238f);
   report.addInsuranceSection(cb);
 //  report.addInsuranceValues(cb, customerNumber);
   addHorizontalSeperatorLine(cb, 162f);
   report.addPreferencesSection(cb, demographicsData.getPreferences());
   addHorizontalSeperatorLine(cb, 123f);
   report.addAdditionalInformationSection(cb);
   addHorizontalSeperatorLine(cb, 80f);
  //        addContent(document);
   document.close();
  } catch (Exception e) {
   AppParam.getLog().error("Exception while creating patient demographics report "+e.getMessage());
  }
 }

 private PdfPTable addTitleTable() throws DocumentException {
  PdfPTable titleTable = new PdfPTable(3);
  float[] columnWidths = {0.2f, 0.5f, 1f};
  titleTable.setWidthPercentage(100);
  titleTable.setWidths(columnWidths);
  PdfPCell cell1 = new PdfPCell();
  disableCellBorders(cell1);
  titleTable.addCell(cell1);
  PdfPCell cell2 = getAddressAsString();
  disableCellBorders(cell2);
  titleTable.addCell(cell2);
  PdfPCell cell3 = getTitleText();
  cell3.setPaddingTop(20f);
  cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
  disableCellBorders(cell3);
  titleTable.addCell(cell3);
  return titleTable;
 }

 
 private PdfPCell getAddressAsString(){
  return (new PdfPCell(new Paragraph(ADDRESS_STRING, font)));
 }
 
 private PdfPCell getTitleText(){
  PdfPCell cell = new PdfPCell();
  PdfPTable subTable = new PdfPTable(1);
  subTable.setWidthPercentage(100);
  PdfPCell subCell1 = new PdfPCell(new Paragraph(TITLE_TEXT, titleFont));
  subCell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
  subCell1.setPaddingBottom(5f);
  disableCellBorders(subCell1);
  PdfPCell subCell2 = new PdfPCell(new Paragraph(SUB_TITLE_TEXT, font));
  subCell2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
  subCell2.setPaddingTop(5f);
  disableCellBorders(subCell2);
  
  subTable.addCell(subCell1);
  subTable.addCell(subCell2);
  cell.addElement(subTable);
  return cell;
 }
 
 private void addPersonalInformationSection(PdfContentByte cb) throws DocumentException, IOException {
  BaseFont bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
  BaseFont bfNormal = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
  cb.beginText();
  cb.moveText(40f, 470f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Personal Information:"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 455f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Name:"));
  cb.endText();
  
  cb.beginText();
  cb.moveText(40f, 440f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Address:"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 425f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Address(continued):"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 410f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("State:"));
  cb.endText();


  cb.beginText();
  cb.moveText(40f, 395f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Zip:"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 380f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Phone Number:"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 365f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Email Address:"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 350f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Date of Birth:"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 335f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Gender:"));
  cb.endText();

  cb.beginText();
  cb.moveText(40f, 320f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText("PCP Name:");
  cb.endText();
  
  
  cb.beginText();
  cb.moveText(400f, 470f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Updated Personal Information:"));
  cb.endText();

  cb.beginText();
  cb.moveText(400f, 455f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Name:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 453f);
  
  cb.beginText();
  cb.moveText(400f, 440f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Address:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 438f);
  
  cb.beginText();
  cb.moveText(400f, 425f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Address(continued):"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 423f);

  cb.beginText();
  cb.moveText(400f, 410f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("State:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 408f);


  cb.beginText();
  cb.moveText(400f, 395f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Zip:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 393f);

  cb.beginText();
  cb.moveText(400f, 380f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Phone Number:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 378f);

  cb.beginText();
  cb.moveText(400f, 365f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Email Address:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 363f);

  cb.beginText();
  cb.moveText(400f, 350f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Date of Birth:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 348f);

  cb.beginText();
  cb.moveText(400f, 335f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Gender:"));
  cb.endText();
  addLineForManualEntry(cb, 520f, 332f);

  cb.beginText();
  cb.moveText(400f, 320f); 
  cb.setFontAndSize(bfNormal, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText("PCP Name:");
  cb.endText();
  addLineForManualEntry(cb, 520f, 318f);
 }
  
 private void addAllergiesSection(PdfContentByte cb, String allergies) throws DocumentException, IOException {
  BaseFont bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
  
  cb.beginText();
  cb.moveText(40f, 296f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Allergies: "));
  cb.endText();

  ColumnText ctMsg = new ColumnText(cb);
  Font textFontMsg = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL);
  float leadingMSG = 12;

  ctMsg.addText(new Chunk(allergies, textFontMsg));
  ctMsg.setSimpleColumn(150, 315, 330, 270, leadingMSG, Element.ALIGN_LEFT);
  ctMsg.go();

  cb.beginText();
  cb.moveText(400f, 296f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Updated Allergies: "));
  cb.endText();
 
  addLineForManualEntry(cb, 520f, 296f);
  addLineForManualEntry(cb, 520f, 282f);
 }
 
 private void addConditionsSection(PdfContentByte cb, String conditions) throws DocumentException, IOException {
  BaseFont bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
  
  cb.beginText();
  cb.moveText(40f, 260f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Conditions: "));
  cb.endText();

  ColumnText ctMsg = new ColumnText(cb);
  Font textFontMsg = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL);
  float leadingMSG = 12;

  ctMsg.addText(new Chunk(conditions, textFontMsg));
  ctMsg.setSimpleColumn(145, 278, 330, 233, leadingMSG, Element.ALIGN_LEFT);
  ctMsg.go();
  
  cb.beginText();
  cb.moveText(400f, 260f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Updated Conditions: "));
  cb.endText();
 
  addLineForManualEntry(cb, 525f, 260f);
  addLineForManualEntry(cb, 525f, 246f);
 }

 private void addInsuranceSection(PdfContentByte cb) throws DocumentException, IOException {
  BaseFont bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
  
  cb.beginText();
  cb.moveText(40f, 224f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Insurance: "));
  cb.endText();

  cb.beginText();
  cb.moveText(400f, 224f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Updated Insurance: "));
  cb.endText();
 
  addLineForManualEntry(cb, 400f, 200f);
  addLineForManualEntry(cb, 400f, 186f);
  addLineForManualEntry(cb, 400f, 172f);
 }

 private void addPreferencesSection(PdfContentByte cb, String preferences) throws DocumentException, IOException {
  BaseFont bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
  
  cb.beginText();
  cb.moveText(40f, 148f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Preferences: "));
  cb.endText();

  ColumnText ctMsg = new ColumnText(cb);
  Font textFontMsg = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL);
  float leadingMSG = 12;

  ctMsg.addText(new Chunk(preferences, textFontMsg));
  ctMsg.setSimpleColumn(145, 165, 330, 126, leadingMSG, Element.ALIGN_LEFT);
  ctMsg.go();

  cb.beginText();
  cb.moveText(400f, 148f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Updated Preferences: "));
  cb.endText();
 
  addLineForManualEntry(cb, 530f, 148f);
  addLineForManualEntry(cb, 530f, 134f);
 }

 private void addAdditionalInformationSection(PdfContentByte cb) throws DocumentException, IOException {
  BaseFont bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
  
  cb.beginText();
  cb.moveText(40f, 110f); 
  cb.setFontAndSize(bfBold, 10f);
  cb.setCharacterSpacing(1.2f);
  cb.showText(DataDefunkifier.toTitleCase("Additional Information: "));
  cb.endText();
 
  addLineForManualEntry(cb, 175f, 104f);
  addLineForManualEntry(cb, 175f, 90f);
 }
 
 private static void addHorizontalSeperatorLine(PdfContentByte cb, float y){
  cb.setLineWidth(1.0f); 
        cb.moveTo(40f, y); 
        cb.lineTo(815, y); 
        cb.stroke(); 
 }
 
 
 public void disableCellBorders(PdfPCell cell){
  cell.disableBorderSide(PdfPCell.TOP);
  cell.disableBorderSide(PdfPCell.BOTTOM);
  cell.disableBorderSide(PdfPCell.LEFT);
  cell.disableBorderSide(PdfPCell.RIGHT);
 }
 
 private void addLineForManualEntry(PdfContentByte cb, float x, float y){
  cb.beginText();
  cb.setLineWidth(1f);
        cb.moveTo(x, y); 
        cb.lineTo(815f, y); 
        cb.stroke(); 
  cb.endText();
 }

 private void printTextValueFromSystem(PdfContentByte cb, float x, float y, String text) throws IOException, DocumentException {
  BaseFont bfNormal = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
  cb.beginText();
  cb.moveText(x, y); 
  cb.setFontAndSize(bfNormal, 8f);
  cb.showText(text);
  cb.endText();
 }

 
 private void addInsuranceValues(PdfContentByte cb, String customerNumber) throws DataModuleException, SystemException {
     CustomerInsurance custIns = new CustomerEnrollmentResolver().getActiveCustomerInsurance(Integer.parseInt(customerNumber));
         if (null != custIns) {
          ArrayList insuranceCards = custIns.getInsuranceCardList();
           int insSize = insuranceCards.size();
           
           
 }
}
}


[ Read More ]
Read more...
Thursday, September 13, 2012

PDF Generation in Java by iText JAR

Posted by Admin at 2:09 PM – 0 comments
 


import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
 
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
 
public class GeneratePDF {
 
    public static void main(String[] args) {
        try {
            OutputStream file = new FileOutputStream(new File("C:\\Test.pdf"));
 
            Document document = new Document();
            PdfWriter.getInstance(document, file);
            document.open();
            document.add(new Paragraph("Hello Sam"));
            document.add(new Paragraph(new Date().toString()));
 
            document.close();
            file.close();
 
        } catch (Exception e) {
 
            e.printStackTrace();
        }
    }
}

[ Read More ]
Read more...
Older Posts
Subscribe to: Posts ( Atom )

List of Java Programs

  • Java Program to check Greater between the Two Number
  • Java Program to find that given number is Palindrome or not
  • Java Program to Demonstrate the Use of Pre and Post Operator
  • Java Program to Reverse the Given Number
  • Java Program to Print Number in the Given Data Type
  • Program to Demonstrate Skipping using Continue
  • Program to find whether entered character is a vowel or Consonant
  • Java Program to Calculate the Sum of Digits of Given Number
  • How to swap two numbers using only two variables
  • Checking the Given Number is Armstrong or Not
  • Average an Array of Values
  • Display ASCII Code Instead of Character
  • Comparison of Two Variable using If
  • Printing Table In java using While Loop
  • Generate Random Number Using Math.Random Function
  • To Find roots of Quadratic Equation
  • Performing Arithmetic Opration on Two Variable
  • Concatenation of Two String in Java
  • Command Line Argument in JAVA
  • Java Hello World Program
  • Calculate Circle Perimeter | Java Program
  • Calculate the Area of Circle | Java Program
  • To Find Whether Given Year is a Leap Year or not
  • Popular
  • Recent
  • Archives

Total Pageviews

Sparkline

Followers

Popular Posts of This Week

  • Java Example that generates General exceptions Like NullPointerException etc.
    Write a program that generates exceptions of type NullPointerException, NegativeArraySizeException, and IndexOutOfBoundsException. Record t...
  • Java program to create a Binary Heap and Perform various operation
    A binary heap (min-heap) is a complete binary tree with elements from a partially ordered set, such that the element at every node is less ...
  • Listing Files and Directory Using Java
    Lists Files and directory present in the system    File dir = new File("directoryName"); String[] children = dir.list(); ...
  • Sort an Integer array with Bucket Sort
    Here is a java program to Sort an Integer array with Bucket Sort class BucketSort { public int[] bucketSort(int[] array) { /...
  • Merge-Sort Algorithm implementation in JAVA
    Merge-Sort Function void MergeSort(int low, int high) // a[low : high] is a global array to be sorted. // Small(P) is true if there...
  • Printing Table In java using While Loop
    Here is a Java Program to Print the Table public class Table { public static void main(String[] args) { int no = Integer.p...
  • Implementation of a basic generic tree, with labels of type T - Data Structure
    // This implements a basic generic tree, with labels of type T, // pointer to the parent node, and a singly linked list of children nodes...
  • Stack implemented as array - Data Structure
    // Stack implemented as array public class ArrayStack<T> { private T[] stack; private int numElements = 0; // points to s...
  • Parse XML file using DOM
    This code snippet explains about the parsing of the xml file using the DOM parser. import java.io.File; import java.io.IOException...
  • Password Encryption Decryption using PBE With MD5 And DES algorithm in java
    In Some applications, at User registration time, we need to Encrypt the password field and then store into the database. After that ...
Powered by Blogger.

Archives

  • ▼  2014 ( 4 )
    • ▼  August ( 4 )
      • Java program to create a Binary Heap and Perform v...
      • Create an Adjacency matrix Graph and perform Add a...
      • To Sort an Interger Array using Shell Sort
      • Sort an Integer array with Bucket Sort
  • ►  2013 ( 6 )
    • ►  August ( 1 )
    • ►  April ( 5 )
  • ►  2012 ( 673 )
    • ►  November ( 9 )
    • ►  October ( 223 )
    • ►  September ( 272 )
    • ►  August ( 2 )
    • ►  June ( 1 )
    • ►  February ( 67 )
    • ►  January ( 99 )
 

Our Blogs

  • Linux Tutorial
  • C Programming Tutorial

Labels

  • Agile Methodology ( 1 )
  • Algorithm ( 3 )
  • AntiSamy ( 1 )
  • Arithmetic Operation ( 1 )
  • Array Example ( 9 )
  • ArrayList Examples ( 11 )
  • Average an Array of Values ( 1 )
  • Barcode Example ( 1 )
  • Basic Java Programs ( 34 )
  • Bing API Example ( 2 )
  • BitSet Example ( 1 )
  • Boolean Example ( 1 )
  • Bouncy Castle API ( 1 )
  • Break Statement ( 2 )
  • BufferedReader Example ( 2 )
  • Calendar Example ( 1 )
  • Chart Generation Example ( 1 )
  • Command Line Argument ( 1 )
  • Comparator Example ( 1 )
  • Concatenation of String ( 1 )
  • Continue Statement ( 1 )
  • Control Structure ( 1 )
  • Copy File Example ( 1 )
  • CRC Example ( 1 )
  • CSV Example ( 6 )
  • Data Structure ( 5 )
  • Date Example ( 2 )
  • Directory Example ( 1 )
  • Do - While Loop Example ( 1 )
  • Domino Database ( 1 )
  • Email Example ( 8 )
  • Encryption Example ( 3 )
  • Excel Example ( 15 )
  • Factorial Example ( 1 )
  • File Upload Example ( 1 )
  • Find Roots of Quadratic Equation ( 1 )
  • FTP Example ( 2 )
  • Graph Examples ( 1 )
  • Greater between Two Numbers ( 1 )
  • GSON Library ( 1 )
  • HashMap Example ( 1 )
  • HashSet Example ( 1 )
  • Hello World Program ( 1 )
  • If Condition ( 2 )
  • Inner Class Example ( 1 )
  • iText Example ( 3 )
  • JAR File ( 1 )
  • JAVA Applet ( 1 )
  • Java Applications ( 1 )
  • Java AWT Example ( 9 )
  • Java Certification ( 1 )
  • Java Class Examples ( 15 )
  • Java Collection Example ( 1 )
  • Java Command Example ( 4 )
  • Java Constructor Examples ( 1 )
  • Java Currency Example ( 1 )
  • Java Database Example ( 3 )
  • Java Date and Time Example ( 3 )
  • Java DateFormat Example ( 3 )
  • Java Examples ( 2 )
  • Java Exception Example ( 5 )
  • Java File Example ( 22 )
  • Java GUI Example ( 1 )
  • Java Image Examle ( 3 )
  • Java Inheritance Example ( 3 )
  • Java Input Output Example ( 1 )
  • Java IO Example ( 3 )
  • Java Jar Example ( 1 )
  • Java JSON Example ( 3 )
  • Java Mail Examples ( 4 )
  • Java Map Example ( 5 )
  • Java MapReduce Example ( 2 )
  • Java MultiThreading Example ( 7 )
  • Java Network Example ( 9 )
  • Java Package ( 1 )
  • Java Programs ( 1 )
  • Java RMI ( 1 )
  • Java Robot Class Examples ( 2 )
  • Java Runtime Example ( 1 )
  • Java Swing Example ( 9 )
  • Java Util Example ( 1 )
  • Java Vector Example ( 4 )
  • Java Voice Example ( 1 )
  • Java Webservice Example ( 1 )
  • Java XML Example ( 3 )
  • Java Zip Class Examples ( 2 )
  • JDBC ( 9 )
  • JDK Version Comparison ( 1 )
  • JFrame Example ( 3 )
  • JOptionPane Dialog Example ( 1 )
  • JPanel Example ( 1 )
  • JSP Example ( 2 )
  • JSTL Example ( 1 )
  • jUnit Example ( 2 )
  • LinkedList Example ( 2 )
  • List Example ( 1 )
  • Long Variable ( 1 )
  • Lottery Nubmer ( 1 )
  • MD5 Hashing Example ( 3 )
  • Memory Management Example ( 1 )
  • Method Override ( 1 )
  • MIDI Sound ( 8 )
  • Module Operator Example ( 2 )
  • Multiplication Table ( 1 )
  • Observer Interface Example ( 1 )
  • Operator Example ( 5 )
  • Pagination ( 1 )
  • Palindrome Number ( 1 )
  • Pass By Reference Example ( 1 )
  • Pass By Value Example ( 1 )
  • PDF File Example ( 3 )
  • PDF Generation Example ( 4 )
  • Pre and Post Operator ( 2 )
  • Prime Number ( 3 )
  • Progress Bar Example ( 1 )
  • Property List Example ( 2 )
  • Random Function ( 7 )
  • Recursion Example ( 2 )
  • Regex Example ( 2 )
  • Remote Host Example ( 2 )
  • Robot Class ( 4 )
  • Searching Example ( 3 )
  • Slideshow ( 1 )
  • Sorting Example ( 7 )
  • SpringLayout Example ( 1 )
  • Stack Example ( 4 )
  • Static Variable ( 1 )
  • StreamTokenizer Example ( 2 )
  • String Example ( 19 )
  • Struts2 Example ( 1 )
  • Sum of Digits ( 1 )
  • Swap Two Numbers ( 1 )
  • Switch Case ( 3 )
  • Tapestry Components ( 1 )
  • Thumbnail Example ( 2 )
  • TimerTask Example ( 2 )
  • To Calculate Volume ( 1 )
  • To Check Armstrong Number ( 1 )
  • Tree Example ( 1 )
  • TreeMap Example ( 1 )
  • TreeSet Example ( 1 )
  • Two Dimensional Array Example ( 1 )
  • UUID ( 1 )
  • Validation Example ( 2 )
  • Variable Casting ( 1 )
  • While Loop ( 1 )
  • XML Parsing ( 7 )
  • XSS Attacks ( 1 )
  • Zip File ( 15 )

Popular Posts

  • Creating Dynamic Macro Enabled Excel by Java
    We can create a dynamic macro enabled excel by java: We need to create a excel sheet template with macro on server. we can copy the...
  • Java program to create a Binary Heap and Perform various operation
    A binary heap (min-heap) is a complete binary tree with elements from a partially ordered set, such that the element at every node is less ...
  • To Sort an Interger Array using Shell Sort
    To Sort an Interger Array using Shell Sort class ShellSort { public static int[] shellSort(int[] array) { int N = array.length; ...
  • Create an Adjacency matrix Graph and perform Add and Remove operation
    import java.util.ArrayList; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; import...
  • Implementation of a basic generic tree, with labels of type T - Data Structure
    // This implements a basic generic tree, with labels of type T, // pointer to the parent node, and a singly linked list of children nodes...
  • Sort an Integer array with Bucket Sort
    Here is a java program to Sort an Integer array with Bucket Sort class BucketSort { public int[] bucketSort(int[] array) { /...
  • Merge-Sort Algorithm implementation in JAVA
    Merge-Sort Function void MergeSort(int low, int high) // a[low : high] is a global array to be sorted. // Small(P) is true if there...
  • Printing Table In java using While Loop
    Here is a Java Program to Print the Table public class Table { public static void main(String[] args) { int no = Integer.p...
  • Java Class to Calculate the Volume of Box
    Here is a Java Class to Calculate the Volume of Box. class Box { double width; double height; double depth; // This is the con...
  • Stack implemented as array - Data Structure
    // Stack implemented as array public class ArrayStack<T> { private T[] stack; private int numElements = 0; // points to s...
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger