本文整理匯總了C#中iTextSharp.text.Document.AddTitle方法的典型用法代碼示例。如果您正苦於以下問題:C# Document.AddTitle方法的具體用法?C# Document.AddTitle怎麽用?C# Document.AddTitle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.AddTitle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: btnCreateReport_Click
private void btnCreateReport_Click(object sender, EventArgs e)
{
// _______________________________________________________1_______________________________________________________
// Setting pagetype, margins and encryption
iTextSharp.text.Rectangle pageType = iTextSharp.text.PageSize.A4;
float marginLeft = 72;
float marginRight = 36;
float marginTop = 60;
float marginBottom = 50;
String reportName = "Test.pdf";
Document report = new Document(pageType, marginLeft, marginRight, marginTop, marginBottom);
PdfWriter writer = PdfWriter.GetInstance(report, new FileStream(reportName, FileMode.Create));
//writer.SetEncryption(PdfWriter.STRENGTH40BITS, "Good", "Bad", PdfWriter.ALLOW_COPY);
report.Open();
// _______________________________________________________2_______________________________________________________
// Setting Document properties(Meta data)
// 1. Title
// 2. Subject
// 3. Keywords
// 4. Creator
// 5. Author
// 6. Header
report.AddTitle("Employee Details Report");
report.AddSubject("This file is generated for administrative use only");
report.AddKeywords("Civil Security Department, Employee Management System, Version 1.0.0, Report Generator");
report.AddCreator("Ozious Technologies");
report.AddAuthor("Eranga Heshan");
report.AddHeader("Owner", "Civil Security Department");
// _______________________________________________________3_______________________________________________________
// Setup the font factory
/*
int totalFonts = FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts");
StringBuilder sb = new StringBuilder();
foreach (string fontname in FontFactory.RegisteredFonts) { sb.Append(fontname + "\n"); }
report.Add(new Paragraph("All Fonts:\n" + sb.ToString()));
*/
iTextSharp.text.Font fontHeader_1 = FontFactory.GetFont("Calibri", 30, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));
iTextSharp.text.Font fontHeader_2 = FontFactory.GetFont("Calibri", 15, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(125, 125, 125));
// _______________________________________________________x_______________________________________________________
// Create header
PdfContentByte cb = writer.DirectContent;
cb.MoveTo(marginLeft, marginTop);
cb.LineTo(500, marginTop);
cb.Stroke();
Paragraph paraHeader_1 = new Paragraph("Civil Security Department", fontHeader_1);
paraHeader_1.Alignment = Element.ALIGN_CENTER;
paraHeader_1.SpacingAfter = 0f;
report.Add(paraHeader_1);
Paragraph paraHeader_2 = new Paragraph("Employee Detailed Report", fontHeader_2);
paraHeader_2.Alignment = Element.ALIGN_CENTER;
paraHeader_2.SpacingAfter = 10f;
report.Add(paraHeader_2);
// _______________________________________________________x_______________________________________________________
// Adding employee image
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgEmployee.ImageLocation);
img.ScaleToFit(100f, 100f);
img.Border = iTextSharp.text.Rectangle.BOX;
img.BorderColor = iTextSharp.text.BaseColor.BLACK;
img.BorderWidth = 5f;
img.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT | iTextSharp.text.Image.ALIGN_TOP;
img.IndentationLeft = 50f;
img.SpacingAfter = 20f;
img.SpacingBefore = 20f;
report.Add(img);
Paragraph para1 = new Paragraph("Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... ");
para1.Alignment = Element.ALIGN_JUSTIFIED;
report.Add(para1);
report.Close();
this.Close();
}
示例2: GetOrCreatePDF
/// <summary>
/// 讀取或創建Pdf文檔並打開寫入文件流
/// </summary>
/// <param name="fileName"></param>
/// <param name="folderPath"></param>
public Document GetOrCreatePDF(string fileName, string folderPath)
{
string filePath = folderPath + fileName;
FileStream fs = null;
if (!File.Exists(filePath))
{
fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
}
else
{
fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.None);
}
//獲取A4紙尺寸
Rectangle rec = new Rectangle(PageSize.A4);
Document doc = new Document(rec);
//創建一個 iTextSharp.text.pdf.PdfWriter 對象: 它有助於把Document書寫到特定的FileStream:
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.AddTitle(fileName.Remove(fileName.LastIndexOf('.')));
doc.AddSubject(fileName.Remove(fileName.LastIndexOf('.')));
doc.AddKeywords("Metadata, iTextSharp 5.4.4, Chapter 1, Tutorial");
doc.AddCreator("MCS");
doc.AddAuthor("Chingy");
doc.AddHeader("Nothing", "No Header");
//打開 Document:
doc.Open();
////關閉 Document:
//doc.Close();
return doc;
}
示例3: ReportPdf
public ReportPdf(Stream Output, Layout Layout, Template Template, Dictionary<string, string> ConfigParams)
: base(Output, Layout, Template, ConfigParams)
{
Rectangle pageSize = new Rectangle(mm2pt(Template.PageSize.Width), mm2pt(Template.PageSize.Height));
// Initialization
m_Document = new Document(pageSize, mm2pt(Template.Margin.Left), mm2pt(Template.Margin.Right), mm2pt(Template.Margin.Top), mm2pt(Template.Margin.Bottom));
m_Writer = PdfWriter.GetInstance(m_Document, Output);
m_Document.AddCreationDate();
m_Document.AddCreator("StrengthReport http://dev.progterv.info/strengthreport) and KeePass (http://keepass.info)");
m_Document.AddKeywords("report");
m_Document.AddTitle(Layout.Title+" (report)");
// Header
HeaderFooter header = new HeaderFooter(new Phrase(Layout.Title+", "+DateTime.Now.ToString(), m_Template.ReportFooter.getFont()), false);
header.Alignment = Template.ReportFooter.getAlignment();
m_Document.Header = header;
// Footer
HeaderFooter footer = new HeaderFooter(new Phrase(new Chunk("Page ", m_Template.ReportFooter.getFont())), new Phrase(new Chunk(".", m_Template.ReportFooter.getFont())));
footer.Alignment = Template.ReportFooter.getAlignment();
m_Document.Footer = footer;
// TODO: Metadata
// Open document
m_Document.Open();
// Report Heading
{
PdfPTable reportTitle = new PdfPTable(1);
PdfPCell titleCell = new PdfPCell(new Phrase(Layout.Title, m_Template.ReportHeader.getFont()));
titleCell.Border = 0;
titleCell.FixedHeight = mm2pt(m_Template.ReportHeader.Height);
titleCell.VerticalAlignment = Element.ALIGN_MIDDLE;
titleCell.HorizontalAlignment = m_Template.ReportHeader.getAlignment();
reportTitle.AddCell(titleCell);
reportTitle.WidthPercentage = 100;
m_Document.Add(reportTitle);
}
// Create main table
m_Table = new PdfPTable(Layout.GetColumnWidths());
m_Table.WidthPercentage = 100;
m_Table.HeaderRows = 1;
foreach (LayoutElement element in Layout) {
PdfPCell cell = new PdfPCell(new Phrase(element.Title, m_Template.Header.getFont()));
cell.BackgroundColor = m_Template.Header.Background.ToColor();
cell.MinimumHeight = mm2pt(m_Template.Header.Height);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
m_Table.AddCell(cell);
}
m_colorRow = new CMYKColor[] { m_Template.Row.BackgroundA.ToColor(), m_Template.Row.BackgroundB.ToColor() };
}
示例4: Form1
// From <ClickButt> -> PdfConnector PdfCreatora <- PdfCreator(naemBank,Bodytext)
// Form <Image> <- PdfConnector -- tworzyć pdf |
public Form1()
{
while (!fileBanksLists.EndOfStream)
{
InitializeComponent();
using (FileStream file = new FileStream(String.Format(path, nameBank), FileMode.Create))
{
Document document = new Document(PageSize.A7);
PdfWriter writer = PdfWriter.GetInstance(document, file);
/// Create metadate pdf file
document.AddAuthor(nameBank);
document.AddLanguage("pl");
document.AddSubject("Payment transaction");
document.AddTitle("Transaction");
document.AddKeywords("OutcomingNumber :" + OutcomingNumber);
document.AddKeywords("IncomingNumber :" + IncomingNumber);
/// Create text in pdf file
document.Open();
document.Add(new Paragraph(_przelew + "\n"));
document.Add(new Paragraph(String.Format("Bank {0}: zaprasza\n", nameBank)));
document.Add(new Paragraph(DateTime.Now.ToString()));
document.Close();
writer.Close();
file.Close();
}
}
}
示例5: GeneratePdfSingleDataType
public static void GeneratePdfSingleDataType(string filePath, string title, string content)
{
try
{
Logger.LogI("GeneratePDF -> " + filePath);
var doc = new Document(PageSize.A3, 36, 72, 72, 144);
using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.AddTitle(title);
doc.AddAuthor(Environment.MachineName);
doc.Add(
new Paragraph("Title : " + title + Environment.NewLine + "ServerName : " +
Environment.MachineName +
Environment.NewLine + "Author : " + Environment.UserName));
doc.NewPage();
doc.Add(new Paragraph(content));
doc.Close();
}
}
catch (Exception ex)
{
Logger.LogE(ex.Source + " -> " + ex.Message + "\n" + ex.StackTrace);
}
}
示例6: TryCreatePdf
public bool TryCreatePdf(string nameBank)
{
try
{
using (FileStream file = new FileStream(String.Format(path,nameBank), FileMode.Create))
{
Document document = new Document(PageSize.A7);
PdfWriter writer = PdfWriter.GetInstance(document, file);
/// Create metadate pdf file
document.AddAuthor("");
document.AddLanguage("pl");
document.AddSubject("Payment transaction");
document.AddTitle("Transaction");
/// Create text in pdf file
document.Open();
document.Add(new Paragraph(_przelew+"\n"));
document.Add(new Paragraph(String.Format("Bank {0}: zaprasza\n",nameBank)));
document.Add(new Paragraph(DateTime.Now.ToString()));
document.Close();
writer.Close();
file.Close();
return true;
}
}
catch (SystemException ex)
{
return false;
}
}
示例7: Build
public void Build()
{
if (artUrls != null)
{
Build2();
return;
}
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(baseDir + _fileName, FileMode.Create));
document.Open();
document.AddTitle(_title);
Font ft = new Font(baseFT, 12);
int cnt = items.Count;
for (int i = cnt - 1; i >= 0; i--)
{
var entity = items[i];
if (!entity.IsDown)
{
continue;
}
_callback("獲取文章 " + (cnt - i) + "/" + cnt + ":" + entity.Title);
document.Add(GetChapter(entity));
}
document.Close();
}
示例8: CreatePdf
public void CreatePdf(Project project, Stream writeStream)
{
var document = new Document();
var writer = PdfWriter.GetInstance(document, writeStream);
// landscape
document.SetPageSize(PageSize.A4.Rotate());
document.SetMargins(36f, 36f, 36f, 36f); // 0.5 inch margins
// metadata
document.AddCreator("EstimatorX.com");
document.AddKeywords("estimation");
document.AddAuthor(project.Creator);
document.AddSubject(project.Name);
document.AddTitle(project.Name);
document.Open();
AddName(project, document);
AddDescription(project, document);
AddAssumptions(project, document);
AddFactors(project, document);
AddTasks(project, document);
AddSummary(project, document);
writer.Flush();
document.Close();
}
示例9: Build
public void Build()
{
iTextSharp.text.Document doc = null;
try
{
// Initialize the PDF document
doc = new Document();
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc,
new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() + "\\ScienceReport.pdf",
System.IO.FileMode.Create));
// Set margins and page size for the document
doc.SetMargins(50, 50, 50, 50);
// There are a huge number of possible page sizes, including such sizes as
// EXECUTIVE, POSTCARD, LEDGER, LEGAL, LETTER_LANDSCAPE, and NOTE
doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width,
iTextSharp.text.PageSize.LETTER.Height));
// Add metadata to the document. This information is visible when viewing the
// document properities within Adobe Reader.
doc.AddTitle("My Science Report");
doc.AddCreator("M. Lichtenberg");
doc.AddKeywords("paper airplanes");
// Add Xmp metadata to the document.
this.CreateXmpMetadata(writer);
// Open the document for writing content
doc.Open();
// Add pages to the document
this.AddPageWithBasicFormatting(doc);
this.AddPageWithInternalLinks(doc);
this.AddPageWithBulletList(doc);
this.AddPageWithExternalLinks(doc);
this.AddPageWithImage(doc, System.IO.Directory.GetCurrentDirectory() + "\\FinalGraph.jpg");
// Add page labels to the document
iTextSharp.text.pdf.PdfPageLabels pdfPageLabels = new iTextSharp.text.pdf.PdfPageLabels();
pdfPageLabels.AddPageLabel(1, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Basic Formatting");
pdfPageLabels.AddPageLabel(2, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Internal Links");
pdfPageLabels.AddPageLabel(3, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Bullet List");
pdfPageLabels.AddPageLabel(4, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "External Links");
pdfPageLabels.AddPageLabel(5, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Image");
writer.PageLabels = pdfPageLabels;
}
catch (iTextSharp.text.DocumentException dex)
{
// Handle iTextSharp errors
}
finally
{
// Clean up
doc.Close();
doc = null;
}
}
示例10: WriteDocument
protected override void WriteDocument(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
if (File.Exists(FilePath))
throw new Pdf2KTException("File already exists.");
Document document = null;
PdfWriter writer = null;
while(Converter.MoveNext())
{
if (worker.CancellationPending == true)
{
e.Cancel = true;
break;
}
BitmapEncoder encoder = BitmapProcessor.GetBitmapEncoder();
BitmapSource processed = BitmapProcessor.Convert(Converter.Current);
if (document == null)
{
document = new Document(new Rectangle(processed.PixelWidth, processed.PixelHeight));
writer = PdfWriter.GetInstance(document, new FileStream(FilePath, FileMode.Create));
document.Open();
document.AddTitle(Converter.Document.Title);
document.AddAuthor(Converter.Document.Author);
document.AddCreationDate();
document.AddCreator("Pdf2KT");
}
document.NewPage();
using (MemoryStream ms = new MemoryStream())
{
encoder.Frames.Add(BitmapFrame.Create(processed));
encoder.Save(ms);
ms.Position = 0;
Image pdfpage = Image.GetInstance(ms);
pdfpage.SetAbsolutePosition(0, 0);
document.Add(pdfpage);
}
worker.ReportProgress((int)((Converter.CurrentProcessedPageNumber * 1f) / Converter.PageCount * 100));
}
document.Close();
}
示例11: Publish
public void Publish(IReadOnlyList<ReleaseNoteWorkItem> workItems)
{
var stream = new MemoryStream();
try
{
_document = new Document(PageSize.A4, 36, 36, 90, 72);
// Initialize pdf writer
_writer = PdfWriter.GetInstance(_document, stream);
_writer.PageEvent = new ReleaseNotesPdfPageEvents(Settings);
// Open document to write
_document.Open();
_document.AddTitle(Settings.GetDocumentTitle());
_document.AddSubject(Settings.ProductName + " Release Notes");
_document.AddAuthor("ReleaseNotes Generator");
_document.AddKeywords(Settings.ProductName + "Release Notes");
_document.AddCreationDate();
_document.AddCreator("ReleaseNotes Generator");
// Add manual release notes for current release
int chapterNumber = 1;
if (!string.IsNullOrEmpty(Settings.MergeReleaseNotesFile) && File.Exists(Settings.MergeReleaseNotesFile))
{
Bookmarks.AddRange(Merge(Settings.MergeReleaseNotesFile, 1));
if (Bookmarks.Count > 0)
chapterNumber = Bookmarks.Count;
}
// Add automatic releases notes for current release
WriteWorkItems("How do I?", ref chapterNumber, workItems.Where(x => x.ResolutionType == "How do I" || x.ResolutionType == "As Designed"));
WriteWorkItems("Bug Fixes", ref chapterNumber, workItems.Where(x => x.ResolutionType == "Bug Fix"));
WriteWorkItems("Known Issues", ref chapterNumber, workItems.Where(x => x.ResolutionType == "Known Issue"));
WriteWorkItems("User Manual", ref chapterNumber, workItems.Where(x => x.ResolutionType == "User Manual"));
CreateBookmarks();
}
catch (Exception exception)
{
throw new Exception("There has an unexpected exception occured whilst creating the release notes: " + exception.Message, exception);
}
finally
{
_document.Close();
}
File.WriteAllBytes(Settings.OutputFile, stream.GetBuffer());
}
示例12: CreateDocument
public static void CreateDocument(Stream stream, Action<Document> action)
{
using (var document = new Document(PageSize.A4))
{
var writer = PdfWriter.GetInstance(document, stream);
document.Open();
document.AddAuthor(Author);
document.AddCreator(DocumentCreator);
document.AddKeywords(DocumentKeywords);
document.AddSubject(DocumentSubject);
document.AddTitle(DocumentTitle);
action.Invoke(document);
document.Close();
}
}
示例13: 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.AddTitle("Hello World example");
document.AddAuthor("Bruno Lowagie");
document.AddSubject("This example shows how to add metadata");
document.AddKeywords("Metadata, iText, PDF");
document.AddCreator("My program using iText");
document.Open();
// step 4
document.Add(new Paragraph("Hello World"));
}
return ms.ToArray();
}
}
示例14: GeneratePDF
public static MemoryStream GeneratePDF(Teacher teacher, SchoolClass schoolClass, string schoolYear)
{
Document document = new Document();
MemoryStream stream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, stream);
writer.CloseStream = false;
document.Open();
document.AddCreationDate();
document.AddAuthor("VaKEGrade");
document.AddTitle("Certificate");
foreach (Pupil pupil in teacher.PrimaryClasses.First().Pupils.OrderBy(x => x.LastName).ToList())
{
CertificateGenerator.GenerateCertificate(pupil, schoolClass, schoolYear, ref document);
}
document.Close();
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
示例15: Main
private static void Main()
{
const string path = @"C:\Users\Santhosh\AppData\test.pdf";
if (File.Exists(path))
File.Delete(path);
var doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create));
// Metadata
doc.AddCreator("");
doc.AddTitle("General Receipt");
// Add content
doc.Open();
PdfContentByte cb = writer.DirectContent;
cb.SetLineWidth(0.1f);
cb.Rectangle(50f, 300f, 500f, 70f);
cb.Stroke();
doc.Close();
}