How to pass and use variables to iTextSharp .dll used in script task

Posted by Marttali under Visual Studio on 1/4/2013 | Points: 10 | Views : 1334 | Status : [Member] | Replies : 0

new user here, so howdy !

So i try to explain what i'm trying to achieve here - pdf watermarking with itextsharp.


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:

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);
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.

So i'm kindly asking for your help to solve this for me


(No response found.)

Login to post response