Recently, the project needs to investigate how to add the logo in pdf to differentiate versions. Finally, it is determined to use itext for implementation.
The Code is as follows:
Java code/*** Authory kingviker* Time: 2012-12-12*/Import java. io. FileOutputStream;Import java. io. IOException; www.2cto.comImport com. itextpdf. text. DocumentException;Import com. itextpdf. text. Font;Import com. itextpdf. text. Image;Import com.itext;.text=. BaseFont;I
I have been dealing with pdf for the past two days and summarize the results of these two days. Here you need to note that itext uses itext 1.4, different versions may have different forms of api, may not be compatible, jar: http://cid-f41b44b9285d0b86.office.live.com/browse.aspx/%e5%85%ac%e5%bc%80%e6%96%87%e4%bb%b6%e5%a4%b9/J2EE%e5%ad%a6%e4%b9%a0%e8%b5%84%e6%96%99%e5%85%b1%e4%ba% AB
In the following exampl
1, import the required jar package: Itext-asian-5.2.0.jar Itextpdf-5.5.11.jar.2. New Word document, create template, save file as PDF, open edit with Adobe Acrobat DC, click "Prepare form" on the right and click "Start"3. In the space where you need to insert the data, right click, click "Text Field", drag and drop the text field to the location you want, change the domain name as the variable name you passed in.4. Save the file and put the file in th
A few days ago the project involves the download function of PDF, after a few days of effort has been completed, deliberately will be involved in a summary of the things.The project is related to several jar packages: itextpdf5.5.6,xmlworker5.5.6,itext-asian5.2.0 (the Linux server cannot display the Chinese must this package, Windows Server does not need), these three packages can be fullyMade in Maven repository.Directly on the code:OneString path =s
PageFormat ();Paper pp = new Paper ();Pp. setSize (width, height );Pp. setImageableArea (0, 0, width, height );Pg. setPaper (pp );Prm. print (g2, pg, 0 );G2.dispose ();
ImgTemplate img = new ImgTemplate (template );Document. add (img );} Catch (incluentexception e ){System. err. println (e );} Catch (IOException e ){System. err. println (e );}Document. close ();
}
Keep in mind that you will need the Batik and Xerces libraries in addition to the iTExt
In fact, use a separate project to add those resource files to the project as embeded resource, and then generate a new library, you do not need to modify the original iTextSharp to achieve this (the CIDFont font support solution I introduced earlier, of course, the effect is the same ). The author told me a few days ago that "The fonts can be loaded not only from resources but also from a directory
Path. I'll try to setip some documentation this weekend. ", he probably didn't say this solution.
Related ja bag: Itext-5.0.6.jar,itextasian-1.5.2.jar.
Note: You must modify the package path in the Itextasian-1.5.2.jar with WinRAR or haozip to change the package path to com.itextpdf.text.pdf.fonts. Otherwise, the PDF-times error is generated.
Example code:
Package com.xy6;
Import Java.io.File;
Import Java.io.FileOutputStream;
Import Java.io.OutputStream;
Import Java.util.Date;
Import Com.itextpdf.text.BaseColor;
Import com.itextpdf.text.Document
. AddEntry ("Readme.txt", Readmetext, Encoding.default); Zip. Password="aicoffees.com";//to set a password for a compressed packageZip. encryption = encryptionalgorithm.winzipaes256;//Encryption Methodzip. AddFile (HttpContext.Current.Server.MapPath (imgs[i). ToString ()),"");//here "" I give is empty is compressed when not set folder, if need to take what name only need in "" Inside add on can, here is an overloaded method, ifzip. AddFile (HttpContext.Current.Server.MapPath (imgs[i). ToString (
(). GetBytes ());Xmlworkerhelper.getinstance (). parsexhtml (writer, document, bis,cssis);Document.close (); } /*** Obtain the source code of the website through the website domain URL * *@paramURL *@returnString *@throwsException*/ Public StaticString geturlsource (File URL)throwsException {inputstream instream=Newfileinputstream (URL); //get HTML binary data from an input stream byte[] data = Readinputstream (instream);//converts binary data to byte byte dataString Htmlsource =NewSt
1. jar packages that need to be imported2. Exporting word and downloading is actually two-step.The first step is to export (upload) the data that needs to be exported to the serverThe second step is to download the documents on the server to the local3.The first step. Uploading documents(1) Setting the response information and constructing the upload path(2) Set the font style to create the object that generated the document(3) Wordutils Tool Class(4) Writing the document title(5) The directory
Html2canvas JSHtml1 Div ID = "Divpdf" > 2 Required Area 3 Div >Js12Background using picture Base64 encoding for image conversion1 //2 ///convert Base64 encoding to image3 /// 4 /// Base64 String5 /// The conversion succeeded in returning the image; Failed returns null6 Public stringBase64toimage (stringImgname,stringBase64string,stringpath)7 {8base64string = Base64string.replace ("Data:image/png;base64,","");9MemoryStream ms =NULL;TenS
https://kathleen1974.wordpress.com/category/itext-pdf/In one of my project, we need to give the user a Web UI (a textbox) to enter some text and allow input of superscriptand s Ubscript tag Take your own change as follows:public class Pdfutil {private static Logger Logger = Loggerfactory.getlogger (pdfutil.class);/** handles superscript and small labels for numbers */public Static final String subscript = "public static Font fontgeneral;//general cont
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.