// 完毕:
using System;
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Pdf.Annotations;
using GrapeCity.Documents.Pdf.Actions;
namespace DsPdfWeb.Demos.Basics
{
// 此示例演示如何在页面上创建文件附件注释。
// 另请参阅演示文档级文件附件的DocAttachments 示例。
public class FileAttachments
{
public int CreatePDF(Stream stream)
{
var doc = new GcPdfDocument();
var page = doc.NewPage();
var g = page.Graphics;
var rc = Common.Util.AddNote(
"示例的 Resources/Images 文件夹中的一些文件已附加到此页。\n" +
"",
page);
var ip = new PointF(rc.X, rc.Bottom + 9);
var attSize = new SizeF(36, 12);
var gap = 8;
var files = new string[]
{
"tudor.jpg",
"sea.jpg",
"puffins.jpg",
"lavender.jpg",
"skye.jpg",
"fiord.jpg",
"newfoundland.jpg"
};
foreach (string fn in files)
{
var file = Path.Combine("Resources", "Images", fn);
var faa = new FileAttachmentAnnotation()
{
Color = Color.FromArgb(unchecked((int)0xFFc540a5)),
UserName = "杰米·史密斯",
Rect = new RectangleF(ip.X, ip.Y, attSize.Width, attSize.Height),
Contents = "附件文件:" + file,
Icon = FileAttachmentAnnotationIcon.Paperclip,
File = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, file)),
};
page.Annotations.Add(faa);
g.FillRectangle(faa.Rect, Color.FromArgb(unchecked((int)0xFF40c5a3)));
g.DrawRectangle(faa.Rect, Color.FromArgb(unchecked((int)0xFF6040c5)));
ip.Y += attSize.Height + gap;
}
// 完毕:
doc.Save(stream);
return doc.Pages.Count;
}
}
}