RSS

Create PDF Using Java

04 Oct

دلوقتي هجرب حاجه جديد وهيا ازاي اعمل

Create PDF Using Java

أول لازم ننزل المكتبه دي عشان دي هستخدمها عمل البرنامج

واسمها

iText Library

نبدأ البرنامج …

First add iText jar file to program library

package IText;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
public class FirstPdf{
        private static String File ="D://FirstPDFpdf";
        public static void main(String args[]){
                try{
                        Document document = new Document();
                        PdfWriter.getInstance(document,new FileOutPutStream(File));
                        document.open();
                        pdfMetaDate(document);
                        pdfTitlePage(document);
                        document.close();
                    } catch(Exception ex){
                       ex.printStackTrace();
                    }
        }
        private static void pdfMetaData(Document document){
                document.addTitle("My First PDF");
                document.addSubject("I Use iText");
                document.addKeywords("Java , PDF , iText");
                document.addAuthor("AhmedSa3d");
                document.addCreator("AhmedSa3d");
                document.addTitle("My First PDF");
                document.addSubject("I Use iText");
                document.addKeywords("Java , PDF , iText");
                document.addAuthor("AhmedSa3d");
                document.addCreator("AhmedSa3d");
        }
        private static void pdfTitlePage(Document document){
                try{
                        Paragraph paragraph = new Paragraph();
                        addEmptyLine(paragraph, 1);
                        paragraph.add(new Paragraph("This Is My First PDF "));
                        addEmptyLine(paragraph, 1);
                        paragraph.add(new Paragraph("My Name Is Ahmed Saad mansour"));
                        document.add(paragraph);
                } catch(Exception ex){
                       ex.printStackTrace();
                }
        }
        private static void addEmptyLine(Paragraph paragraph, int number){
                for(int i = 0 ; i < number ; i++){
                        paragraph.add(new Paragraph(" "));
                }
        }
}

 

طبعا لسه في حاجات كتير جدا جوه الليبراري دي اقدر استخدمها

ودا هنجربه في موضوع تاني ان شاء الله

 
Leave a comment

Posted by on October 4, 2010 in Java Technology

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: