使用 silverlight 多次打印同一图像

发布于 2024-11-08 13:25:50 字数 116 浏览 0 评论 0原文

我有一个图像和一个文本框。用户在文本框中输入份数 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

|煩躁 2024-11-15 13:25:50

Silverlight 有一个非常简单易用的打印 API。我最近一直在使用它,并学习了如何使用列出的教程 Melodatron 和 这一点位于 Visiblox 网站。这是特定于他们的图表库的,但我仍然发现它非常有用。

我假设您一次只能打印一张图像,如果您有更多图像,请告诉我。首先,您需要设置一个网格或类似的东西来放入您的照片。您将需要在此网格中包含 N 行。您必须在后面的代码中执行此操作,因为您想要创建一定数量的行,但这可以通过以下方式轻松实现:

Grid grid = new Grid();

// Set the column and row definitions
for (int i = 0; i < Number of rows; i++)
{
    grid.RowDefinitions.Add(new RowDefinition()); 
}

这应该设置您需要的网格。获得网格后,您需要用您拥有的图像填充它。这非常简单,唯一的问题是您的图像不能多次使用 - 即您已有的图像只能在网格上出现一次。您必须复制它才能将其多次放置在网格上。我不确定您如何创建图像,但您可以根据现有图像的源路径创建新图像吗?有一个关于如何执行此操作的线程

// Set the column and row definitions
for (int i = 0; i < Number of rows; i++)
{
    // Duplicate your existing image here.
    Image image = new Image();
    grid.Children.Add(image);
    Grid.SetRow(image, i);
}

上面的所有代码都应该在这个方法中:

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
     //Code from above...

     e.PageVisual = grid;
}

在您想要打印的按钮事件处理程序中,执行以下操作:

private void Button_Click(object sender, RoutedEventArgs e)
{
     PrintDocument printDocument = new PrintDocument();
     printDocument.PrintPage +=  new EventHandler<PrintPageEventArgs>(printDocument_PrintPage);
     printDocument.Print("TITLE");
}

希望这有帮助!

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:

Grid grid = new Grid();

// Set the column and row definitions
for (int i = 0; i < Number of rows; i++)
{
    grid.RowDefinitions.Add(new RowDefinition()); 
}

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.

// Set the column and row definitions
for (int i = 0; i < Number of rows; i++)
{
    // Duplicate your existing image here.
    Image image = new Image();
    grid.Children.Add(image);
    Grid.SetRow(image, i);
}

All of the code above should be in this method:

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
     //Code from above...

     e.PageVisual = grid;
}

In the button event handler where you wish to print, do this:

private void Button_Click(object sender, RoutedEventArgs e)
{
     PrintDocument printDocument = new PrintDocument();
     printDocument.PrintPage +=  new EventHandler<PrintPageEventArgs>(printDocument_PrintPage);
     printDocument.Print("TITLE");
}

Hope this helps!

陪我终i 2024-11-15 13:25:50

有一个非常好的教程(下面的链接),其中包含有关 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文