本文整理汇总了C#中System.Windows.Documents.FixedDocument类的典型用法代码示例。如果您正苦于以下问题:C# FixedDocument类的具体用法?C# FixedDocument怎么用?C# FixedDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FixedDocument类属于System.Windows.Documents命名空间,在下文中一共展示了FixedDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFixedDocument
public static FixedDocument CreateFixedDocument(double pageWidth, double pageHeight, UIElement content)
{
if (content == null)
{
throw new ArgumentNullException("content");
}
if (pageWidth <= 0 || pageHeight <= 0)
{
throw new ArgumentOutOfRangeException();
}
RenderTargetBitmap renderTarget = new RenderTargetBitmap(Convert.ToInt32(content.RenderSize.Width), Convert.ToInt32(content.RenderSize.Height),
Constants.ScreenDPI, Constants.ScreenDPI, PixelFormats.Pbgra32);
renderTarget.Render(content);
FixedDocument doc = new FixedDocument();
Size pageSize = new Size(pageWidth, pageHeight);
doc.DocumentPaginator.PageSize = pageSize;
FixedPage fixedPage = new FixedPage();
fixedPage.Width = pageWidth;
fixedPage.Height = pageHeight;
Image image = new Image();
image.Height = pageHeight;
image.Width = pageWidth;
image.Stretch = Stretch.Uniform;
image.StretchDirection = StretchDirection.Both;
image.Source = renderTarget;
fixedPage.Children.Add(image);
PageContent pageContent = new PageContent();
((IAddChild)pageContent).AddChild(fixedPage);
doc.Pages.Add(pageContent);
return doc;
}
示例2: ShowFixedDocument
/// <summary>
/// Displays the <see cref="FixedDocument" /> in a <see cref="DocumentViewer" />
/// </summary>
/// <param name="fixedDocument">The fixed document to display.</param>
/// <param name="title">Title of the preview window</param>
/// <param name="windowProvider">An implementation for creating a customized window. If null, default implementation is used.</param>
public static void ShowFixedDocument(FixedDocument fixedDocument, string title, IWindowProvider windowProvider = null)
{
var tempFileName = Path.GetTempFileName();
WriteXps(fixedDocument, tempFileName);
ShowXps(tempFileName, title, windowProvider);
}
示例3: btnPrint_Click_1
private void btnPrint_Click_1(object sender, RoutedEventArgs e)
{
var printControl = new SummaryControl();
printControl.DataContext = _reservation;
printControl.Width = 8.27 * 96;
printControl.Height = 11.69 * 96;
//Create a fixed Document and Print the document
FixedDocument fixedDoc = new FixedDocument();
PageContent pageContent = new PageContent();
FixedPage fixedPage = new FixedPage();
fixedPage.Height = 11.69 * 96;
fixedPage.Width = 8.27 * 96;
fixedPage.Children.Add(printControl);
((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
//dialog.PrintVisual(_PrintCanvas, "My Canvas");
dialog.PrintDocument(fixedDoc.DocumentPaginator, "Print label");
}
}
示例4: GenerateFixedDocumentFromText
/// <summary>
/// Builds FixedDocument from string.
/// </summary>
/// <param name="text">Text to use.</param>
/// <returns>FixedDocument of text.</returns>
public static FixedDocument GenerateFixedDocumentFromText(string text)
{
FixedDocument document = new FixedDocument();
PageContent content = GeneratePageFromText(text);
document.Pages.Add(content);
return document;
}
示例5: SaveFixedDocumentAsTiff
public static void SaveFixedDocumentAsTiff(FixedDocument document, string outputFileName)
{
int pages = document.DocumentPaginator.PageCount;
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Compression = TiffCompressOption.Ccitt4;
for (int pageNum = 0; pageNum < pages; pageNum++)
{
DocumentPage docPage = document.DocumentPaginator.GetPage(pageNum);
RenderTargetBitmap renderTarget =
new RenderTargetBitmap((int)(docPage.Size.Width * 300 / 96),
(int)(docPage.Size.Height * 300 / 96),
300d, // WPF (Avalon) units are 96dpi based
300d,
System.Windows.Media.PixelFormats.Default);
renderTarget.Render(docPage.Visual);
encoder.Frames.Add(BitmapFrame.Create(renderTarget));
}
FileStream outputFileStream = new FileStream(outputFileName, FileMode.Create);
encoder.Save(outputFileStream);
outputFileStream.Close();
}
示例6: Start
public override void Start()
{
base.Start();
document = new FixedDocument();
// point 595x842
// 827/1169
// A4 paper is 210mm x 297mm
//8.2 inch x 11.6 inch
//1240 px x 1754 px
/*
iTextSharp uses a default of 72 pixels per inch.
792 would be 11", or the height of a standard Letter size paper." +
595 would be 8.264",
which is the standard width of A4 size paper.
Using 595 x 792 as the page size would be a cheap and dirty way
to ensure that you could print on either A4 or Letter
without anything getting cut off. –
*/
docCreator.PageSize = new System.Windows.Size(reportSettings.PageSize.Width,reportSettings.PageSize.Height);
document.DocumentPaginator.PageSize = docCreator.PageSize;
}
示例7: FixedDocumentFromImageStream
public static FixedDocument FixedDocumentFromImageStream(Stream[] ImagesStream)
{
FixedDocument fdReturn = new FixedDocument();
foreach (Stream streamImage in ImagesStream)
{
FixedPage fpFromImage = new FixedPage();
var bitImage = new BitmapImage();
bitImage.BeginInit();
bitImage.StreamSource = streamImage;
bitImage.DecodePixelWidth = 250;
bitImage.CacheOption = BitmapCacheOption.OnLoad;
bitImage.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
bitImage.EndInit();
bitImage.StreamSource.Seek(0, System.IO.SeekOrigin.Begin);
bitImage.Freeze();
var tempImage = new System.Windows.Controls.Image { Source = bitImage };
//var imageObject = new ImageObject(tempImage, fileName);
fpFromImage.Children.Add(tempImage);
fdReturn.Pages.Add(new PageContent() { Child = fpFromImage });
bitImage.StreamSource.Dispose();
}
return fdReturn;
}
示例8: print_btn_Click
private void print_btn_Click(object sender, RoutedEventArgs e)
{
try
{
report.report_cr_dr p = new BMS.report.report_cr_dr();
p.lst_balance.ItemsSource = dr;
p.r_date.Content = DateTime.Now.Date.ToShortDateString();
p.r_name.Content = "Top Debitors";
PrintDialog pd = new PrintDialog();
FixedDocument document = new FixedDocument();
document.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11);
FixedPage page1 = new FixedPage();
page1.Width = document.DocumentPaginator.PageSize.Width;
page1.Height = document.DocumentPaginator.PageSize.Height;
Canvas can = p.layout;
page1.Children.Add(can);
PageContent page1Content = new PageContent();
((IAddChild)page1Content).AddChild(page1);
document.Pages.Add(page1Content);
pd.PrintDocument(document.DocumentPaginator, "My first document");
}
catch (Exception ex)
{
MessageBox.Show("Sorry some system error has occour please try again");
}
}
示例9: Convert
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
{
var document = value as Document;
if (document == null)
return null;
FrameworkContentElement content;
DocumentRenderTargetBase target;
if (DocumentType == PresentationDocumentType.FixedDocument) {
var fixedDocument = new FixedDocument();
target = new FixedDocumentRenderTarget(fixedDocument);
content = fixedDocument;
}
else {
var flowDocument = new FlowDocument();
target = new FlowDocumentRenderTarget(flowDocument);
content = flowDocument;
}
target.Background = Background;
target.FontFamily = FontFamily;
target.FontSize = FontSize;
target.FontStretch = FontStretch;
target.FontStyle = FontStyle;
target.FontWeight = FontWeight;
ConsoleRenderer.RenderDocument(document, target, new Rect(new Size(ConsoleWidth, Size.Infinity)));
return content;
}
示例10: SaveXPS
public static bool SaveXPS(FixedPage page, bool isSaved)
{
FixedDocument fixedDoc = new FixedDocument();//创建一个文档
fixedDoc.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11);
PageContent pageContent = new PageContent();
((IAddChild)pageContent).AddChild(page);
fixedDoc.Pages.Add(pageContent);//将对象加入到当前文档中
string containerName = GetXPSFromDialog(isSaved);
if (containerName != null)
{
try
{
File.Delete(containerName);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
XpsDocument _xpsDocument = new XpsDocument(containerName, FileAccess.Write);
XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);
xpsdw.Write(fixedDoc);//写入XPS文件
_xpsDocument.Close();
return true;
}
else return false;
}
示例11: CreateFixedDocument
static FixedDocument CreateFixedDocument(ReportSettings reportSettings)
{
var document = new FixedDocument();
document.DocumentPaginator.PageSize = new System.Windows.Size(reportSettings.PageSize.Width,
reportSettings.PageSize.Height);
return document;
}
示例12: AddPageToDocument
static void AddPageToDocument(FixedDocument fixedDocument,FixedPage page)
{
PageContent pageContent = new PageContent();
((IAddChild)pageContent).AddChild(page);
fixedDocument.Pages.Add(pageContent);
}
示例13: PrintPreview_Click
private void PrintPreview_Click(object sender, RoutedEventArgs e)
{
var printdialog = new PrintDialog();
if (printdialog.ShowDialog() != true) { return; }
var doc = new FixedDocument();
doc.DocumentPaginator.PageSize = new Size(printdialog.PrintableAreaWidth, printdialog.PrintableAreaHeight);
var queue = printdialog.PrintQueue;
var caps = queue.GetPrintCapabilities();
var area = caps.PageImageableArea;
var marginwidth = (printdialog.PrintableAreaWidth - caps.PageImageableArea.ExtentWidth) / 2.0;
var marginheight = (printdialog.PrintableAreaHeight - caps.PageImageableArea.ExtentHeight) / 2.0;
double gutter;
if (!Double.TryParse(GutterWidthTextbox.Text, out gutter)) { gutter = 0.25; }
// Translate inches to device independent pixels
gutter *= 96.0;
var opts = new PrintOptions
{
PrintableWidth = area.ExtentWidth,
PrintableHeight = area.ExtentHeight,
MarginWidth = marginwidth,
MarginHeight = marginheight,
Gutter = gutter
};
var category = (CardCategory)DataContext;
category.AddPagesToDocument(doc, opts, category.SelectedCards);
var preview = new PrintPreview();
preview.Document = doc;
preview.ShowDialog();
}
示例14: printing_2
public void printing_2(Grid grid_table_print)
{
DocumentViewer documentViewer1 = new DocumentViewer();
FixedDocument fixedDoc = new FixedDocument();
PageContent pgc = new PageContent();
FixedPage fxp = new FixedPage();
//A4
fxp.Width = 11.69 * 96;
fxp.Height = 8.27 * 96;
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Vertical;
panel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
panel.Width = (11.69 * 96) * 0.9;
panel.Orientation = Orientation.Vertical;
Thickness margin = panel.Margin;
margin.Bottom = 0;
margin.Left = 50;
margin.Top = 50;
margin.Right = 25;
panel.Margin = margin;
BitmapImage bmp_ = new BitmapImage();
Label test_lb = new Label();
test_lb.Content = "\n\n\t\t\tРежим расчетов \n \tОцифровка в автоматическом режиме";
margin = test_lb.Margin;
margin.Bottom = 50;
margin.Left = 50;
margin.Top = 50;
margin.Right = 0;
test_lb.BorderThickness = margin;
panel.Children.Add(test_lb);
ImageSource imageSource = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\file.jpg"));
Image img = new Image();
img.Source = imageSource;
panel.Children.Add(img);
Grid grid_table_print_copy = new Grid();// { DataContext = grid_table_print.DataContext };
string gridXaml = XamlWriter.Save(grid_table_print);
StringReader stringReader = new StringReader(gridXaml);
XmlReader xmlReader = XmlReader.Create(stringReader);
grid_table_print_copy = (Grid)XamlReader.Load(xmlReader);
panel.Children.Add(grid_table_print_copy);
fxp.Children.Add(panel);
((System.Windows.Markup.IAddChild)pgc).AddChild(fxp);
fixedDoc.Pages.Add(pgc);
documentViewer1.Document = fixedDoc;
Window ShowWindow = new Window();
ShowWindow.Width = 850;
ShowWindow.Height = 850;
ShowWindow.Content = documentViewer1;
ShowWindow.Show();
}
示例15: GenerateReport
protected FixedDocument GenerateReport(Func<int, object> frameDataContext, Size paperSize, Margins margins, IEnumerable records)
{
var document = new FixedDocument();
document.DocumentPaginator.PageSize = new Size(DPI * paperSize.Width, DPI * paperSize.Height);
foreach (var page in CreatePages(frameDataContext, paperSize, margins, records))
{
document.Pages.Add(page);
}
return document;
}