Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.pdf.kit
Class PdfFileStamp

java.lang.Object
  extended bycom.aspose.pdf.kit.PdfFileStamp

public class PdfFileStamp
extends java.lang.Object

Represents a class for adding watermark or logo at (x,y) on each page of Pdf file. The logo is a string of characters.


Constructor Summary
PdfFileStamp(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Creates a PdfFileStamp object instance.
PdfFileStamp(java.lang.String inputFile, java.lang.String outputFile)
          Creates a PdfFileStamp object instance.
 
Method Summary
 void addLogomark(FormattedText logo, float x, float y)
          Adds a logo on each page of the Pdf fila at (x,y).
 void addPageNumber(FormattedText formattedText)
          Adds page number with specified format in each pages of the pdf file and save it.
 void addPageNumber(java.lang.String formatString)
          Adds page number in each pages of the pdf file and save it.
 void addStamp(Stamp stamp)
          Adds stamp at the specified pages of pdf file.The stamp can be added as watermark,logo and background according to the isBackground function of stamp.
 void addWatermark(java.lang.String imageFile, float x, float y)
          Adds a watermark on each page of the Pdf file at (x,y).
 void close()
          Closes the PdfFileStamp object,writes the watermark and logo to the Pdf document.
 float getPageHeight()
          Gets the page's height of pdf file which you want to be stamped.
 float getPageWidth()
          Gets the page's width of pdf file which you want to be stamped.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfFileStamp

public PdfFileStamp(java.lang.String inputFile,
                    java.lang.String outputFile)
             throws java.io.IOException,
                    PdfKitException
Creates a PdfFileStamp object instance.

Parameters:
inputFile - String Source input Pdf file.
outputFile - String Output Pdf file.
Throws:
java.io.IOException
PdfKitException

PdfFileStamp

public PdfFileStamp(java.io.InputStream inputStream,
                    java.io.OutputStream outputStream)
             throws java.io.IOException,
                    PdfKitException
Creates a PdfFileStamp object instance.

Parameters:
inputStream - InputStream Source input Pdf Stream.
outputStream - OutputStream Output Pdf Stream.
Throws:
java.io.IOException
PdfKitException
Method Detail

addWatermark

public void addWatermark(java.lang.String imageFile,
                         float x,
                         float y)
                  throws java.io.IOException,
                         com.aspose.pdf.kit.BadElementException,
                         java.net.MalformedURLException
Adds a watermark on each page of the Pdf file at (x,y). Use this method before 2006/11/26. Aspose has upgraded to a new method addStamp((Stamp stamp)). Please use new method after that date.

Parameters:
imageFile - String The path of image, the types supported are JPG,PNG,GIF.
x - float Horizon position.
y - float Vertical position.
Throws:
java.io.IOException
BadElementException
java.net.MalformedURLException

addLogomark

public void addLogomark(FormattedText logo,
                        float x,
                        float y)
Adds a logo on each page of the Pdf fila at (x,y). Use this method before 2006/11/26. Aspose has upgraded to a new method addStamp((Stamp stamp)). Please use new method after that date.

Parameters:
logo - FormattedText The logo with font,encoding and size format.
x - float The X position.
y - float The Y position.

close

public void close()
           throws PdfKitException,
                  java.io.IOException
Closes the PdfFileStamp object,writes the watermark and logo to the Pdf document.

 [SampleCode]
 String inFile = "example2.pdf";
 String outFile = "kitOut.pdf";
 PdfFileStamp fileStamp = new PdfFileStamp(inFile, outFile);
 FormattedText logo1 = new FormattedText("Evaluation Only. Created with Aspose.Pdf.Kit. Copyright 2002-2005 Aspose Pty Ltd",new FontColor(0, 20, 180),
 FontStyle.TimesRoman,EncodingType.Winansi, false, 12);
 FormattedText logo2 = new FormattedText("Aspose.Pdf.Kit",new Color(10, 30, 100),FontStyle.HelveticaOblique,
 EncodingType.Winansi, false, 20);
 fileStamp.addLogomark(logo1, 20, 50);
 fileStamp.addLogomark(logo2, 20, 70);
 fileStamp.addWatermark("imgLogoPDFKit.gif", 100,100);
 fileStamp.close();
 

Throws:
PdfKitException
java.io.IOException

addStamp

public void addStamp(Stamp stamp)
Adds stamp at the specified pages of pdf file.The stamp can be added as watermark,logo and background according to the isBackground function of stamp.

 [SampleCode]
 String path = "./examples/resources/";
 String inFile = path + "text.pdf";
 String outFile = path + "stamp2.pdf";
 PdfFileStamp fileStamp = new PdfFileStamp(inFile, outFile);
 
 Stamp logoStamp = new Stamp();
 logoStamp.bindLogo(new FormattedText("Hello World!", 
 	new Color(180, 0, 0), FontStyle.TimesRoman, EncodingType.Winansi, false, 30));
 logoStamp.setRotation(45);
 
 Stamp watermarkStamp = new Stamp();
 watermarkStamp.bindImage(path + "imgLogoPDFKit.gif");
 logoStamp.setOrigin(100, 50);
 logoStamp.setRotation(15);
 
 Stamp backgroundStamp = new Stamp();
 backgroundStamp.bindImage(path + "butterfly.jpg");
 backgroundStamp.setImageSize(100,100);
 backgroundStamp.setOrigin(200,200);
 backgroundStamp.isBackgroud(true);
 
 Stamp pdfFileStamp = new Stamp();
 pdfFileStamp.bindPdf(path + "Online.pdf", 1);
 pdfFileStamp.isBackground(true);
 pdfFileStamp.setOpacity(0.5f);
 
 fileStamp.addStamp(logoStamp);
 fileStamp.addStamp(watermarkStamp);
 fileStamp.addStamp(backgroundStamp);
 fileStamp.addStamp(pdfFileStamp);
 fileStamp.close();
 

Parameters:
stamp - Stamp content.

addPageNumber

public void addPageNumber(java.lang.String formatString)
Adds page number in each pages of the pdf file and save it.

 [SampleCode]
 String path = "./examples/resources/";
 String inFile = path + "example2.pdf";
 String outFile = path + "example2withpagenumber.pdf";
 PdfFileStamp fileStamp = new PdfFileStamp(inFile, outFile);
 //add page number
 fileStamp.addPageNumber("Page # .");
 fileStamp.close(); 
 

Parameters:
formatString - the format of page number string, must contain one and only one "#", such as "Page #". The "#" string will be replaced with page number.

addPageNumber

public void addPageNumber(FormattedText formattedText)
Adds page number with specified format in each pages of the pdf file and save it.

 [SampleCode]
 String path = "./examples/resources/";
 String inFile = path + "example2.pdf";
 String outFile = path + "example2withpagenumber.pdf";
 PdfFileStamp fileStamp = new PdfFileStamp(inFile, outFile);
 //add page number
 FormattedText ft = new FormattedText("Page # .", new Color(0,0,100),
 FontStyle.CourierBold,EncodingType.Winansi, false, 10);
 fileStamp.addPageNumber(ft);
 fileStamp.close(); 
 

Parameters:
formattedText - a FormattedText object which contain the format of page number string, must contain one and only one "#", such as "Page #". The "#" string will be replaced with page number.

getPageHeight

public float getPageHeight()
Gets the page's height of pdf file which you want to be stamped.

Returns:
Page height.

getPageWidth

public float getPageWidth()
Gets the page's width of pdf file which you want to be stamped.

Returns:
Page width.