-
Notifications
You must be signed in to change notification settings - Fork 41
Added new kb article add-watermark-pdf-radpdfprocessing #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dessyordanova
merged 4 commits into
master
from
new-kb-add-watermark-pdf-radpdfprocessing-148c1282b51b44c38dd649ca2925a3e3
Jul 23, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- | ||
| title: Adding a Watermark to PDF Files Using RadPdfProcessing | ||
| description: Learn how to add custom watermarks to PDF documents using the RadPdfProcessing library. | ||
| type: how-to | ||
| page_title: How to Add Watermarks to PDF Documents with RadPdfProcessing | ||
| slug: add-watermark-pdf-radpdfprocessing | ||
| tags: radpdfprocessing, document processing, watermark, pdf, text watermark | ||
| res_type: kb | ||
| ticketid: 1653970 | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| | Version | Product | Author | | ||
| | --- | --- | ---- | | ||
| | 2024.2.426| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| | ||
|
|
||
| ## Description | ||
|
|
||
| This KB article demonstrates how to add a text watermark across all pages of a PDF document using RadPdfProcessing. | ||
|
|
||
| ## Solution | ||
|
|
||
| To add a watermark to PDF pages using RadPdfProcessing, follow these steps: | ||
|
|
||
| 1. Import the PDF document using [PdfFormatProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-pdfformatprovider%}). | ||
| 2. Iterate through each page of the document. | ||
| 3. Use [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%}) to add a watermark text block to each page. | ||
| 4. Customize the watermark's text properties, color, and position. | ||
| 5. [Export](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/pdf/pdfformatprovider/pdfformatprovider#export) the document with watermarks back to a PDF file. | ||
|
|
||
| Here is a complete code snippet demonstrating these steps: | ||
|
|
||
| ```csharp | ||
| static void Main(string[] args) | ||
| { | ||
| string fileName = "sample.pdf"; | ||
| PdfFormatProvider provider = new PdfFormatProvider(); | ||
| RadFixedDocument document = provider.Import(File.ReadAllBytes(fileName)); | ||
|
|
||
| foreach (RadFixedPage page in document.Pages) | ||
| { | ||
| AddWatermarkText(page, "Watermark text!", 100); | ||
| } | ||
|
|
||
| string exportFileName = "testWatermarks.pdf"; | ||
| File.Delete(exportFileName); | ||
|
|
||
| File.WriteAllBytes(exportFileName, new PdfFormatProvider().Export(document)); | ||
| ProcessStartInfo psi = new ProcessStartInfo() | ||
| { | ||
| FileName = exportFileName, | ||
| UseShellExecute = true | ||
| }; | ||
| Process.Start(psi); | ||
| } | ||
|
|
||
| private static void AddWatermarkText(RadFixedPage page, string text, byte transparency) | ||
| { | ||
| FixedContentEditor editor = new FixedContentEditor(page); | ||
|
|
||
| Block block = new Block(); | ||
| block.TextProperties.FontSize = 80; | ||
| block.TextProperties.TrySetFont(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold); | ||
| block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center; | ||
| block.GraphicProperties.FillColor = new RgbColor(transparency, 255, 0, 0); | ||
| block.InsertText(text); | ||
|
|
||
| double angle = -45; | ||
| editor.Position.Rotate(angle); | ||
| editor.Position.Translate(0, page.Size.Width); | ||
| editor.DrawBlock(block, new Size(page.Size.Width / Math.Abs(Math.Sin(angle)), double.MaxValue)); | ||
| } | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| ## See Also | ||
|
|
||
| - [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%}) | ||
| - [SDK Example: Add Watermark](https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/AddWatermark/Program.cs) | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.