本文整理汇总了C#中System.Windows.Documents.FlowDocument类的典型用法代码示例。如果您正苦于以下问题:C# FlowDocument类的具体用法?C# FlowDocument怎么用?C# FlowDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FlowDocument类属于System.Windows.Documents命名空间,在下文中一共展示了FlowDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public void Write(string outputPath, FlowDocument doc)
{
Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
Font textFont = new Font(baseFont, DEFAULT_FONTSIZE, Font.NORMAL, BaseColor.BLACK);
Font headingFont = new Font(baseFont, DEFAULT_HEADINGSIZE, Font.BOLD, BaseColor.BLACK);
using (FileStream stream = new FileStream(outputPath, FileMode.Create))
{
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
foreach (Block i in doc.Blocks) {
if (i is System.Windows.Documents.Paragraph)
{
TextRange range = new TextRange(i.ContentStart, i.ContentEnd);
Console.WriteLine(i.Tag);
switch (i.Tag as string)
{
case "Paragraph": iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(range.Text, textFont);
par.Alignment = Element.ALIGN_JUSTIFIED;
pdfDoc.Add(par);
break;
case "Heading": iTextSharp.text.Paragraph head = new iTextSharp.text.Paragraph(range.Text, headingFont);
head.Alignment = Element.ALIGN_CENTER;
head.SpacingAfter = 10;
pdfDoc.Add(head);
break;
default: iTextSharp.text.Paragraph def = new iTextSharp.text.Paragraph(range.Text, textFont);
def.Alignment = Element.ALIGN_JUSTIFIED;
pdfDoc.Add(def);
break;
}
}
else if (i is System.Windows.Documents.List)
{
iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.UNORDERED, 10f);
list.SetListSymbol("\u2022");
list.IndentationLeft = 15f;
foreach (var li in (i as System.Windows.Documents.List).ListItems)
{
iTextSharp.text.ListItem listitem = new iTextSharp.text.ListItem();
TextRange range = new TextRange(li.Blocks.ElementAt(0).ContentStart, li.Blocks.ElementAt(0).ContentEnd);
string text = range.Text.Substring(1);
iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(text, textFont);
listitem.SpacingAfter = 10;
listitem.Add(par);
list.Add(listitem);
}
pdfDoc.Add(list);
}
}
if (pdfDoc.PageNumber == 0)
{
iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(" ");
par.Alignment = Element.ALIGN_JUSTIFIED;
pdfDoc.Add(par);
}
pdfDoc.Close();
}
}
示例2: ZTextBufferWindow
public ZTextBufferWindow(ZWindowManager manager, FontAndColorService fontAndColorService)
: base(manager, fontAndColorService)
{
this.normalFontFamily = new FontFamily("Cambria");
this.fixedFontFamily = new FontFamily("Consolas");
var zero = new FormattedText(
textToFormat: "0",
culture: CultureInfo.InstalledUICulture,
flowDirection: FlowDirection.LeftToRight,
typeface: new Typeface(normalFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
emSize: this.FontSize,
foreground: Brushes.Black);
this.fontCharSize = new Size(zero.Width, zero.Height);
this.document = new FlowDocument
{
FontFamily = normalFontFamily,
FontSize = this.FontSize,
PagePadding = new Thickness(8.0)
};
this.paragraph = new Paragraph();
this.document.Blocks.Add(this.paragraph);
this.scrollViewer = new FlowDocumentScrollViewer
{
FocusVisualStyle = null,
Document = this.document
};
this.Children.Add(this.scrollViewer);
}
示例3: UndoMyEditAction
public UndoMyEditAction(int columnId, bool isInlineNote, FlowDocument document, UVEditUndoAction undoAction)
{
__ColumnId = columnId;
__IsInlineNote = isInlineNote;
__DocumentGuid = (Guid)document.Tag;
__UndoAction = undoAction;
}
示例4: CreateDocument
static FlowDocument CreateDocument(Project project, Lessee lessee, bool overview) {
var doc = new FlowDocument();
if ( lessee != null && !overview ) {// Print 1 page for a single lessee
WritePage(doc, new Lessee[] { lessee }, project, false, true);
} else if ( lessee == null && overview ) {// Partition lessees 8 at a time
int i = 0;
var list = new List<Lessee>();
foreach ( Lessee l in project.Result.Lessees.Keys.OrderBy(l => l.Name) ) {
list.Add(l);
if ( ++i == 8 ) {
WritePage(doc, list, project, true, false);
i = 0;
list = new List<Lessee>();
}
}
if ( i > 6 ) {
WritePage(doc, list.Take(6).ToList(), project, true, false);
WritePage(doc, new Lessee[] { list[list.Count - 1] }, project, true, true);
} else WritePage(doc, list, project, true, true);
} else if ( lessee == null && !overview ) {// Print 1 page per lessee for all lessees
foreach ( Lessee l in project.Result.Lessees.Keys ) {
WritePage(doc, new Lessee[] { l }, project, false, false);
}
} else {
throw new ArgumentException("Arguments invalid");
}
return doc;
}
示例5: RotateContainers
public FlowDocument RotateContainers(Object data)
{
var doc = new FlowDocument();
if (data is ObservableCollection<Vehicle>)
{
vehicles = (ObservableCollection<Vehicle>)data;
doc = ShowVehicles();
}
else if (data is List<VerticalBlock>)
{
vBlocks = (List<VerticalBlock>)data;
doc = ShowVerticalBlocks();
}
else if (data is List<RowBlock>)
{
rBlocks = (List<RowBlock>)data;
doc = ShowRowBlocks();
}
else if (data is List<Container>)
{
containers = (List<Container>)data;
doc = ShowContainers();
}
else
{
MessageBox.Show("В форму отчета передан неверный тип данных:" + data.GetType());
return null;
}
return doc;
}
示例6: OnBoundDocumentChanged
private static void OnBoundDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RichTextBox box = d as RichTextBox;
if (box == null)
return;
RemoveEventHandler(box);
string newXAML = GetBoundDocument(d);
box.Document.Blocks.Clear();
if (!string.IsNullOrEmpty(newXAML))
{
using (MemoryStream xamlMemoryStream = new MemoryStream(Encoding.ASCII.GetBytes(newXAML)))
{
ParserContext parser = new ParserContext();
parser.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
parser.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
FlowDocument doc = new FlowDocument();
Section section = XamlReader.Load(xamlMemoryStream, parser) as Section;
box.Document.Blocks.Add(section);
}
}
AttachEventHandler(box);
}
示例7: ReportPaginator
/// <summary>
/// Constructor
/// </summary>
/// <param name="report">report document</param>
/// <param name="data">report data</param>
/// <exception cref="ArgumentException">Flow document must have a specified page height</exception>
/// <exception cref="ArgumentException">Flow document must have a specified page width</exception>
/// <exception cref="ArgumentException">Flow document can have only one report header section</exception>
/// <exception cref="ArgumentException">Flow document can have only one report footer section</exception>
public ReportPaginator(ReportDocument report, ReportData data)
{
_report = report;
_data = data;
_flowDocument = report.CreateFlowDocument();
_pageSize = new Size(_flowDocument.PageWidth, _flowDocument.PageHeight);
if (_flowDocument.PageHeight == double.NaN) throw new ArgumentException("Flow document must have a specified page height");
if (_flowDocument.PageWidth == double.NaN) throw new ArgumentException("Flow document must have a specified page width");
_dynamicCache = new ReportPaginatorDynamicCache(_flowDocument);
ArrayList listPageHeaders = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportHeader));
if (listPageHeaders.Count > 1) throw new ArgumentException("Flow document can have only one report header section");
if (listPageHeaders.Count == 1) _blockPageHeader = (SectionReportHeader)listPageHeaders[0];
ArrayList listPageFooters = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportFooter));
if (listPageFooters.Count > 1) throw new ArgumentException("Flow document can have only one report footer section");
if (listPageFooters.Count == 1) _blockPageFooter = (SectionReportFooter)listPageFooters[0];
_paginator = ((IDocumentPaginatorSource)_flowDocument).DocumentPaginator;
// remove header and footer in our working copy
Block block = _flowDocument.Blocks.FirstBlock;
while (block != null)
{
Block thisBlock = block;
block = block.NextBlock;
if ((thisBlock == _blockPageHeader) || (thisBlock == _blockPageFooter)) _flowDocument.Blocks.Remove(thisBlock);
}
// get report context values
_reportContextValues = _dynamicCache.GetFlowDocumentVisualListByInterface(typeof(IInlineContextValue));
FillData();
}
示例8: AddTextToRTF
private static void AddTextToRTF(FlowDocument myFlowDoc, string text)
{
var para = new Paragraph();
var run = new Run(text);
para.Inlines.Add(run);
myFlowDoc.Blocks.Add(para);
}
示例9: AddBlock
public static void AddBlock(Block from, FlowDocument to)
{
if (from != null)
{
//if (from is ItemsContent)
//{
// ((ItemsContent)from).RunBeforeCopy();
//}
//else
{
TextRange range = new TextRange(from.ContentStart, from.ContentEnd);
MemoryStream stream = new MemoryStream();
System.Windows.Markup.XamlWriter.Save(range, stream);
range.Save(stream, DataFormats.XamlPackage);
TextRange textRange2 = new TextRange(to.ContentEnd, to.ContentEnd);
textRange2.Load(stream, DataFormats.XamlPackage);
}
}
}
示例10: FormatBlocks
public void FormatBlocks(FlowDocument doc, BlockCollection blocks, StringBuilder buf, int indent)
{
foreach (Block block in blocks)
{
FormatBlock (doc, block, buf, indent);
}
}
示例11: FormatDocument
public string FormatDocument(FlowDocument doc)
{
StringBuilder buf = new StringBuilder ();
FormatBlocks (doc, doc.Blocks, buf, 0);
return buf.ToString ();
}
示例12: GetRunsAndParagraphs
private static IEnumerable<TextElement> GetRunsAndParagraphs(FlowDocument doc)
{
for (TextPointer position = doc.ContentStart;
position != null && position.CompareTo(doc.ContentEnd) <= 0;
position = position.GetNextContextPosition(LogicalDirection.Forward))
{
if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
{
Run run = position.Parent as Run;
if (run != null)
{
yield return run;
}
else
{
Paragraph para = position.Parent as Paragraph;
if (para != null)
{
yield return para;
}
}
}
}
}
示例13: SubscribeToAllHyperlinks
private void SubscribeToAllHyperlinks(FlowDocument flowDocument)
{
var hyperlinks = GetVisuals(flowDocument).OfType<Hyperlink>();
foreach (var link in hyperlinks) {
link.RequestNavigate += OnRequestNavigate;
}
}
示例14: Print
public static void Print(FlowDocument printedPage)
{
PrintDialog dialog = new PrintDialog();
dialog.PrintTicket = dialog.PrintQueue.DefaultPrintTicket;
dialog.PrintTicket.PageOrientation = PageOrientation.Portrait;
dialog.PrintTicket.OutputQuality = OutputQuality.High;
dialog.PrintTicket.PageBorderless = PageBorderless.None;
dialog.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);
if (dialog.ShowDialog() == true)
{
double pageHeight = printedPage.PageHeight;
double pageWidth = printedPage.PageWidth;
Thickness pagePadding = printedPage.PagePadding;
double columnGap = printedPage.ColumnGap;
double columnWidth = printedPage.ColumnWidth;
printedPage.PageHeight = dialog.PrintableAreaHeight;
printedPage.PageWidth = dialog.PrintableAreaWidth;
printedPage.PagePadding = new Thickness(50);
dialog.PrintDocument(((IDocumentPaginatorSource)printedPage).DocumentPaginator, "");
printedPage.PagePadding = pagePadding;
printedPage.PageHeight = pageHeight;
printedPage.PageWidth = pageWidth;
printedPage.ColumnWidth = columnWidth;
printedPage.ColumnGap = columnGap;
}
}
示例15: Convert
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
{
var text = value as String;
var flowDocument = new FlowDocument();
if (String.IsNullOrEmpty(text))
return flowDocument;
var paragraph = new Paragraph();
using (var reader = new StringReader(text))
{
String line;
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("+++") ||
line.StartsWith("---") ||
line.StartsWith("diff ", StringComparison.OrdinalIgnoreCase))
continue;
paragraph.Inlines.Add(BuildLine(line));
paragraph.Inlines.Add(new LineBreak());
}
}
return paragraph.Inlines;
}