本文整理汇总了C#中XpsDocument类的典型用法代码示例。如果您正苦于以下问题:C# XpsDocument类的具体用法?C# XpsDocument怎么用?C# XpsDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XpsDocument类属于命名空间,在下文中一共展示了XpsDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetXpsDocument
public static XpsDocument GetXpsDocument(FlowDocument document)
{
//Uri DocumentUri = new Uri("pack://currentTicket_" + new Random().Next(1000).ToString() + ".xps");
Uri docUri = new Uri("pack://tempTicket.xps");
var ms = new MemoryStream();
{
Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
PackageStore.RemovePackage(docUri);
PackageStore.AddPackage(docUri, package);
XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, docUri.AbsoluteUri);
XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false);
DocumentPaginator docPage = ((IDocumentPaginatorSource)document).DocumentPaginator;
//docPage.PageSize = new System.Windows.Size(PageWidth, PageHeight);
//docPage.PageSize = new System.Windows.Size(document.PageWidth, document.PageHeight);
rsm.SaveAsXaml(docPage);
return xpsDocument;
}
}
示例2: 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;
}
示例3: Window2_Loaded
void Window2_Loaded(object sender, RoutedEventArgs e)
{
//throw new NotImplementedException();
XpsDocument xpsdoc = new XpsDocument("xml.xps", System.IO.FileAccess.Read);
FixedDocumentSequence fds = xpsdoc.GetFixedDocumentSequence();
documentViewer.Document = fds.References[0].GetDocument(true);
}
示例4: Export
/// <summary>
/// Exports the specified plot model to an xps file.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="fileName">The file name.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="background">The background color.</param>
public static void Export(IPlotModel model, string fileName, double width, double height, OxyColor background)
{
using (var xpsPackage = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite))
{
using (var doc = new XpsDocument(xpsPackage))
{
var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() };
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));
var rc = new ShapesRenderContext(canvas);
#if !NET35
rc.TextFormattingMode = TextFormattingMode.Ideal;
#endif
model.Update(true);
model.Render(rc, width, height);
canvas.UpdateLayout();
var xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
xpsdw.Write(canvas);
}
}
}
示例5: PreviewWindow
public PreviewWindow(CustomDocumentPaginator documentPaginator)
{
InitializeComponent();
//xps
stream = new MemoryStream();
Package package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite);
var uri = new Uri(@"memorystream://myXps.xps");
//already in packagestore, so remove
if (PackageStore.GetPackage(uri) != null)
{
PackageStore.RemovePackage(uri);
}
PackageStore.AddPackage(uri, package);
var xpsDoc = new XpsDocument(package);
xpsDoc.Uri = uri;
XpsDocument.CreateXpsDocumentWriter(xpsDoc).Write(documentPaginator);
FixedDocumentSequence fds = xpsDoc.GetFixedDocumentSequence();
dv1.Document = (IDocumentPaginatorSource)fds;
}
示例6: SaveToPdf
public static void SaveToPdf(this FlowDocument flowDoc, string filename)
{
MemoryStream xamlStream = new MemoryStream();
XamlWriter.Save(flowDoc, xamlStream);
File.WriteAllBytes("d:\\file.xaml", xamlStream.ToArray());
IDocumentPaginatorSource text = flowDoc as IDocumentPaginatorSource;
xamlStream.Close();
MemoryStream memoryStream = new MemoryStream();
Package pkg = Package.Open(memoryStream, FileMode.Create, FileAccess.ReadWrite);
string pack = "pack://temp.xps";
PackageStore.AddPackage(new Uri(pack), pkg);
XpsDocument doc = new XpsDocument(pkg, CompressionOption.SuperFast, pack);
XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
DocumentPaginator pgn = text.DocumentPaginator;
rsm.SaveAsXaml(pgn);
MemoryStream xpsStream = new MemoryStream();
var writer = new XpsSerializerFactory().CreateSerializerWriter(xpsStream);
writer.Write(doc.GetFixedDocumentSequence());
MemoryStream outStream = new MemoryStream();
NiXPS.Converter.XpsToPdf(xpsStream, outStream);
File.WriteAllBytes("file.pdf", outStream.ToArray());
}
示例7: ShowPrintPreview
private void ShowPrintPreview()
{
// We have to clone the FlowDocument before we use different pagination settings for the export.
RichTextDocument document = (RichTextDocument)fileService.ActiveDocument;
FlowDocument clone = document.CloneContent();
clone.ColumnWidth = double.PositiveInfinity;
// Create a package for the XPS document
MemoryStream packageStream = new MemoryStream();
package = Package.Open(packageStream, FileMode.Create, FileAccess.ReadWrite);
// Create a XPS document with the path "pack://temp.xps"
PackageStore.AddPackage(new Uri(PackagePath), package);
xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, PackagePath);
// Serialize the XPS document
XpsSerializationManager serializer = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false);
DocumentPaginator paginator = ((IDocumentPaginatorSource)clone).DocumentPaginator;
serializer.SaveAsXaml(paginator);
// Get the fixed document sequence
FixedDocumentSequence documentSequence = xpsDocument.GetFixedDocumentSequence();
// Create and show the print preview view
PrintPreviewViewModel printPreviewViewModel = printPreviewViewModelFactory.CreateExport().Value;
printPreviewViewModel.Document = documentSequence;
previousView = shellViewModel.ContentView;
shellViewModel.ContentView = printPreviewViewModel.View;
shellViewModel.IsPrintPreviewVisible = true;
printPreviewCommand.RaiseCanExecuteChanged();
}
示例8: window_Loaded
private void window_Loaded(object sender, RoutedEventArgs e)
{
doc = new XpsDocument("ch19.xps", FileAccess.ReadWrite);
docViewer.Document = doc.GetFixedDocumentSequence();
service = AnnotationService.GetService(docViewer);
if (service == null)
{
Uri annotationUri = PackUriHelper.CreatePartUri(new Uri("AnnotationStream", UriKind.Relative));
Package package = PackageStore.GetPackage(doc.Uri);
PackagePart annotationPart = null;
if (package.PartExists(annotationUri))
{
annotationPart = package.GetPart(annotationUri);
}
else
{
annotationPart = package.CreatePart(annotationUri, "Annotations/Stream");
}
// Load annotations from the package.
AnnotationStore store = new XmlStreamStore(annotationPart.GetStream());
service = new AnnotationService(docViewer);
service.Enable(store);
}
}
示例9: SaveToFile
private void SaveToFile()
{
if (Directory.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData") == false)
{ Directory.CreateDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData"); }
string destination = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + " " +
DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + " " + Environment.UserName + " 2dView";
using (var stream = new FileStream(destination+".xps", FileMode.Create))
{
using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
{
using (var xpsDoc = new XpsDocument(package, CompressionOption.Maximum))
{
var rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);
var paginator = ((IDocumentPaginatorSource)FlowDocViewer.Document).DocumentPaginator;
rsm.SaveAsXaml(paginator);
rsm.Commit();
}
}
stream.Position = 0;
var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(stream);
XpsConverter.Convert(pdfXpsDoc, destination + ".pdf", 0);
}
}
示例10: btnXpsDocumentWriter_Click
private void btnXpsDocumentWriter_Click(object sender, RoutedEventArgs e)
{
using (Package xpsPackage = Package.Open("Out.xps", FileMode.Create,
FileAccess.ReadWrite))
using (XpsDocument doc = new XpsDocument(xpsPackage))
{
FixedPage page = new FixedPage();
Canvas canvas = new Canvas();
canvas.Width = 600;
canvas.Height = 400;
page.Children.Add(canvas);
Rectangle rect = new Rectangle();
Canvas.SetLeft(rect, 50);
Canvas.SetTop(rect, 50);
rect.Width = 200;
rect.Height = 100;
rect.Stroke = Brushes.Black;
rect.StrokeThickness = 1;
canvas.Children.Add(rect);
XpsDocumentWriter documentWriter =
XpsDocument.CreateXpsDocumentWriter(doc);
documentWriter.Write(page);
doc.CoreDocumentProperties.Description = "Rectangle Output";
}
}
示例11: ConvertWordToXps
public static XpsDocument ConvertWordToXps(string wordFilename, string xpsFilename)
{
// Create a WordApplication and host word document
Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
try
{
wordApp.Documents.Open(wordFilename);
// To Invisible the word document
wordApp.Application.Visible = false;
// Minimize the opened word document
wordApp.WindowState = WdWindowState.wdWindowStateMinimize;
Document doc = wordApp.ActiveDocument;
doc.SaveAs(xpsFilename, WdSaveFormat.wdFormatXPS);
XpsDocument xpsDocument = new XpsDocument(xpsFilename, FileAccess.Read);
return xpsDocument;
}
catch (Exception ex)
{
MessageBox.Show("Error occurs, The error message is " + ex.ToString());
return null;
}
finally
{
wordApp.Documents.Close();
((_Application)wordApp).Quit(WdSaveOptions.wdDoNotSaveChanges);
}
}
示例12: btnPrint_Click
private void btnPrint_Click(object sender, EventArgs e)
{
//REFACTOR ME
dtgParentReport.Update();
System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
Nullable<bool> print = printDialog.ShowDialog();
if (print == true)
{
try
{
XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
printDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
}
catch (UnauthorizedAccessException e1)
{
const string message =
"Unauthoried to access that printer.";
const string caption = "Unauthoried Access";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
catch (PrintDialogException e2)
{
const string message =
"Unknow error occurred.";
const string caption = "Error Printing";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
示例13: Concat
public static void Concat(string targetFileName, params string[] filesToConcat)
{
var fixedDocumentSequence = new FixedDocumentSequence();
var tempFileName = Path.GetTempFileName();
using (var target = new XpsDocument(tempFileName, FileAccess.Write))
{
var xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(target);
if (filesToConcat != null)
{
foreach (var doc in filesToConcat)
{
Add(doc, fixedDocumentSequence);
}
}
xpsDocumentWriter.Write(fixedDocumentSequence);
}
if (File.Exists(targetFileName))
{
File.Delete(targetFileName);
}
File.Move(tempFileName, targetFileName);
}
示例14: InternalCreateFileFromXaml
private static CreateXpsFileResult InternalCreateFileFromXaml(FrameworkElement template, object dataContext)
{
string xpsFile = Path.GetTempFileName() + ".xps";
using (var container = Package.Open(xpsFile, FileMode.Create))
using (var document = new XpsDocument(container, CompressionOption.SuperFast))
{
var coupon = template;
coupon.DataContext = dataContext;
coupon.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
coupon.UpdateLayout();
var ticket = new PrintTicket()
{
PageMediaSize = new PageMediaSize(coupon.DesiredSize.Width, coupon.DesiredSize.Height)
};
XpsDocument.CreateXpsDocumentWriter(document).Write(coupon, ticket);
return new CreateXpsFileResult()
{
Path = xpsFile,
Ticket = ticket
};
}
}
示例15: Print
public void Print()
{
MemoryStream xpsStream = new MemoryStream();
Package pack = Package.Open(xpsStream, FileMode.CreateNew);
string inMemPackageName= "memorystream://myXps.xps";
Uri packageUri = new Uri(inMemPackageName);
PackageStore.AddPackage(packageUri, pack);
XpsDocument xpsDoc = new XpsDocument(pack, CompressionOption.SuperFast, inMemPackageName);
XpsDocumentWriter xpsDocWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
FixedDocument doc = CreatePawnTicket();
//DocumentPaginator documentPaginator = (FlowDocument)IDocumentPaginatorSource).DocumentPaginator;
//documentPaginator = New DocumentPaginatorWrapper(documentPaginator, pageSize, margin, documentStatus, firstPageHeaderPath, primaryHeaderPath)
xpsDocWriter.Write(doc);
//Package package =
//XpsDocument xpsd = new XpsDocument((filename, FileAccess.ReadWrite);
// //XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
// xw.Write(doc);
// xpsd.Close();
}