0% found this document useful (0 votes)
17 views

Different Text Background Superscript

The document discusses adding different text effects like background color and superscript to PDF documents using Java code. It also provides examples of adding watermarks and page numbers to existing PDF files programmatically.

Uploaded by

iwc2008007
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Different Text Background Superscript

The document discusses adding different text effects like background color and superscript to PDF documents using Java code. It also provides examples of adding watermarks and page numbers to existing PDF files programmatically.

Uploaded by

iwc2008007
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Different Text Background Superscript

import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class DifferentTextackgroundSuper!cript #
public static void main$String%& arg!' #
Document document ( new Document$';
try #
PdfWriter.get)n!tance$document*new FileOutputStream
$+DifferentTextackgroundSuper!cript.pdf+'';
document.open$';
Chunk c ( new Chunk$+,ackground+';
c.!etText-i!e$.';
c.!etackground$new Color$/xFF* /x//* /x//'';
Paragraph p ( new Paragraph$+The following chunk i!
+';
p.add$c';
document.add$p';
0 catch $1xception ioe' #
S2!tem.err.println$ioe.get3e!!age$'';
0
document.clo!e$';
0
0
Add Watermark Image to an Existing PDF File
import java.io.FileOutputStream;
import java.util.4a!h3ap;
import com.lowagie.text.1lement;
import com.lowagie.text.)mage;
import com.lowagie.text.PageSi5e;
import com.lowagie.text.pdf.a!eFont;
import com.lowagie.text.pdf.PdfContent2te;
import com.lowagie.text.pdf.Pdf-eader;
import com.lowagie.text.pdf.PdfStamper;
public class 6ddWatermark)mageTo6n1xi!tingPDFFile #
public static void main$String%& arg!' #
try #
Pdf-eader reader ( new Pdf-eader$+7ourOwnPDF.pdf+';
int n ( reader.get8um,erOfPage!$';
PdfStamper !tamp ( new PdfStamper$reader* new FileOutputStream$+8ewPDFWithWatermark)mage.pdf+
int i ( /;
PdfContent2te under;
)mage img ( )mage.get)n!tance$+logo.png+';
img.!et6,!olutePo!ition$9//* ://';
while $i ; n' #
i<<;
under ( !tamp.get=nderContent$i';
under.add)mage$img';
0
!tamp.clo!e$';
0
catch $1xception de' #
de.printStackTrace$';
0
0
0

Add Page Numbers to Existing PDF document
import java.io.FileOutputStream;
import com.lowagie.text.1lement;
import com.lowagie.text.pdf.a!eFont;
import com.lowagie.text.pdf.PdfContent2te;
import com.lowagie.text.pdf.Pdf-eader;
import com.lowagie.text.pdf.PdfStamper;
public class 6ddPage8um,er!To1xi!tingPage8um,erPDF #
public static void main$String%& arg!' #
try #
Pdf-eader reader ( new Pdf-eader$+7ourOwnPDF.pdf+';
int n ( reader.get8um,erOfPage!$';
PdfStamper !tamp ( new PdfStamper$reader* new FileOutputStream$+6ddPage8um,er!To1xi!tingPage8um,erPDF.pdf+
int i ( /;
PdfContent2te over;
a!eFont ,f ( a!eFont.createFont$a!eFont.41>?1T)C6* a!eFont.W)868S)* a!eFont.131DD1D';
while $i ; n' #
i<<;
over ( !tamp.getOverContent$i';
over.,eginText$';
over.!etFont6ndSi5e$,f* @.';
over.!etText3atrix$A/* A/';
over.!howText$+page + < i';
over.!etFont6ndSi5e$,f* A9';
over.!howText6ligned$1lement.6>)B8C>1FT* +D=P>)C6T1+* 9A/* :A/* :D';
over.endText$';
0
!tamp.clo!e$';
0 catch $1xception de' #
de.printStackTrace$';
0
0
0

You might also like