本文整理汇总了C#中iTextSharp.text.Chunk.SetAction方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.SetAction方法的具体用法?C# Chunk.SetAction怎么用?C# Chunk.SetAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Chunk
的用法示例。
在下文中一共展示了Chunk.SetAction方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public byte[] ManipulatePdf(byte[] src) {
// Create a table with named actions
Font symbol = new Font(Font.FontFamily.SYMBOL, 20);
PdfPTable table = new PdfPTable(4);
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
Chunk first = new Chunk( ((char)220).ToString() , symbol);
first.SetAction(new PdfAction(PdfAction.FIRSTPAGE));
table.AddCell(new Phrase(first));
Chunk previous = new Chunk( ((char)172).ToString(), symbol);
previous.SetAction(new PdfAction(PdfAction.PREVPAGE));
table.AddCell(new Phrase(previous));
Chunk next = new Chunk( ((char)174).ToString(), symbol);
next.SetAction(new PdfAction(PdfAction.NEXTPAGE));
table.AddCell(new Phrase(next));
Chunk last = new Chunk( ((char)222).ToString(), symbol);
last.SetAction(new PdfAction(PdfAction.LASTPAGE));
table.AddCell(new Phrase(last));
table.TotalWidth = 120;
// 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 table to each page
PdfContentByte canvas;
for (int i = 0; i < reader.NumberOfPages; ) {
canvas = stamper.GetOverContent(++i);
table.WriteSelectedRows(0, -1, 696, 36, canvas);
}
}
return ms.ToArray();
}
}
示例2: CreateNavigationTable
// ---------------------------------------------------------------------------
/**
* Create a table that can be used as a footer
* @param pagenumber the page that will use the table as footer
* @param total the total number of pages
* @return a tabel
*/
public PdfPTable CreateNavigationTable(int pagenumber, int total) {
PdfPTable table = new PdfPTable(4);
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
Chunk first = new Chunk(((char)220).ToString(), SYMBOL);
first.SetAction(actions[0]);
table.AddCell(new Phrase(first));
Chunk previous = new Chunk(((char)172).ToString(), SYMBOL);
previous.SetAction(actions[pagenumber - 2 < 0 ? 0 : pagenumber - 2]);
table.AddCell(new Phrase(previous));
Chunk next = new Chunk(((char)174).ToString(), SYMBOL);
next.SetAction(actions[pagenumber >= total ? total - 1 : pagenumber]);
table.AddCell(new Phrase(next));
Chunk last = new Chunk(((char)222).ToString(), SYMBOL);
last.SetAction(actions[total - 1]);
table.AddCell(new Phrase(last));
table.TotalWidth = 120;
return table;
}
示例3: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result (localhost)
* @param src the original PDF
*/
public byte[] ManipulatePdf(byte[] src)
{
// Create the reader
PdfReader reader = new PdfReader(src);
int n = reader.NumberOfPages;
using (MemoryStream ms = new MemoryStream())
{
// Create the stamper
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
// Add JavaScript
jsString = File.ReadAllText(
Path.Combine(Utility.ResourceJavaScript, RESOURCE)
);
stamper.JavaScript = jsString;
// Create a Chunk with a chained action
PdfContentByte canvas;
Chunk chunk = new Chunk("print this page");
PdfAction action = PdfAction.JavaScript(
"app.alert('Think before you print!');",
stamper.Writer
);
action.Next(PdfAction.JavaScript(
"printCurrentPage(this.pageNum);",
stamper.Writer
));
action.Next(new PdfAction("http://www.panda.org/savepaper/"));
chunk.SetAction(action);
Phrase phrase = new Phrase(chunk);
// Add this Chunk to every page
for (int i = 0; i < n; )
{
canvas = stamper.GetOverContent(++i);
ColumnText.ShowTextAligned(
canvas, Element.ALIGN_RIGHT, phrase, 816, 18, 0
);
}
}
return ms.ToArray();
}
}
示例4: CreateMoviePage
// ---------------------------------------------------------------------------
/**
* Creates the PDF.
* @return the bytes of a PDF file.
*/
public byte[] CreateMoviePage(Movie movie)
{
using (MemoryStream ms = new MemoryStream()) {
// step 1
using (Document document = new Document()) {
// step 2
PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
Paragraph p = new Paragraph(
movie.MovieTitle,
FontFactory.GetFont(
BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, 16
)
);
document.Add(p);
document.Add(Chunk.NEWLINE);
PdfPTable table = new PdfPTable(WIDTHS);
table.AddCell(Image.GetInstance(
String.Format(RESOURCE, movie.Imdb)
));
PdfPCell cell = new PdfPCell();
cell.AddElement(new Paragraph("Year: " + movie.Year.ToString()));
cell.AddElement(new Paragraph("Duration: " + movie.Duration.ToString()));
table.AddCell(cell);
document.Add(table);
PdfTargetDictionary target = new PdfTargetDictionary(false);
target.AdditionalPath = new PdfTargetDictionary(false);
Chunk chunk = new Chunk("Go to original document");
PdfAction action = PdfAction.GotoEmbedded(
null, target, new PdfString("movies"), false
);
chunk.SetAction(action);
document.Add(chunk);
}
return ms.ToArray();
}
}
示例5: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream) {
// step 1
using (Document document = new Document()) {
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
Image img = Image.GetInstance(IMG_BOX);
document.Add(img);
List list = new List(List.UNORDERED, 20);
PdfDestination dest = new PdfDestination(PdfDestination.FIT);
dest.AddFirst(new PdfNumber(1));
IEnumerable<Movie> box = PojoFactory.GetMovies(1)
.Concat(PojoFactory.GetMovies(4))
;
foreach (Movie movie in box) {
if (movie.Year > 1960) {
PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(
writer, null,
String.Format("kubrick_{0}.pdf", movie.Imdb),
CreateMoviePage(movie)
);
fs.AddDescription(movie.Title, false);
writer.AddFileAttachment(fs);
ListItem item = new ListItem(movie.MovieTitle);
PdfTargetDictionary target = new PdfTargetDictionary(true);
target.EmbeddedFileName = movie.Title;
PdfAction action = PdfAction.GotoEmbedded(null, target, dest, true);
Chunk chunk = new Chunk(" (see info)");
chunk.SetAction(action);
item.Add(chunk);
list.Add(item);
}
}
document.Add(list);
}
}
示例6: CreateTaggedPdf13
public void CreateTaggedPdf13() {
InitializeDocument("13");
Paragraph p = new Paragraph();
Chunk chunk = new Chunk("Please visit ");
p.Add(chunk);
PdfAction action = new PdfAction("http://itextpdf.com");
chunk = new Chunk("http://itextpdf.com",
new Font(Font.FontFamily.HELVETICA, Font.UNDEFINED, Font.UNDERLINE, BaseColor.BLUE));
chunk.SetAction(action);
p.Add(chunk);
p.Add(new Chunk(" for more details."));
document.Add(p);
document.Close();
// int[] nums = new int[] {5};
// CheckNums(nums);
CompareResults("13");
}
示例7: CreateDirectorParagraph
// ---------------------------------------------------------------------------
/**
* Creates a Phrase with the name and given name of a director
* using different fonts.
* @param r the DbDataReader containing director records.
*/
public Paragraph CreateDirectorParagraph(PdfWriter writer, DbDataReader r)
{
string n = r["name"].ToString();
Chunk name = new Chunk(n);
name.SetAction(PdfAction.JavaScript(
string.Format("findDirector('{0}');", n),
writer
));
name.Append(", ");
name.Append(r["given_name"].ToString());
return new Paragraph(name);
}
示例8: CreatePdf
// ---------------------------------------------------------------------------
/**
* Creates a PDF document.
*/
public byte[] CreatePdf()
{
using (MemoryStream ms = new MemoryStream())
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
// Add text with a local destination
Paragraph p = new Paragraph();
Chunk top = new Chunk("Country List", FilmFonts.BOLD);
top.SetLocalDestination("top");
p.Add(top);
document.Add(p);
// Add text with a link to an external URL
Chunk imdb = new Chunk("Internet Movie Database", FilmFonts.ITALIC);
imdb.SetAction(new PdfAction(new Uri("http://www.imdb.com/")));
p = new Paragraph(
@"Click on a country, and you'll get a list of movies,
containing links to the "
);
p.Add(imdb);
p.Add(".");
document.Add(p);
// Add text with a remote goto
p = new Paragraph("This list can be found in a ");
Chunk page1 = new Chunk("separate document");
page1.SetAction(new PdfAction(RESULT1, 1));
p.Add(page1);
p.Add(".");
document.Add(p);
document.Add(Chunk.NEWLINE);
// Get a list with countries from the database
var SQL =
@"SELECT DISTINCT mc.country_id, c.country, count(*) AS c
FROM film_country c, film_movie_country mc
WHERE c.id = mc.country_id
GROUP BY mc.country_id, country
ORDER BY c DESC";
using (var c = AdoDB.Provider.CreateConnection())
{
c.ConnectionString = AdoDB.CS;
using (DbCommand cmd = c.CreateCommand())
{
cmd.CommandText = SQL;
c.Open();
using (var r = cmd.ExecuteReader())
{
while (r.Read())
{
Paragraph country = new Paragraph(r["country"].ToString());
country.Add(": ");
Chunk link = new Chunk(string.Format(
"{0} movies", r["c"].ToString()
));
link.SetAction(PdfAction.GotoRemotePage(
RESULT1,
r["country_id"].ToString(),
false,
true
));
country.Add(link);
document.Add(country);
}
}
}
}
document.Add(Chunk.NEWLINE);
// Add text with a local goto
p = new Paragraph("Go to ");
top = new Chunk("top");
top.SetAction(PdfAction.GotoLocalPage("top", false));
p.Add(top);
p.Add(".");
document.Add(p);
}
return ms.ToArray();
}
}