List of usage examples for com.itextpdf.text.pdf BaseFont CP1257
String CP1257
To view the source code for com.itextpdf.text.pdf BaseFont CP1257.
Click Source Link
From source file:pdf.alterLetter.java
public static void main(String args[]) { try {//from w w w . j a va2s. c om PdfReader pdfReader; pdfReader = new PdfReader("C:\\Users\\asus\\Desktop\\web\\Appointment letter.pdf"); //pdfReader = new PdfReader("C:\\Users\\asus\\Desktop\\TFMsystem\\Appointment letter.pdf"); //Create PdfStamper instance. PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream( "C:\\Users\\asus\\Desktop\\TFMsystem\\web\\Modified appointment letter.pdf")); //new FileOutputStream("C:\\Users\\asus\\Desktop\\TFMsystem\\Modified appointment letter.pdf")); //Create BaseFont instance. BaseFont baseFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1257, BaseFont.NOT_EMBEDDED); //Get the number of pages in pdf. int pages = pdfReader.getNumberOfPages(); //Iterate the pdf through pages. for (int i = 1; i <= pages; i++) { //Contain the pdf data. PdfContentByte pageContentByte = pdfStamper.getOverContent(i); pageContentByte.beginText(); //Set text font and size. pageContentByte.setFontAndSize(baseFont, 12); //Write text pageContentByte.setTextMatrix(120, 706); pageContentByte.showText("[no rujukan(enter by admin/opai)]"); pageContentByte.setTextMatrix(500, 706); pageContentByte.showText("[current date]"); //address pageContentByte.setTextMatrix(46, 641); pageContentByte.showText("[name]"); pageContentByte.setTextMatrix(46, 629); pageContentByte.showText("[position]"); pageContentByte.setTextMatrix(46, 617); pageContentByte.showText("[department]"); pageContentByte.setTextMatrix(155, 493); pageContentByte.showText("[status(penyelaras/ahli),taskforce name]"); pageContentByte.setTextMatrix(178, 433); pageContentByte.showText("[start date]"); pageContentByte.setTextMatrix(290, 433); pageContentByte.showText("[end date] ."); pageContentByte.setTextMatrix(46, 248); pageContentByte.showText("[name]"); pageContentByte.setTextMatrix(46, 236); pageContentByte.showText("[post]"); pageContentByte.setTextMatrix(46, 224); pageContentByte.showText("[faculty]"); pageContentByte.setTextMatrix(46, 212); pageContentByte.showText("[email]"); pageContentByte.endText(); } //Close the pdfStamper. pdfStamper.close(); System.out.println("PDF modified successfully."); } catch (Exception e) { e.printStackTrace(); } }
From source file:pdf.letter.java
public boolean AlterLetter(String rujukan, String name, String position, String department, String gStatus, String sDate, String eDate, String taskName, String postHolderName, String postHolderEmail, String postName) {// w w w . jav a 2 s. com DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Date today = Calendar.getInstance().getTime(); String currDate = df.format(today); try { PdfReader pdfReader; pdfReader = new PdfReader("C:\\Users\\on\\Desktop\\AD\\TFMsystem\\web\\Appointment letter.pdf"); //C:\\Users\\on\\Desktop\\AD\\TFMsystem\\web\\Appointment letter.pdf //Create PdfStamper instance. PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream( "C:\\Users\\on\\Desktop\\AD\\TFMsystem\\web\\Modified appointment letter.pdf")); //C:\\Users\\on\\Desktop\\AD\\TFMsystem\\web\\Modified Appointment letter.pdf //Create BaseFont instance. BaseFont baseFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1257, BaseFont.NOT_EMBEDDED); //Get the number of pages in pdf. int pages = pdfReader.getNumberOfPages(); //Iterate the pdf through pages. for (int i = 1; i <= pages; i++) { //Contain the pdf data. PdfContentByte pageContentByte = pdfStamper.getOverContent(i); pageContentByte.beginText(); //Set text font and size. pageContentByte.setFontAndSize(baseFont, 11); //Write text pageContentByte.setTextMatrix(120, 706); pageContentByte.showText(rujukan); pageContentByte.setTextMatrix(500, 706); pageContentByte.showText(currDate); //address pageContentByte.setTextMatrix(46, 641); pageContentByte.showText(name); pageContentByte.setTextMatrix(46, 629); pageContentByte.showText(position); pageContentByte.setTextMatrix(46, 617); pageContentByte.showText(department); String gstatus; pageContentByte.setTextMatrix(157, 493); String changeCase = gStatus + ", " + taskName; pageContentByte.showText(changeCase.toUpperCase()); pageContentByte.setTextMatrix(250, 444); pageContentByte.showText(gStatus + " " + taskName + " ."); pageContentByte.setTextMatrix(180, 432); pageContentByte.showText(sDate); pageContentByte.setTextMatrix(290, 432); pageContentByte.showText(eDate + " ."); pageContentByte.setTextMatrix(46, 248); pageContentByte.showText(postHolderName); pageContentByte.setTextMatrix(46, 236); pageContentByte.showText(postName); pageContentByte.setTextMatrix(46, 224); pageContentByte.showText("Fakulti Komputeran"); pageContentByte.setTextMatrix(46, 212); pageContentByte.showText(postHolderEmail); pageContentByte.endText(); } //Close the pdfStamper. pdfStamper.close(); System.out.println("PDF modified successfully."); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:storehausimport.SaveToPdf.java
public boolean save(String inputFilePath, String outputFilePath) throws Exception { if (outputFilePath.isEmpty()) { throw new Exception("Trkst parametrs outputFilePath"); }/*from w w w .ja va2s . c om*/ if (inputFilePath.isEmpty()) { throw new Exception("Trkst parametrs inputFilePath"); } File inputFile = new File(inputFilePath); Document pdfDoc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(pdfDoc, new FileOutputStream(outputFilePath)); pdfDoc.open(); pdfDoc.setMarginMirroring(true); pdfDoc.setMargins(36, 72, 108, 180); pdfDoc.topMargin(); BaseFont helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1257, BaseFont.NOT_EMBEDDED); Font normal_font = new Font(helvetica, 10, Font.NORMAL); Font bold_font = new Font(); bold_font.setStyle(Font.BOLD); bold_font.setSize(10); pdfDoc.add(new Paragraph("\n")); if (inputFile.exists()) { iStream = new FileInputStream(inputFile); in = new DataInputStream(iStream); is = new InputStreamReader(in); br = new BufferedReader(is); String strLine; while ((strLine = br.readLine()) != null) { Paragraph para = new Paragraph(strLine + "\n", normal_font); para.setAlignment(Element.ALIGN_LEFT); pdfDoc.add(para); } } else { pdfDoc.close(); throw new Exception("Trkst parametrs inputFilePath"); } pdfDoc.close(); } catch (Exception ex) { throw new Exception(ex); } return true; }