PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteUse iText 7’s page and canvas APIs, not raw PDF bytes. Open the source with a PdfReader and destination PdfWriter backed by your streams. For every page, create a PdfCanvas, save the graphics state, apply a PdfExtGState with the opacity you want, draw text or an image, restore the state, and close the PdfDocument. Closing is what finalizes the output stream.
The example below writes a translucent, rotated “CONFIDENTIAL” mark over every page. It uses each page’s real dimensions, so A4, Letter, landscape, and mixed-size documents are handled without hard-coded coordinates.
What the stream-based workflow does
In a server, desktop utility, or function, the PDF may already be in a FileInputStream, HTTP body, database blob, or memory stream. iText’s reader/writer constructor accepts those streams (use the overload provided by the iText 7 version in your project):
- Create
PdfDocumentwithnew PdfReader(inputStream)andnew PdfWriter(outputStream). - Loop from page 1 through
getNumberOfPages(). - Get the page’s
Rectangleand aPdfCanvas. - Call
saveState(), set aPdfExtGState, and add the mark. - Call
restoreState()before moving to the next page. - Call
pdfDoc.close()after the loop.
Do not edit the underlying canvas stream bytes. The PdfCanvas API documentation warns that “Manipulating with underlying stream object of canvas could lead to corruption of it’s data.”
Free tools Windows power users keep installed
One-click scans. No signup required.
Complete Java example: transparent text on every page
This class reads and writes only through streams. Replace the file streams with your application’s streams when integrating it into an upload or API endpoint.
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.io.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfExtGState;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Canvas;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.properties.TextAlignment;
import com.itextpdf.layout.properties.VerticalAlignment;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class WatermarkPdf {
public static void addWatermark(InputStream input, OutputStream output)
throws Exception {
PdfDocument pdfDoc = new PdfDocument(
new PdfReader(input), new PdfWriter(output));
PdfFont font = PdfFontFactory.createFont(StandardFonts.HELVETICA);
PdfExtGState watermarkState = new PdfExtGState()
.setFillOpacity(0.20f);
for (int pageNumber = 1;
pageNumber <= pdfDoc.getNumberOfPages(); pageNumber++) {
PdfPage page = pdfDoc.getPage(pageNumber);
Rectangle size = page.getPageSize();
PdfCanvas canvas = new PdfCanvas(page);
canvas.saveState().setExtGState(watermarkState);
Paragraph mark = new Paragraph("CONFIDENTIAL")
.setFont(font).setFontSize(60);
new Canvas(canvas, pdfDoc, size).showTextAligned(
mark,
size.getWidth() / 2,
size.getHeight() / 2,
TextAlignment.CENTER,
VerticalAlignment.MIDDLE,
(float) Math.toRadians(45));
canvas.restoreState();
}
pdfDoc.close();
}
public static void main(String[] args) throws Exception {
Path source = Paths.get("input.pdf");
Path destination = Paths.get("watermarked.pdf");
try (InputStream in = Files.newInputStream(source);
OutputStream out = Files.newOutputStream(destination)) {
addWatermark(in, out);
}
}
}
The official examples use 0.2f (20% fill opacity) as a setting; it is not a universal “correct” value. Increase it for a faint mark that must survive printing, or decrease it when the page contains dense text, photographs, or an opaque background.
Version-sensitive calls
iText 7 minor versions can expose different showTextAligned overloads and angle conventions. Keep the same sequence but check the API shipped with your dependency if the compiler reports an overload mismatch. Java methods such as saveState, setExtGState, and showTextAligned have corresponding .NET methods SaveState, SetExtGState, and ShowTextAligned.
Put the mark above or below existing page content
A PDF page can contain multiple content streams. A stream added after existing content is rendered on top; one added before it is rendered behind it. This decision matters when the page contains a full-page image or a solid shape.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #2
| Desired result | Placement choice | When to use it |
|---|---|---|
| Visible stamp over text and images | After existing content | Confidentiality labels, review status, or ownership marks that must remain visible |
| Background pattern that never covers text | Before existing content | Decorative logos or a light security pattern |
Constructing new PdfCanvas(page) writes to the page’s current (foreground) stream in the common usage shown above. For explicit ordering, use the PdfCanvas constructor or page content-stream methods documented for your installed version to request a stream before or after the existing streams. Verify the result with a page that has an opaque image: if the mark disappears, it was placed behind that image.
Keep a watermark readable without hiding the page
Opacity and graphics-state isolation
PdfExtGState.setFillOpacity(float) affects subsequent filled text and shapes. Enclose every page’s drawing in saveState() and restoreState(). The pair prevents the watermark’s opacity, transforms, clipping, or color from leaking into other page content. A missing restore can produce rendering bugs that are difficult to diagnose.
Center and rotate using the page itself
Read size.getWidth() and size.getHeight() for every page. Centering at half those values works for mixed page sizes. The sample rotates 45 degrees by passing radians; follow the angle and unit convention of your iText minor version. For a horizontal stamp, pass zero. For a corner label, use coordinates near the page margins rather than the center.
Long text, fonts, and international characters
Helvetica is convenient for the ASCII word “CONFIDENTIAL.” For accented, Cyrillic, Arabic, or CJK text, embed a font file with PdfFontFactory.createFont(path, PdfEncodings.IDENTITY_H) (using the font and encoding supported by your iText version). Test right-to-left scripts and glyph coverage; a missing glyph can render as a box. Reduce font size or wrap the mark when the text is longer than a single line.
Image watermark variant
Use an image for a logo, seal, or scanned stamp. Load the bytes as ImageData, wrap them in the layout Image, and add that image through a Canvas backed by the page’s PdfCanvas. Apply the same PdfExtGState before adding it and restore afterward:
ImageData data = ImageDataFactory.create("stamp.png");
Image stamp = new Image(data).scaleToFit(220, 120);
canvas.saveState().setExtGState(watermarkState);
new Canvas(canvas, pdfDoc, size).add(stamp);
canvas.restoreState();
Position the image with the layout API or a transformation appropriate to your iText version. Keep the image’s intrinsic transparency when the PNG already contains an alpha channel, and use fill opacity when the entire stamp should be subdued.
Stream handling, errors, and recovery
“No such method” or constructor errors
Cause: iText 7 minor versions differ in stream constructors and layout overloads. Fix: open the API documentation for the exact dependency version, then adapt only the constructor or showTextAligned signature. The reader/writer, canvas, graphics-state, and close sequence remains the same.
Output is empty, truncated, or unreadable
Cause: the destination stream was read before iText finalized it, or an exception interrupted processing without closing the document. Fix: call pdfDoc.close() after all pages, and place stream ownership in try-with-resources when your method creates the streams. If your framework owns them, close the document in a finally path and let the framework decide when to close the underlying response stream.
Recommended Free Tools
Rank #4
The watermark is invisible
Cause: it was written before an opaque image, opacity is too low, the text color matches the page, or the mark is outside the page’s coordinate system. Fix: place the stream after existing content, temporarily use full opacity and a contrasting color, and calculate coordinates from getPageSize().
The page becomes unexpectedly opaque or later content changes
Cause: graphics state was not isolated. Fix: ensure every saveState() has exactly one matching restoreState(), including paths that add an image or throw an exception.
Raw-stream edits corrupt the PDF
Cause: direct byte manipulation can break PDF stream lengths, filters, or graphics-state boundaries. Fix: use the documented PdfCanvas and page content-stream APIs instead of editing underlying bytes.
Performance and reliability considerations
- One pass: the loop is linear in page count and adds one mark per page. Reuse the font and
PdfExtGStaterather than recreating them inside the loop. - Memory: stream input and output so large PDFs do not need to be loaded into one application byte array. Ensure the output destination has enough space for the rewritten document.
- Mixed geometry: calculate position and, if necessary, rotation for each page; do not assume every page is the same size or orientation.
- Validation: open the produced file in more than one PDF viewer, inspect pages with photographs and transparency, and test printing if the mark is used for compliance.
- Security: a visual watermark is page content, not encryption or access control. Use PDF permissions and encryption separately when preventing copying or editing is required.
Or skip the browser setup
If what you actually need is a screenshot or PDF capture of a web page rather than a watermark embedded in an existing PDF, ScreenshotNeo provides a single HTTP call. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. Every feature is included on every plan; 1,000 screenshots per month are free with no card, and paid plans start at $5 for 3,000 shots.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesSee the ScreenshotNeo API documentation for all options. A direct call looks like this:
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Create a free ScreenshotNeo account to use the 1,000-shot monthly allowance with no credit card.
Frequently asked questions
Can I watermark only selected pages?
Yes. Replace the 1-to-number-of-pages loop with a set of page numbers or a predicate that selects the pages you want, while retaining the same graphics-state and close sequence.
Does opacity affect an image watermark?
Yes. The PdfExtGState applies to the image drawn through the canvas, so the same state can make a logo or stamp translucent.
Should I use a PDF watermark for access control?
No. A watermark identifies or labels content visually. Combine it with PDF encryption and permissions when you need to restrict opening, copying, or editing.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

