How to create Watermarks using Foxit PDF SDK (Objective-C)
A watermark is a type of PDF annotation and is widely used in PDF documents. A watermark is a visible embedded overlay on a document consisting of text, a logo, or a copyright notice. The purpose of a watermark is to brand your work and discourage its unauthorized use. Foxit PDF SDK provides APIs to work with watermarks, allowing applications to create, insert, release and remove watermarks.
Example:
Contents
How to create a text watermark and insert it into the first page
import com.foxit.sdk.common.Font; import com.foxit.sdk.pdf.*; import com.foxit.sdk.pdf.Watermark; import com.foxit.sdk.pdf.WatermarkSettings; import com.foxit.sdk.pdf.WatermarkTextProperties; import com.foxit.sdk.common.Constants; import static com.foxit.sdk.common.Constants.e_AlignmentCenter; import static com.foxit.sdk.common.Font.e_StdIDTimesB; import static com.foxit.sdk.pdf.WatermarkSettings.*; import static com.foxit.sdk.pdf.WatermarkTextProperties.e_FontStyleNormal; ... // Assuming PDFDoc doc has been loaded. WatermarkSettings settings = new WatermarkSettings(); settings.setFlags(e_FlagASPageContents | e_FlagOnTop); settings.setOffset_x(0); settings.setOffset_y(0); settings.setOpacity(90); settings.setPosition(Constants.e_PosTopRight); settings.setRotation(-45.f); settings.setScale_x(1.f); settings.setScale_y(1.f); WatermarkTextProperties text_properties = new WatermarkTextProperties(); text_properties.setAlignment(e_AlignmentCenter); text_properties.setColor(0xF68C21); text_properties.setFont_size(e_FontStyleNormal); text_properties.setLine_space(1); text_properties.setFont_size(12.f); text_properties.setFont(new Font(e_StdIDTimesB)); Watermark watermark = new Watermark(doc, "Foxit PDF SDK\nwww.foxit.com", text_properties, settings); watermark.insertToPage(page); // Save document to file ...
How to create an image watermark and insert it into the first page
import com.foxit.sdk.common.Bitmap; import com.foxit.sdk.common.Image; import com.foxit.sdk.pdf.*; import com.foxit.sdk.pdf.Watermark; import com.foxit.sdk.pdf.WatermarkSettings; import com.foxit.sdk.common.Constants; import static com.foxit.sdk.common.Constants.e_AlignmentCenter; import static com.foxit.sdk.common.Font.e_StdIDTimesB; import static com.foxit.sdk.pdf.WatermarkSettings.*; import static com.foxit.sdk.pdf.WatermarkTextProperties.e_FontStyleNormal; ... // Assuming PDFDoc doc has been loaded. WatermarkSettings settings = new WatermarkSettings(); settings.setFlags(e_FlagASPageContents | e_FlagOnTop); settings.setOffset_x(0.f); settings.setOffset_y(0.f); settings.setOpacity(20); settings.setPosition(Constants.e_PosCenter); settings.setRotation(0.0f); Image image = new Image(image_file); Bitmap bitmap = image.getFrameBitmap(0); settings.setScale_x(page.getWidth() * 0.618f / bitmap.getWidth()); settings.setScale_y(settings.getScale_x()); Watermark watermark = new Watermark(doc, image, 0, settings); watermark.insertToPage(page); // Save document to file. ...
How to remove all watermarks from a page
import com.foxit.sdk.pdf.PDFPage; ... // Assuming PDFPage page has been loaded and parsed. ... page.removeAllWatermarks(); ... // Save document to file ...
Updated on May 8, 2019