本文整理汇总了C#中XpsDocument.Close方法的典型用法代码示例。如果您正苦于以下问题:C# XpsDocument.Close方法的具体用法?C# XpsDocument.Close怎么用?C# XpsDocument.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XpsDocument
的用法示例。
在下文中一共展示了XpsDocument.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Window_Loaded
private void Window_Loaded(object sender, EventArgs e)
{
XpsDocument doc = new XpsDocument("test.xps", FileAccess.ReadWrite);
docViewer.Document = doc.GetFixedDocumentSequence();
doc.Close();
}
示例3: ViewDocument
public void ViewDocument(string fileName)
{
if (System.IO.File.Exists(fileName) == true)
{
XpsDocument xpsDocument = new XpsDocument(fileName, System.IO.FileAccess.Read);
this.Viewer.Document = xpsDocument.GetFixedDocumentSequence();
xpsDocument.Close();
}
}
示例4: LoadQuickStartToDocummentViewer
private void LoadQuickStartToDocummentViewer()
{
string fileName = @"Quick Start Guide.xps";
XpsDocument document = new XpsDocument(fileName, FileAccess.Read);
this.documentViewer.Document = document.GetFixedDocumentSequence();
document.Close();
this.documentViewer.FitToWidth();
var contentHost = this.documentViewer.Template.FindName("PART_ContentHost", this.documentViewer) as ScrollViewer;
var grid = contentHost?.Parent as Grid;
grid?.Children.RemoveAt(0);
}
示例5: button2_Click
private void button2_Click(object sender, RoutedEventArgs e)
{
string filename = "Test.txt";
File.Delete(filename);
XpsDocument doc = new XpsDocument(filename, System.IO.FileAccess.ReadWrite);
XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
//PageContent content = CreateFifthPageContent();
FixedPage page = CreateFifthPageContent();
//page.conten
// page.
xpsdw.Write(page);
doc.Close();
}
示例6: SaveToFile
internal void SaveToFile(string fileName)
{
Transform transform = canvasContainer.LayoutTransform;
canvasContainer.LayoutTransform = null;
Size size = new Size(canvasContainer.Width, canvasContainer.Height);
canvasContainer.Measure(size);
canvasContainer.Arrange(new Rect(size));
Package package = Package.Open(fileName, System.IO.FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
writer.Write(canvasContainer);
doc.Close();
package.Close();
canvasContainer.LayoutTransform = transform;
}
示例7: LoadDocument
/// <summary>
/// Loads the specified DocumentPaginatorWrapper document for print preview.
/// </summary>
public void LoadDocument(DocumentPaginatorWrapper document)
{
m_Document = document;
string temp = System.IO.Path.GetTempFileName();
if (File.Exists(temp))
{
File.Delete(temp);
}
XpsDocument xpsDoc = new XpsDocument(temp, FileAccess.ReadWrite);
XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
xpsWriter.Write(document);
documentViewer.Document = xpsDoc.GetFixedDocumentSequence();
xpsDoc.Close();
}
示例8: SaveVisualToByteArray
/// <summary>
/// Store a visual in an array of bytes.
/// </summary>
/// <param name="v">The <see cref="Visual"/> to serialise.</param>
/// <returns>The serialised <see cref="Visual"/>.</returns>
public static byte[] SaveVisualToByteArray(this Visual v)
{
// Open new package
MemoryStream stream = new MemoryStream();
Package package = Package.Open(stream, FileMode.Create);
// Create new xps document based on the package opened
XpsDocument doc = new XpsDocument(package);
// Create an instance of XpsDocumentWriter for the document
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
// Write the Visual to the document
writer.Write(v);
// Close document
doc.Close();
// Close package
package.Close();
return stream.ToArray();
}
示例9: Xps_Click
private void Xps_Click(object sender, RoutedEventArgs e)
{
FixedPage page = new FixedPage() { Background = Brushes.White, Width = Dpi * PaperWidth, Height = Dpi * PaperHeight };
TextBlock tbTitle = new TextBlock { Text = "My InkCanvas Sketch", FontSize = 24, FontFamily = new FontFamily("Arial") };
FixedPage.SetLeft(tbTitle, Dpi * 0.75);
FixedPage.SetTop(tbTitle, Dpi * 0.75);
page.Children.Add((UIElement)tbTitle);
var toPrint = myInkCanvasBorder;
myGrid.Children.Remove(myInkCanvasBorder);
FixedPage.SetLeft(toPrint, Dpi * 2);
FixedPage.SetTop(toPrint, Dpi * 2);
page.Children.Add(toPrint);
Size sz = new Size(Dpi * PaperWidth, Dpi * PaperHeight);
page.Measure(sz);
page.Arrange(new Rect(new Point(), sz));
page.UpdateLayout();
var filepath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "PrintingTest");
if (!File.Exists(filepath))
Directory.CreateDirectory(filepath);
var filename = System.IO.Path.Combine(filepath, "myXpsFile.xps");
FixedDocument doc = new FixedDocument();
PageContent pageContent = new PageContent();
((System.Windows.Markup.IAddChild)pageContent).AddChild(page);
doc.Pages.Add(pageContent);
XpsDocument xpsd = new XpsDocument(filename, FileAccess.Write);
XpsDocument.CreateXpsDocumentWriter(xpsd).Write(doc); //requires System.Printing namespace
xpsd.Close();
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
printDialog.PrintQueue.AddJob("MyInkCanvas print job", filename, true);
page.Children.Remove(toPrint);
myGrid.Children.Add(toPrint);
}
示例10: cmdShowFlow_Click
private void cmdShowFlow_Click(object sender, RoutedEventArgs e)
{
if (File.Exists("test2.xps")) File.Delete("test2.xps");
using (FileStream fs = File.Open("FlowDocument1.xaml", FileMode.Open))
{
FlowDocument doc = (FlowDocument)XamlReader.Load(fs);
XpsDocument xpsDocument = new XpsDocument("test2.xps", FileAccess.ReadWrite);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
writer.Write(((IDocumentPaginatorSource)doc).DocumentPaginator);
// Display the new XPS document in a viewer.
docViewer.Document = xpsDocument.GetFixedDocumentSequence();
xpsDocument.Close();
}
}
示例11: LoadDocument
/// <summary>
/// Loads the specified FlowDocument document for print preview.
/// </summary>
public void LoadDocument(FlowDocument document)
{
mDocument = document;
string temp = System.IO.Path.GetTempFileName();
if (File.Exists(temp) == true)
File.Delete(temp);
XpsDocument xpsDoc = new XpsDocument(temp, FileAccess.ReadWrite);
XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
xpsWriter.Write(((FlowDocument)document as IDocumentPaginatorSource).DocumentPaginator);
documentViewer.Document = xpsDoc.GetFixedDocumentSequence();
xpsDoc.Close();
}
示例12: ConvertToXps
/// <summary>
/// Convert a FixedDocument to an XPS file.
/// </summary>
/// <param name="fixedDoc">The FixedDocument to convert.</param>
/// <param name="outputStream">The output stream.</param>
public static void ConvertToXps(FixedDocument fixedDoc, Stream outputStream)
{
var package = Package.Open(outputStream, FileMode.Create);
var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
// xps documents are built using fixed document sequences
var fixedDocSeq = new FixedDocumentSequence();
var docRef = new DocumentReference();
docRef.BeginInit();
docRef.SetDocument(fixedDoc);
docRef.EndInit();
((IAddChild)fixedDocSeq).AddChild(docRef);
// write out our fixed document to xps
xpsWriter.Write(fixedDocSeq.DocumentPaginator);
xpsDoc.Close();
package.Close();
}
示例13: Print
public static void Print(List<object> printCollection,
String FinalTargetFileName, String HeadLineText, String PrintPageOrientation = "Portrait")
{
PrintDialog PrtDialog = new PrintDialog();
LocalPrintServer LPS = new LocalPrintServer();
PrintQueue DefaultPrinterQueue = LocalPrintServer.GetDefaultPrintQueue();
PrintTicket DefaultTicket = DefaultPrinterQueue.DefaultPrintTicket;
PrintCapabilities DefaultCapabilities = DefaultPrinterQueue.GetPrintCapabilities(DefaultTicket);
if (PrintPageOrientation == "Landscape")
PrtDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
else
PrtDialog.PrintTicket.PageOrientation = PageOrientation.Portrait;
PAPER_SIZE_WIDTH = PrtDialog.PrintableAreaWidth;
PAPER_SIZE_HEIGHT = PrtDialog.PrintableAreaHeight;
TOP_MARGIN = PrtDialog.PrintableAreaHeight * 0.08;
SIDE_MARGIN = PrtDialog.PrintableAreaWidth * 0.08;
double MaxOWidth = PAPER_SIZE_WIDTH - (2 * SIDE_MARGIN);
double MaxOHeight = PAPER_SIZE_HEIGHT - (2 * TOP_MARGIN) - 20;
FixedDocument PageDocumentToPrint = new FixedDocument();
DefinitionsForPrintWithXAMLControls XAMLDefinitionsForOnePage = GenerateNewContent(PageDocumentToPrint);
ObservableCollection<object> PageCollection = XAMLDefinitionsForOnePage.GlobalContainer.ItemsSource as ObservableCollection<object>;
int NumberOfPages = CreatePages (XAMLDefinitionsForOnePage, PageDocumentToPrint, MaxOHeight, printCollection,
PageCollection, HeadLineText);
XpsDocument XpsDoc = new XpsDocument(FinalTargetFileName, FileAccess.Write);
XpsDocumentWriter XpsWriter = XpsDocument.CreateXpsDocumentWriter(XpsDoc);
XpsWriter.Write(PageDocumentToPrint.DocumentPaginator);
XpsDoc.Close();
}
示例14: FlowDocumentToPDF
public void FlowDocumentToPDF(DocumentPaginator paginator, string filename, string reportName, bool overWrite)
{
MemoryStream lMemoryStream = new MemoryStream();
Package package = Package.Open(lMemoryStream, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
XpsPackagingPolicy packagePolicy = new XpsPackagingPolicy(doc);
XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, false);
writer.Write(paginator);
doc.Close();
package.Close();
var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(lMemoryStream);
PdfSharp.Xps.XpsConverter.Convert(pdfXpsDoc, filename, 0);
pdfXpsDoc.Close();
}
示例15: Save
public void Save()
{
if (Uri == null)
{
throw new ArgumentException("Uri has not been specified");
}
var xpsDocument = new XpsDocument(Uri.OriginalString, FileAccess.ReadWrite);
var xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
xpsDocumentWriter.Write(FixedDocumentSequence);
xpsDocument.Close();
}