使用 silverlight 多次打印同一图像
我有一个图像和一个文本框。用户在文本框中输入份数 (N) 并单击打印。打印机将照片打印 N 次(每页 3 张照片,一张在下)。
嗨,你会做这样的事情吗?我需要先生成一个 silverlight 页面吗?
I have an image an a textbox. the user enters into the textbox the number of copies (N) and clicks print. The printer prints the photo N times (3 photos per page, one under the other).
Hiw would you do something like that? Do I need to first generate a silverlight page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Silverlight 有一个非常简单易用的打印 API。我最近一直在使用它,并学习了如何使用列出的教程 Melodatron 和 这一点位于 Visiblox 网站。这是特定于他们的图表库的,但我仍然发现它非常有用。
我假设您一次只能打印一张图像,如果您有更多图像,请告诉我。首先,您需要设置一个网格或类似的东西来放入您的照片。您将需要在此网格中包含 N 行。您必须在后面的代码中执行此操作,因为您想要创建一定数量的行,但这可以通过以下方式轻松实现:
这应该设置您需要的网格。获得网格后,您需要用您拥有的图像填充它。这非常简单,唯一的问题是您的图像不能多次使用 - 即您已有的图像只能在网格上出现一次。您必须复制它才能将其多次放置在网格上。我不确定您如何创建图像,但您可以根据现有图像的源路径创建新图像吗?有一个关于如何执行此操作的线程
上面的所有代码都应该在这个方法中:
在您想要打印的按钮事件处理程序中,执行以下操作:
希望这有帮助!
Silverlight has a really simple to use Printing API. I have recently been using it and learnt how to do so using the tutorial Melodatron listed, and this one over at the Visiblox site. This is specific to their charting library but I still found it very useful.
I am assuming that you only have 1 image to print at a time here, let me know if you have more. First, you need to set up a grid or something similar to put your photos in. You will need N number of rows in this grid. You'll have to do this in code behind as you have a certain number of rows you'd like to create, but this can easily be achieved by something like this:
That should set up your grid that you need. After you have the grid, you need to populate it with the images that you have. This is pretty straightforward, the only issue will be that your image can't be used multiple times - i.e. the image that you already have can only appear on the grid once. You will have to duplicate it in order to place it on the grid multiple times. I'm not sure how you are creating your images, but you could possibly create a new image based on the source path of the existing image? There is a thread on how to do this here. You'll need to give more details if you need help with that.
All of the code above should be in this method:
In the button event handler where you wish to print, do this:
Hope this helps!
有一个非常好的教程(下面的链接),其中包含有关 Silverlight 中高级打印技术的示例和源代码。
您需要将布局创建为自定义控件,这应该不是那么困难,但您不需要显示它。
http://www.silverlightshow.net/items/Advanced-printing -in-Silverlight-4.aspx
希望这能让您朝着正确的方向开始。
There's a pretty good tutorial (link below) with an example and source code on advanced printing techniques in Silverlight.
You will need to create the layout as a custom control, which should not be so difficult, but you won't need to display it.
http://www.silverlightshow.net/items/Advanced-printing-in-Silverlight-4.aspx
Hopefully this gets you started in the right direction.