本文整理汇总了C#中System.PageData.GetPropertyValues方法的典型用法代码示例。如果您正苦于以下问题:C# PageData.GetPropertyValues方法的具体用法?C# PageData.GetPropertyValues怎么用?C# PageData.GetPropertyValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.PageData
的用法示例。
在下文中一共展示了PageData.GetPropertyValues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneratePdf
/// <summary>
/// Generates the PDF.
/// </summary>
/// <param name="page">
/// The page.
/// </param>
/// <returns>
/// The pdf in bytes.
/// </returns>
public static byte[] GeneratePdf(PageData page)
{
List<KeyValuePair<string, string>> propertyValues = page.GetPropertyValues();
IContentRepository contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
PageData startPage = contentRepository.Get<PageData>(ContentReference.StartPage);
using (MemoryStream memoryStream = new MemoryStream())
{
using (Document document = new Document(PageSize.A4))
{
PdfWriter.GetInstance(document, memoryStream);
document.AddCreationDate();
string author = page["Author"] as string;
string title = page["Title"] as string;
XhtmlString pdfHeader = startPage["PdfHeader"] as XhtmlString;
XhtmlString pdfFooter = startPage["PdfFooter"] as XhtmlString;
if (!string.IsNullOrWhiteSpace(author))
{
document.AddAuthor(author);
}
document.AddTitle(!string.IsNullOrWhiteSpace(title) ? title : page.Name);
document.Open();
Dictionary<string, object> providers = new Dictionary<string, object>
{
{
HTMLWorker.IMG_PROVIDER,
new ImageProvider(
document)
}
};
StyleSheet styleSheet = OutputHelper.GetStyleSheet();
try
{
Paragraph paragraph = new Paragraph(!string.IsNullOrWhiteSpace(title) ? title : page.Name);
document.Add(paragraph);
// Add the header
if (pdfHeader != null && !pdfHeader.IsEmpty)
{
using (StringReader stringReader = new StringReader(pdfHeader.ToHtmlString()))
{
foreach (IElement element in
HTMLWorker.ParseToList(stringReader, styleSheet, providers))
{
document.Add(element);
}
}
}
// Add the selected properties
foreach (KeyValuePair<string, string> content in propertyValues)
{
using (StringReader stringReader = new StringReader(content.Value))
{
foreach (IElement element in
HTMLWorker.ParseToList(stringReader, styleSheet, providers))
{
document.Add(element);
}
}
document.Add(new Chunk(Environment.NewLine));
}
// Add the footer
if (pdfFooter != null && !pdfFooter.IsEmpty)
{
using (StringReader stringReader = new StringReader(pdfFooter.ToHtmlString()))
{
foreach (IElement element in
HTMLWorker.ParseToList(stringReader, styleSheet, providers))
{
document.Add(element);
}
}
}
}
catch (Exception exception)
{
Paragraph paragraph = new Paragraph("Error!" + exception.Message);
Chunk text = paragraph.Chunks[0];
if (text != null)
//.........这里部分代码省略.........