Hi,
new user here, so howdy !
So i try to explain what i’m trying to achieve here – pdf watermarking with itextsharp.
Requirements:
- Each PDF file needs a watermark in this catalog.
- Each page of a pdf file needs a watermark.
- Watermark needs to be the name of the file without the file extension (.PDF).
- Watermark position fixed, say top-middle or bottom-middle of a page, pdf's are in A4 size always.
- Pdf's must keep their original file names and stay in the same folder "c:\ftp_out\test" after watermarking.
I must add i'm not a programmer so bear with me. But i'm learning :)
At one point i created a forum topic and asked for help:
http://stackoverflow.com/questions/13741160/watermark-existing-pdfs-before-ftping-them-in-visual-studio-2008
So i pretty much implemented everything there but as i ’m not programmer i don’t know how to define and use variables in this script.
Created a package variable „Pdf_To_Stamp“, created a for each loop container with a following collection, added the variable i mentioned earlier and gave initial value of 0 under "variable mappings"
PDF's are in the catalog "c:\ftp_out\test", "Files" value is "*.PDF", Fully qualified. No other settings for "foreach loop"
Inside of the foreach loop i placed a script task, readonlyvariables i put the "User::Pdf_To_Stamp" i mentioned earlier. the script it self is following:
using System;
using System.IO;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace ST_f19c41b37b1247068cf0b6f35d026cfa.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public static byte[] Stamp(byte[] resource)
{
PdfReader reader = new PdfReader(resource);
using (var ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
PdfContentByte canvas = stamper.GetOverContent(1);
ColumnText.ShowTextAligned(
canvas,
Element.ALIGN_LEFT,
new Phrase("name of the pdf file without the extension (.PDF) needed "),
36, 540, 0
);
}
return ms.ToArray();
}
}
}
}
But as you guessed correctly, it's not working :) So i'm clearly missing something here. I'm missing variables is my guess :)