Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - PDF generated by itext (1)
PDF generated by itext (1)
PDF generated by itext (2)

Official website: blogs.com/images/adminlogo.gif "); //Add picture 2 to document.add(image2) in the pdf file; //Close the document document.close (); //Close the writer writer.close (); }

Open the picture

85 149 1-20 16 1209 165247 147-746087588 . png

Create a list in PDF

Publilistaticvoidmain (string [] args) throwsdocumentexception, filenotfoundexception {// Create a file documentdocument = newdocument (); //Create writer pdf writer = pdf writer.getinstance (document, new file output stream ("c:/users/h _ _ d/desktop/test5.pdf")); //Open the file document.open (); //Add the content document.add (new paragraph ("HD content is here")); //Add an ordered list list = new list (list. Ordered); ordered list . add(new listitem(" Item one ")); ordered list . add(new listitem(" Item two ")); ordered list . add(new listitem(" Item three ")); document . add(ordered list); //Close the document document.close (); //Close the writer writer.close (); }

opening file

85 149 1-20 16 1209 180029726- 1 1687325 15 . png

To set the style/print format in PDF and output Chinese content, itext-asian.jar must be introduced.

Publilistaticvoidmain (string [] args) throwsdocumentexception, io exception {// Create the file documentdocument = newdocument (); //Create writer pdf writer = pdf writer.getinstance (document, new file output stream ("c:/users/h _ _ d/desktop/test6.pdf")); //Open the file document.open (); //Chinese fonts, which can solve the problem that Chinese cannot be displayed; basefont bfchinese = basefont. createfont ("st song-light", "unigb-ucs2-h", basefont. not _ embedded); //blue font = new font (BF Chinese); blueFont.setColor(BaseColor。 Blue); //Paragraph body Paragraph blue = new paragraph ("Paragraph 1 blue front", blue font); document . add(paragraph blue); //green font = new font (BF Chinese); greenFont.setColor(BaseColor。 Green); //Create a section paragraph chapter title = new paragraph ("paragraph title xxxx", green font); chapter 1 = new chapter(chapter title, 1); chapter 1 . set number depth(0); Paragraph chapter title = new paragraph ("section title", in green font); section section 1 = chapter 1 . add section(section title); Paragraph section content = new paragraph ("partial content", blue font); section 1 . add(section content); //Add a chapter to the article document.add(chapter 1); //Close the document document.close (); //Close the writer writer.close (); }

Open the picture

! [

85 149 1-20 16 1209 180029726- 1 1687325 15 . png

]

85 149 1-20 16 1209 165247 147-746087588 . png

To set a password for the PDF file, you need to import the bcprov-jdk 15on.jar package:

Publilistaticvoidmain (string [] args) throwsdocumentexception, io exception {// Create the file documentdocument = newdocument (); //Create writer pdf writer = pdf writer.getinstance (document, new file output stream ("c:/users/h _ _ d/desktop/test8.pdf")); //user password string userpassword = "123456"; //Owner password string = "hdwriter.setencryption (userpassword.getbytes (), ownerPassword.getBytes (), PdfWriter. ALLOW_PRINTING。 Encryption _ AES _128); //Open the file document.open (); //Add the content document.add (new paragraph ("password! ! ! ! ")); //Close the document document.close (); //Close the writer writer.close (); }

Open the picture

85 149 1-20 16 1209 165247 147-746087588 . png

Set permissions for PDF files

Publilistaticvoidmain (string [] args) throwsdocumentexception, io exception {// Create the file documentdocument = newdocument (); //Create writer pdf writer = pdf writer.getinstance (document, new file output stream ("c:/users/h _ _ d/desktop/test9.pdf")); //Read-only permission writer.setencryption ("). getbytes()," "。 getbytes(),pdfwriter.allow _ printing,pdf writer . encryption _ AES _ 128); //Open the file document.open (); //Add the content document.add (new paragraph ("password! ! ! ! ")); //Close the document document.close (); //Close the writer writer.close (); }

Read/modify existing PDF files.

publistaticvoidmain(string[]args)through document exception,io exception {//Read pdf file pdf reader pdf reader = new pdf reader(" c:/users/h _ _ d/desktop/test 1 . pdf "); //modifier pdfstamper = newpdfstamper (pdf reader, New fileoutputstream ("c:/users/h _ _ d/desktop/test10.pdf")); image image = image . getinstance(" C:/Users/H _ _ D/Desktop/IMG _ 0 109。 JPG”); image.scaleAbsolute(50,50); image.setAbsolutePosition(0,700); for(inti = 1; I< = pdf reader. getnumberofpages (); i++){ PdfContentBytecontent = pdfstamper . getundercontent(I); Content.addImage (picture); } pdfstamper . close(); }

itext? Generate PDF (2)

Link: /p/20d4905383b4