Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, May 11, 2017 3:13:41 PM(UTC)

Aaron  
Aaron

Groups: Registered, Tech Support, Administrators
Posts: 71

Was thanked: 4 time(s) in 3 post(s)

Attached is a small sample application developed in C# with .NET 4.5.2 using Visual Studio 2017 which demonstrates how you could use the LEADTOOLS Bates Stamp functionalities to add watermarks to any documents you may have. The sample application assumes you have the LEADTOOLS SDK installed and uses the default evaluation license and key files (you may need to change these to point to your license and key files):

Code:
RasterSupport.SetLicense(@"C:\LEADTOOLS 19\Common\License\LEADTOOLS.LIC", System.IO.File.ReadAllText(@"C:\LEADTOOLS 19\Common\License\LEADTOOLS.LIC.key"));


The sample application uses the RasterCodecs class to load in the pages of the input document into memory, then uses the AnnBatesStamp class to load in the watermark you wish to apply and uses the AnnBatesStampComposer to render the watermark on each page of the document. The application then saves each modified page to disk creating a new document which contains the watermark:

Before and After

Here is the source code showing the full process:

Code:

string inputFile = @"..\..\Leadtools.pdf";
string watermarkFile = @"..\..\watermark.png";
string outputFile = @"..\..\output.pdf";

using (RasterCodecs codecs = new RasterCodecs())
{
   CodecsImageInfo info = codecs.GetInformation(inputFile, true);
   for (int i = 1; i <= info.TotalPages; i++)
   {
      using (RasterImage image = codecs.Load(inputFile, i))
      {
         // Create AnnBatesStampComposer instance and add the created Bates stamp to it
         using (AnnBatesStampComposer batesStampComposer = new AnnBatesStampComposer())
         {
            //Set the rendering engine
            AnnBatesStampComposer.RenderingEngine = new AnnWinFormsRenderingEngine();
            //Create Bates stamp container
            AnnContainer batesStampContainer = new AnnContainer();
            // Map the resolutions of the AnnContainer to match the image
            batesStampContainer.Mapper.MapResolutions(image.XResolution, image.YResolution, image.XResolution, image.YResolution);
            // Set the size of the AnnContainer based on the size of the image
            batesStampContainer.Size = batesStampContainer.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(image.Width, image.Height));

            // Create AnnBatesStamp and set its properties
            using (AnnBatesStamp batesStamp = new AnnBatesStamp())
            {
               batesStamp.HorizontalAlignment = AnnHorizontalAlignment.Left;
               batesStamp.VerticalAlignment = AnnVerticalAlignment.Top;
               batesStamp.Logo.Opacity = 0.5;
               batesStamp.Logo.Angle = -45;
               batesStamp.Logo.StretchLogo = true;
               batesStamp.Logo.Picture = new AnnPicture(watermarkFile);
               // Add the AnnBatesStamp to the collection
               batesStampComposer.Stamps.Add(batesStamp);
               // Add the AnnContainer to the collection
               batesStampComposer.TargetContainers.Add(batesStampContainer);

               // Render the AnnContainer on the image
               AnnBatesStampComposer.RenderingEngine.RenderOnImage(batesStampContainer, image);
            }
         }
         // Save the resulting RasterImage which contains the newly created watermark
         codecs.Save(image, outputFile, RasterImageFormat.RasPdf, 0, 1, -1, 1, CodecsSavePageMode.Append);
      }
   }
}

File Attachment(s):
CSBatesStamps.zip (117kb) downloaded 275 time(s).

Edited by moderator Tuesday, December 17, 2019 2:50:45 PM(UTC)  | Reason: Fixed image link

Aaron Brasington
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, September 28, 2018 9:22:24 AM(UTC)
Christopher

Groups: Registered, Tech Support, Administrators
Posts: 89

Was thanked: 4 time(s) in 4 post(s)

The attached project has been updated to work with the Latest LEADTOOLS v20 SDK.
Several of the annotation Dlls from v19 were deprecated or changed in v20.
This is reflected in this latest version of the project.

File Attachment(s):
CSBatesStamps.zip (345kb) downloaded 190 time(s).
Chris Thompson
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.078 seconds.