我正在尝试允许用户在保存或打印文档之前使用触摸屏对文档进行注释。从本质上讲,我用代码将文档组装成三个部分-一个包含在第三方应用程序中创建的动态文本的“图片”的ImageBrush,一个包含空白表单(透明背景)的ImageBrush,以及一个表示触摸屏输入的笔划集合。我知道这不是创建XPS的首选方法,但是我无法在运行时访问动态文本以将其生成为TextBlocks等。
<Viewbox x:Name="viewboxDocView" Grid.Row="0">
<FixedPage x:Name="fixedPage" Width="720" Height="960" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10">
<InkCanvas x:Name="inkCanvas" Width="720" Height="960" HorizontalAlignment="Center" VerticalAlignment="Center" ></InkCanvas>
</FixedPage>
</Viewbox>
在后台代码中,我将FixedPage背景设置为显示动态文本,将InkCanvas背景设置为显示透明表单。
inkCanvas.Background = myImageBrush;
fixedPage.Background = myOtherImageBrush;
它在我的应用程序中显示得很漂亮,保存为XPS文件,在XPS查看器和Microsoft Reader中都显示得很漂亮。唯一的问题是,当我尝试从这些应用程序中打印时,页面图像很小。这两个图像全部打印并缩小,并且Strokes显示为全尺寸,但在大多数打印机上会被裁剪,因此只有左上角部分可见。
我显式地将页面尺寸定义为720x960,因为960 * 1/96“= 10英寸和720 * 1/96”= 7.5英寸,强制8.5x11“页面上的最小页边距为0.5”。当我打印时,图像正好是2.4“x 3.2",这意味着打印机的分辨率是960 / 3.2 =300dpi,而不是预期的96dpi。我知道打印机通常使用300dpi,所以这并不完全令人惊讶,但我认为正如here所描述的那样,FixedDocument的全部要点是所见即所得的概念。
有没有一种方法可以明确地将页面定义为7.5“x 10”(或8.5“x 11”,内容居中),以便正确打印?似乎当我开始调整XAML中的内容大小或尝试使用转换时,它会搞乱屏幕显示,而屏幕显示最终对应用程序更重要。
发布于 2015-01-16 06:41:12
我仍然想弄清楚如何使我的文件与标准的微软程序兼容,但现在我已经创建了一个简单的单窗口WPF .xps文件查看器应用程序,它接受文件路径作为命令行参数,并正确地打印这些文件。显然,我可以使用现有程序中的另一个窗口来完成此操作,但我似乎无法解决Windows打印对话框的线程安全问题。在XAML中:
<Window x:Class="Viewer.ViewerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Document Viewer">
<Grid>
<DocumentViewer x:Name="Viewer" />
</Grid>
</Window>
在代码隐藏中:
public partial class ViewerWindow : Window
{
XpsDocument doc;
string fileName;
public ViewerWindow()
{
InitializeComponent();
// get file name from command line
string[] args = System.Environment.GetCommandLineArgs();
fileName = args[1];
// size window
this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
this.Width = ((System.Windows.SystemParameters.PrimaryScreenHeight * 8.5) / 11);
// Open File and Create XpsDocument
if (!File.Exists(fileName) || fileName == null || fileName == "")
{
System.Windows.MessageBox.Show("File Not Found!");
this.Close();
}
else if (!fileName.EndsWith(".xps") && !fileName.EndsWith(".oxps"))
{
System.Windows.MessageBox.Show("File not in XPS format");
this.Close();
}
else
{
try
{
doc = new XpsDocument(fileName, System.IO.FileAccess.Read);
}
catch (UnauthorizedAccessException)
{
System.Windows.MessageBox.Show("Unable to open file - check user permission settings and make sure that the file is not open in another program.");
this.Close();
}
}
// Display XpsDocument in Viewer
Viewer.Document = doc.GetFixedDocumentSequence();
}
}
这只是一个临时的解决办法,所以请随时贡献!
https://stackoverflow.com/questions/27947796
复制相似问题