本文整理匯總了C#中iTextSharp.text.pdf.PdfStamper.AddAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfStamper.AddAnnotation方法的具體用法?C# PdfStamper.AddAnnotation怎麽用?C# PdfStamper.AddAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfStamper
的用法示例。
在下文中一共展示了PdfStamper.AddAnnotation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DoGet
// ---------------------------------------------------------------------------
/**
* Show keys and values passed to the query string with GET
*/
protected void DoGet(byte[] pdf, Stream stream) {
// We get a resource from our web app
PdfReader reader = new PdfReader(pdf);
// Now we create the PDF
using (PdfStamper stamper = new PdfStamper(reader, stream)) {
// We add a submit button to the existing form
PushbuttonField button = new PushbuttonField(
stamper.Writer, new Rectangle(90, 660, 140, 690), "submit"
);
button.Text = "POST";
button.BackgroundColor = new GrayColor(0.7f);
button.Visibility = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT;
PdfFormField submit = button.Field;
submit.Action = PdfAction.CreateSubmitForm(
WebContext.Request.RawUrl, null, 0
);
stamper.AddAnnotation(submit, 1);
// We add an extra field that can be used to upload a file
TextField file = new TextField(
stamper.Writer, new Rectangle(160, 660, 470, 690), "image"
);
file.Options = TextField.FILE_SELECTION;
file.BackgroundColor = new GrayColor(0.9f);
PdfFormField upload = file.GetTextField();
upload.SetAdditionalActions(PdfName.U,
PdfAction.JavaScript(
"this.getField('image').browseForFileToSubmit();"
+ "this.getField('submit').setFocus();",
stamper.Writer
)
);
stamper.AddAnnotation(upload, 1);
}
}
示例2: highlightPDFAnnotation
// private void highlightPDFAnnotation(string readerPath, string outputFile, int pageno, string[] highlightText)
private void highlightPDFAnnotation(string readerPath, string outputFile, string[] highlightText)
{
PdfReader reader = new PdfReader(readerPath);
PdfContentByte canvas;
using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (PdfStamper stamper = new PdfStamper(reader, fs))
{
int pageCount = reader.NumberOfPages;
for (int pageno = 1; pageno <= pageCount; pageno++)
{
var strategy = new HighLightTextLocation();
strategy.UndercontentHorizontalScaling = 100;
string currentText = PdfTextExtractor.GetTextFromPage(reader, pageno, strategy);
for (int i = 0; i < highlightText.Length; i++)
{
List<Rectangle> MatchesFound = strategy.GetTextLocations(highlightText[i].Trim(), StringComparison.CurrentCultureIgnoreCase);
foreach (Rectangle rect in MatchesFound)
{
float[] quad = { rect.Left - 3.0f, rect.Bottom, rect.Right, rect.Bottom, rect.Left - 3.0f, rect.Top + 1.0f, rect.Right, rect.Top + 1.0f };
//Create our hightlight
PdfAnnotation highlight = PdfAnnotation.CreateMarkup(stamper.Writer, rect, null, PdfAnnotation.MARKUP_HIGHLIGHT, quad);
//Set the color
highlight.Color = BaseColor.YELLOW;
PdfAppearance appearance = PdfAppearance.CreateAppearance(stamper.Writer, rect.Width, rect.Height);
PdfGState state = new PdfGState();
state.BlendMode = new PdfName("Multiply");
appearance.SetGState(state);
appearance.Rectangle(0, 0, rect.Width, rect.Height);
appearance.SetColorFill(BaseColor.YELLOW);
appearance.Fill();
highlight.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance);
//Add the annotation
stamper.AddAnnotation(highlight, pageno);
}
}
}
}
}
reader.Close();
}
示例3: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public byte[] ManipulatePdf(byte[] src)
{
// Create a reader
PdfReader reader = new PdfReader(src);
int n = reader.NumberOfPages;
using (MemoryStream ms = new MemoryStream())
{
// Create a stamper
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
// Create pushbutton 1
PushbuttonField saveAs = new PushbuttonField(
stamper.Writer,
new Rectangle(636, 10, 716, 30),
"Save"
);
saveAs.BorderColor = BaseColor.BLACK;
saveAs.Text = "Save";
saveAs.TextColor = BaseColor.RED;
saveAs.Layout = PushbuttonField.LAYOUT_LABEL_ONLY;
saveAs.Rotation = 90;
PdfAnnotation saveAsButton = saveAs.Field;
saveAsButton.Action = PdfAction.JavaScript(
"app.execMenuItem('SaveAs')", stamper.Writer
);
// Create pushbutton 2
PushbuttonField mail = new PushbuttonField(
stamper.Writer,
new Rectangle(736, 10, 816, 30),
"Mail"
);
mail.BorderColor = BaseColor.BLACK;
mail.Text = "Mail";
mail.TextColor = BaseColor.RED;
mail.Layout = PushbuttonField.LAYOUT_LABEL_ONLY;
mail.Rotation = 90;
PdfAnnotation mailButton = mail.Field;
mailButton.Action = PdfAction.JavaScript(
"app.execMenuItem('AcroSendMail:SendMail')",
stamper.Writer
);
// Add the annotations to every page of the document
for (int page = 1; page <= n; page++)
{
stamper.AddAnnotation(saveAsButton, page);
stamper.AddAnnotation(mailButton, page);
}
}
return ms.ToArray();
}
}
示例4: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public override byte[] ManipulatePdf(byte[] src) {
locations = PojoFactory.GetLocations();
// Create a reader
PdfReader reader = new PdfReader(src);
using (MemoryStream ms = new MemoryStream()) {
// Create a stamper
using (PdfStamper stamper = new PdfStamper(reader, ms)) {
// Add annotations for every screening
int page = 1;
Rectangle rect;
PdfAnnotation annotation;
foreach (string day in PojoFactory.GetDays()) {
foreach (Screening screening in PojoFactory.GetScreenings(day)) {
rect = GetPosition(screening);
annotation = PdfAnnotation.CreateLink(
stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_INVERT,
new PdfAction(string.Format(IMDB, screening.movie.Imdb))
);
stamper.AddAnnotation(annotation, page);
}
page++;
}
}
return ms.ToArray();
}
}
示例5: AddNavigationTest
public void AddNavigationTest() {
String src = srcFolder + "primes.pdf";
String dest = outFolder + "primes_links.pdf";
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
PdfDestination d = new PdfDestination(PdfDestination.FIT);
Rectangle rect = new Rectangle(0, 806, 595, 842);
PdfAnnotation a10 = PdfAnnotation.CreateLink(stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_INVERT, 2, d);
stamper.AddAnnotation(a10, 1);
PdfAnnotation a1 = PdfAnnotation.CreateLink(stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_PUSH, 1, d);
stamper.AddAnnotation(a1, 2);
stamper.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(dest, srcFolder + "cmp_primes_links.pdf", outFolder, "diff_");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例6: ManipulatePdf
public void ManipulatePdf(String src, String dest)
{
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
Rectangle linkLocation = new Rectangle(523, 770, 559, 806);
PdfDestination destination = new PdfDestination(PdfDestination.FIT);
PdfAnnotation link = PdfAnnotation.CreateLink(stamper.Writer,
linkLocation, PdfAnnotation.HIGHLIGHT_INVERT,
3, destination);
stamper.AddAnnotation(link, 1);
stamper.Close();
}
示例7: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public byte[] ManipulatePdf(byte[] src)
{
// Create a reader for the original document
PdfReader reader = new PdfReader(src);
// Create a reader for the advertisement resource
PdfReader ad = new PdfReader(RESOURCE);
using (MemoryStream ms = new MemoryStream())
{
// Create a stamper
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
// Create the advertisement annotation for the menubar
Rectangle rect = new Rectangle(400, 772, 545, 792);
PushbuttonField button = new PushbuttonField(
stamper.Writer, rect, "click"
);
button.BackgroundColor = BaseColor.RED;
button.BorderColor = BaseColor.RED;
button.FontSize = 10;
button.Text = "Close this advertisement";
button.Image = Image.GetInstance(
Path.Combine(Utility.ResourceImage, IMAGE)
);
button.Layout = PushbuttonField.LAYOUT_LABEL_LEFT_ICON_RIGHT;
button.IconHorizontalAdjustment = 1;
PdfFormField menubar = button.Field;
String js = "var f1 = getField('click'); f1.display = display.hidden;"
+ "var f2 = getField('advertisement'); f2.display = display.hidden;"
;
menubar.Action = PdfAction.JavaScript(js, stamper.Writer);
// Add the annotation
stamper.AddAnnotation(menubar, 1);
// Create the advertisement annotation for the content
rect = new Rectangle(400, 550, 545, 772);
button = new PushbuttonField(
stamper.Writer, rect, "advertisement"
);
button.BackgroundColor = BaseColor.WHITE;
button.BorderColor = BaseColor.RED;
button.Text = "Buy the book iText in Action 2nd edition";
button.Template = stamper.GetImportedPage(ad, 1);
button.Layout = PushbuttonField.LAYOUT_ICON_TOP_LABEL_BOTTOM;
PdfFormField advertisement = button.Field;
advertisement.Action = new PdfAction(
"http://www.1t3xt.com/docs/book.php"
);
// Add the annotation
stamper.AddAnnotation(advertisement, 1);
}
return ms.ToArray();
}
}
示例8: addTextAnnotationToPDF
// Add annotation to PDF using iTextSharp
private void addTextAnnotationToPDF(string filePath, string contents, int pageNum, int x, int y, int width, int height)
{
PdfReader pdfReader = null;
PdfStamper pdfStamp = null;
try
{
using (var inStream = new FileStream(filePath, FileMode.Open))
{
pdfReader = new PdfReader(inStream);
}
using (var outStream = new FileStream(filePath, FileMode.Create))
{
pdfStamp = new PdfStamper(pdfReader, outStream, (char)0, true);
var rect = new iTextSharp.text.Rectangle((float)x, (float)y, (float)x + width, (float)y + height);
// Generating the annotation's appearance using a TextField
TextField textField = new TextField(pdfStamp.Writer, rect, null);
textField.Text = contents;
textField.FontSize = 8;
textField.TextColor = BaseColor.DARK_GRAY;
textField.BackgroundColor = new BaseColor(Color.LightGoldenrodYellow);
textField.BorderColor = new BaseColor(Color.BurlyWood);
textField.Options = TextField.MULTILINE;
textField.SetExtraMargin(2f, 2f);
textField.Alignment = Element.ALIGN_TOP | Element.ALIGN_LEFT;
PdfAppearance appearance = textField.GetAppearance();
// Create the annotation
PdfAnnotation annotation = PdfAnnotation.CreateFreeText(pdfStamp.Writer, rect, null, new PdfContentByte(null));
annotation.SetAppearance(PdfName.N, appearance);
annotation.Flags = PdfAnnotation.FLAGS_READONLY | PdfAnnotation.FLAGS_LOCKED | PdfAnnotation.FLAGS_PRINT;
annotation.Put(PdfName.NM, new PdfString(Guid.NewGuid().ToString()));
// Add annotation to PDF
pdfStamp.AddAnnotation(annotation, pageNum);
pdfStamp.Close();
}
}
catch (Exception ex)
{
throw new Exception("Could not add signature image to PDF with error: " + ex.Message);
}
}
示例9: DoGet
// ---------------------------------------------------------------------------
/**
* Show keys and values passed to the query string with GET
*/
protected void DoGet(byte[] pdf, Stream stream) {
// We get a resource from our web app
PdfReader reader = new PdfReader(pdf);
// Now we create the PDF
using (PdfStamper stamper = new PdfStamper(reader, stream)) {
// We add a submit button to the existing form
PushbuttonField button = new PushbuttonField(
stamper.Writer, new Rectangle(90, 660, 140, 690), "submit"
);
button.Text = "POST";
button.BackgroundColor = new GrayColor(0.7f);
button.Visibility = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT;
PdfFormField submit = button.Field;
submit.Action = PdfAction.CreateSubmitForm(
WebContext.Request.Url.ToString(), null, PdfAction.SUBMIT_XFDF
);
stamper.AddAnnotation(submit, 1);
}
}
示例10: TimestampPdf
private void TimestampPdf()
{
using (var pdfReader = new PdfReader(this.PdfProcessingPath))
{
using (var pdfStamper = new PdfStamper(pdfReader, new FileStream(this.PdfPath, FileMode.Create)))
{
var parentField = PdfFormField.CreateTextField(pdfStamper.Writer, false, false, 0);
parentField.FieldName = FieldName;
var lineSeparator = new LineSeparator();
for (var pageNumber = 1; pageNumber <= pdfReader.NumberOfPages; pageNumber++)
{
var pdfContentByte = pdfStamper.GetOverContent(pageNumber);
TextField textField = null;
if (this.Orientation == PdfOrientation.Portrait)
{
lineSeparator.DrawLine(pdfContentByte, PortraitFieldLeftX, PortraitFieldRightX, PortraitFieldUnderlineHeight);
textField = new TextField(pdfStamper.Writer, new Rectangle(PortraitFieldLeftX, PortraitFieldLeftY, PortraitFieldRightX, PortraitFieldRightY), null);
textField.Visibility = TextField.HIDDEN_BUT_PRINTABLE;
}
var childField = textField.GetTextField();
parentField.AddKid(childField);
childField.PlaceInPage = pageNumber;
}
pdfStamper.AddAnnotation(parentField, 1);
var pdfAction = PdfAction.JavaScript(LoadTimestampScript(), pdfStamper.Writer);
pdfStamper.Writer.SetAdditionalAction(PdfWriter.WILL_PRINT, pdfAction);
}
}
}
開發者ID:michaelbmorris,項目名稱:StandardOperatingProcedureManager,代碼行數:29,代碼來源:StandardOperatingProcedure.cs
示例11: addFields
private static void addFields(iTextSharp.text.pdf.PdfReader reader, FileStream fs, SqlDataReader dr)
{
using (var pdfStamper = new PdfStamper(reader, fs))
{
int i = 0;
int fieldIndex = 0;
int page = 1;
int top;
int bottom;
while (dr.Read())
{
if (i > 22 && page == 1)
{
page = 2;
i = 1;
}
i++;
fieldIndex++;
int lineSp = (i - 1) * 20;
if (page == 1)
{
top = 450 - lineSp;
bottom = 470 - lineSp;
}
else
{
top = 600 - lineSp;
bottom = 620 - lineSp;
}
iTextSharp.text.BaseColor currBackgrd;
if (i % 2 == 0)
currBackgrd = iTextSharp.text.BaseColor.WHITE;
else
currBackgrd = iTextSharp.text.BaseColor.LIGHT_GRAY;
TextField field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(20, top, 90, bottom), "Day" + fieldIndex.ToString());
field.FontSize = MYSIZE;
field.Rotation = 90;
field.BackgroundColor = currBackgrd;
pdfStamper.AddAnnotation(field.GetTextField(), page);
field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(92, top, 145, bottom), "Time" + fieldIndex.ToString());
field.FontSize = MYSIZE;
field.Rotation = 90;
field.BackgroundColor = currBackgrd;
pdfStamper.AddAnnotation(field.GetTextField(), page);
field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(147, top, 197, bottom), "Type" + fieldIndex.ToString());
field.FontSize = MYSIZE;
field.Rotation = 90;
field.BackgroundColor = currBackgrd;
pdfStamper.AddAnnotation(field.GetTextField(), page);
field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(199, top, 309, bottom), "Topic" + fieldIndex.ToString());
field.FontSize = MYSIZE;
field.Rotation = 90;
field.BackgroundColor = currBackgrd;
pdfStamper.AddAnnotation(field.GetTextField(), page);
field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(311, top, 461, bottom), "aaGroup" + fieldIndex.ToString());
field.FontSize = MYSIZE;
field.Rotation = 90;
field.BackgroundColor = currBackgrd;
pdfStamper.AddAnnotation(field.GetTextField(), page);
field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(463, top, 690, bottom), "Location" + fieldIndex.ToString());
field.FontSize = MYSIZE;
field.Rotation = 90;
field.BackgroundColor = currBackgrd;
pdfStamper.AddAnnotation(field.GetTextField(), page);
field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(692, top, 782, bottom), "City" + fieldIndex.ToString());
field.FontSize = MYSIZE;
field.Rotation = 90;
field.BackgroundColor = currBackgrd;
pdfStamper.AddAnnotation(field.GetTextField(), page);
}
pdfStamper.FormFlattening = true;
pdfStamper.Close();
reader.Close();
}
fs.Close();
}
示例12: MakePage
/// <summary>
/// Makes a single PDF page by reference.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <param name="x">The running record total.</param>
/// <param name="dt">DataTable contaning report query.</param>
/// <param name="bdt">DataTable containing the report detail query.</param>
/// <param name="verticalSpacing">The vertical spacing between each line in the report detail.</param>
/// <param name="rpp">Records Per Page.</param>
/// <param name="page">Current Page to read from.</param>
/// <param name="currentPage">Current page to write to.</param>
/// <param name="totalPages">The total number of pages.</param>
/// <param name="queryArguments">The query arguments.</param>
/// <returns>rendered pdf page</returns>
private static MemoryStream MakePage(string filePath, ref int x, ref DataTable dt, ref DataTable bdt,
int verticalSpacing, int rpp, int page, int currentPage, int totalPages, Dictionary<string, object> queryArguments)
{
("FUNCTION /w binaryStream makePage").Debug(10);
MemoryStream ms = new MemoryStream();
PdfReader reader = new PdfReader(filePath);
PdfStamper stamp = new PdfStamper(reader, ms);
Dictionary<string, AField> docFields = new Dictionary<string, AField>();
reader.SelectPages(page.ToString());
float top = 0;
for(var y = 0; rpp > y; y++) {
if(y + x > bdt.Rows.Count - 1) { break; };
foreach(string fieldKey in stamp.AcroFields.Fields.Keys) {
if(fieldKey.StartsWith(">>") || fieldKey.StartsWith(">>image")) {
WriteField(x + y, 1, top, fieldKey, ref stamp, ref docFields, currentPage, totalPages, bdt, queryArguments);
}
}
top -= verticalSpacing;
}
foreach(string fieldKey in stamp.AcroFields.Fields.Keys) {
if(
(fieldKey.StartsWith(">") && (!fieldKey.StartsWith(">>"))) ||
(fieldKey.StartsWith(">image") && (!fieldKey.StartsWith(">>image"))) || fieldKey.StartsWith("_page")
) {
WriteField(0, 0, 0, fieldKey, ref stamp, ref docFields, currentPage, totalPages, dt, queryArguments);
}
}
reader.RemoveFields();
foreach(KeyValuePair<string, AField> f in docFields) {
Rectangle rect = f.Value.Rect;
string value = f.Value.Value;
TextField field = new TextField(stamp.Writer, rect, f.Key);
field.DefaultText = value;
field.FieldName = f.Key;
field.Options = iTextSharp.text.pdf.TextField.MULTILINE;
stamp.AddAnnotation(field.GetTextField(), 1);
}
stamp.Close();
reader.Close();
reader = new PdfReader(ms.GetBuffer());
MemoryStream os = new MemoryStream();
stamp = new PdfStamper(reader, os);
WriteAFieldCollection(ref stamp, docFields, filePath);
reader.RemoveFields();
stamp.Close();
reader.Close();
return os;
}
示例13: AddPopup
// ---------------------------------------------------------------------------
/**
* Adds a popup.
* @param stamper the PdfStamper to which the annotation needs to be added
* @param rect the position of the annotation
* @param title the annotation title
* @param contents the annotation content
* @param imdb the IMDB number of the movie used as name of the annotation
*/
public void AddPopup(PdfStamper stamper, Rectangle rect,
String title, String contents, String imdb)
{
// Create the text annotation
PdfAnnotation text = PdfAnnotation.CreateText(
stamper.Writer,
rect, title, contents, false, "Comment"
);
text.Name = string.Format("IMDB{0}", imdb);
text.Flags = PdfAnnotation.FLAGS_READONLY | PdfAnnotation.FLAGS_NOVIEW;
// Create the popup annotation
PdfAnnotation popup = PdfAnnotation.CreatePopup(
stamper.Writer,
new Rectangle(
rect.Left + 10, rect.Bottom + 10,
rect.Left + 200, rect.Bottom + 100
),
null, false
);
// Add the text annotation to the popup
popup.Put(PdfName.PARENT, text.IndirectReference);
// Declare the popup annotation as popup for the text
text.Put(PdfName.POPUP, popup.IndirectReference);
// Add both annotations
stamper.AddAnnotation(text, 1);
stamper.AddAnnotation(popup, 1);
// Create a button field
PushbuttonField field = new PushbuttonField(
stamper.Writer, rect,
string.Format("b{0}", imdb)
);
PdfAnnotation widget = field.Field;
// Show the popup onMouseEnter
PdfAction enter = PdfAction.JavaScript(
string.Format(JS1, imdb), stamper.Writer
);
widget.SetAdditionalActions(PdfName.E, enter);
// Hide the popup onMouseExit
PdfAction exit = PdfAction.JavaScript(
string.Format(JS2, imdb), stamper.Writer
);
widget.SetAdditionalActions(PdfName.X, exit);
// Add the button annotation
stamper.AddAnnotation(widget, 1);
}
示例14: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public virtual byte[] ManipulatePdf(byte[] src)
{
locations = PojoFactory.GetLocations();
// Create a reader
PdfReader reader = new PdfReader(src);
using (MemoryStream ms = new MemoryStream())
{
// Create a stamper
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
// Add the annotations
int page = 1;
Rectangle rect;
PdfAnnotation annotation;
Movie movie;
foreach (string day in PojoFactory.GetDays())
{
foreach (Screening screening in PojoFactory.GetScreenings(day))
{
movie = screening.movie;
rect = GetPosition(screening);
annotation = PdfAnnotation.CreateText(
stamper.Writer, rect, movie.MovieTitle,
string.Format(INFO, movie.Year, movie.Duration),
false, "Help"
);
annotation.Color = WebColors.GetRGBColor(
"#" + movie.entry.category.color
);
stamper.AddAnnotation(annotation, page);
}
page++;
}
}
return ms.ToArray();
}
}
示例15: addTextToPdf
/// <summary>
/// AppData contains the information needed to create a new PDF with overlayed information including name, description, website, and image.
/// </summary>
/// <param name="data">The data to use</param>
static void addTextToPdf(AppData data)
{
using (PdfStamper stamper = new PdfStamper(new PdfReader(sourcePDF), File.Create(data.filename)))
{
// Create the header textbox
TextField name = new TextField(stamper.Writer, new Rectangle(80, 932, 719, 1022), "Name");
name.Text = data.name;
name.Alignment = Element.ALIGN_CENTER;
// Get and set the image
Image image;
try
{
image = Image.GetInstance(data.photo);
} catch
{
image = Image.GetInstance("../../files/default.png");
}
image.ScaleAbsolute(new Rectangle(80, 200, 721, 593));
image.SetAbsolutePosition(79, 488);
// Create the description textbox
TextField description = new TextField(stamper.Writer, new Rectangle(80, 74, 719, 438), "Description");
description.Options = TextField.MULTILINE;
description.Text = data.description;
description.Alignment = Element.ALIGN_CENTER;
//calculate the font size
float size = ColumnText.FitText(new Font(description.Font), data.description, new Rectangle(0, 0, 560, 365), 80, 0);
description.FontSize = size;
//Add the website URL if it exists
TextField website = new TextField(stamper.Writer, new Rectangle(80, 30, 719, 60), "Website");
website.Text = data.website;
website.Alignment = Element.ALIGN_CENTER;
// Write and close
stamper.AddAnnotation(name.GetTextField(), 1);
stamper.GetOverContent(1).AddImage(image);
stamper.AddAnnotation(description.GetTextField(), 1);
stamper.AddAnnotation(website.GetTextField(), 1);
stamper.Close();
}
}