import PyPDF2/80382945dab298bc311181b31af0e8fa.js'>
def add_watermark(input_pdf, output_pdf, watermark_text):
# Open the PDF files
with open(input_pdf, 'rb') as file_in, open(output_pdf, 'wb') as file_out:
# Create PDF reader and writer objects
pdf_reader = PyPDF2.PdfFileReader(file_in)
pdf_writer = PyPDF2.PdfFileWriter()
google.com, pub-0000000000000000, DIRECT, f08c47fec0942fa0
# Create a watermark object
watermark = PyPDF2.PdfFileReader(watermark_text)
# Iterate through each page of the input PDF
for page_num in range(pdf_reader.numPages):
# Get the current page
page = pdf_reader.getPage(page_num)
# Merge the page with the watermark
page.merge_page(watermark.getPage(0))
# Add the merged page to the PDF writer
pdf_writer.addPage(page)
# Write the result to the output PDF file
pdf_writer.write(file_out)
if __name__ == "__main__":
# Specify input and output PDF files
input_pdf_path = "input.pdf"
output_pdf_path = "output.pdf"
# Specify watermark text (you can also use a PDF file as a watermark)
watermark_text_path = "watermark.pdf"
# Add watermark to the PDF
add_watermark(input_pdf_path, output_pdf_path, watermark_text_path)
About this:
Watermarking a PDF involves adding a visible or invisible mark to the document to indicate its status, ownership, or other information. Watermarks are often used to protect intellectual property, such as logos, copyright information, or confidential labels. Here's how watermarking typically works in the context of PDFs:
Choose a Watermark:
Text Watermark: This can include text such as "Confidential," "Draft," or any custom message.
Image Watermark: This involves overlaying an image, logo, or pattern onto the PDF.
Selecting a Tool:
Many software tools, both online and offline, offer features for adding watermarks to PDFs. Some popular options include Adobe Acrobat, PDF-XChange Editor, and various online PDF editors.
Open the PDF:
Launch the chosen tool and open the PDF file you want to watermark.
Add Text or Image Watermark:
For text watermarks, you typically provide the text content, font style, size, color, and positioning.
For image watermarks, you choose the image file, adjust transparency, and position it on the PDF.
Adjust Watermark Settings:
Configure additional settings such as opacity, rotation, scale, and placement on the page. Some tools allow you to choose whether the watermark will appear on every page or only on specific pages.
Preview the Watermark:
Most tools provide a preview option to see how the watermark will appear on the document before applying it.
Apply the Watermark:
Once satisfied with the settings, apply the watermark to the PDF. This process may involve clicking a specific button or choosing an option in the menu.
Save or Export the PDF:
Save the PDF with the applied watermark. Some tools may also allow you to export the document in a different format or overwrite the existing file.
Invisible Watermarks:
Some tools offer the ability to add invisible watermarks, which are not visible to the naked eye but can be detected using specialized software. These invisible watermarks often include information about the document or its owner and are used for tracking and verification purposes.
It's essential to note that the specific steps may vary slightly depending on the software or online service you are using. Always refer to the documentation of the tool you choose for detailed instructions on watermarking PDFs.
Comments