- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很难弄清楚 c# 打印多页。我的应用程序创建了一个包含 1 到 10 个元素的对象类型列表。每个对象包含 2 个字符串属性:docTypeNumber 和 docTypeDescription。一个名为 flightnumber 的变量也被传递到类构造函数中。每个实例都是一种文档类型,必须作为单独的条形码表打印,其中包含文档类型编号、说明和航类号。大多数多页打印示例是一个文档“溢出”到多个页面上,而不是一个文档由多个单独的页面组成。我的问题是如何实现这一目标。
我是否需要创建一个覆盖多个页面的大型文档?我是否必须创建 PrintDocument 类的多个实例?
如有任何帮助,我们将不胜感激。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace BarcodeTest
{
class BarcodePrinter
{
public BarcodePrinter(List<DocumentType> type, string flightnumber)
{
docType = type;
flightNumber = flightnumber;
}
//Attributes
private List<DocumentType> docType = new List<DocumentType>();
private string flightNumber;
//helper variables
string docTypeNumber;
string docTypeDescription;
int pageNumber = 1;
int numberOfPages;
private static Font barcodeFont = new Font("3 of 9 Barcode", 24);
private static Font printFont = new Font("Arial", 24);
public void Print()
{
numberOfPages = docType.Count;
PrintDocument pd = new PrintDocument();
foreach (DocumentType type in docType)
{
docTypeNumber = type.DocumentTypeNumber;
docTypeDescription = type.DocumentDescription;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
}//end foreach
#if DEBUG
PrintPreviewDialog printPreview = new PrintPreviewDialog();
printPreview.Document = pd;
printPreview.Show();
#else
pd.Print();
#endif
}// end Print() method
public void pd_PrintPage(Object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
//e.Graphics.PageUnit = GraphicsUnit.Point;
e.Graphics.PageUnit = GraphicsUnit.Inch;
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
Brush br = new SolidBrush(Color.Black);
RectangleF rec1 = new RectangleF(1.9375f, 0f, 4, 1);
RectangleF rec2 = new RectangleF(1.9375f, .5f, 4, 1);
RectangleF rec3 = new RectangleF(1.9375f, 1f, 4, 1);
RectangleF rec4 = new RectangleF(1.9375f, 2, 4, 1);
RectangleF rec5 = new RectangleF(1.9375f, 2.5f, 4, 1);
g.DrawString("Air - " + docTypeDescription, printFont, br, rec1, stringFormat);
g.DrawString("*" + docTypeNumber + "*", barcodeFont, br, rec2, stringFormat);
g.DrawString(docTypeNumber, printFont, br, rec3, stringFormat);
g.DrawString("*" + flightNumber + "*", barcodeFont, br, rec4, stringFormat);
g.DrawString(flightNumber, printFont, br, rec5, stringFormat);
if (pageNumber < numberOfPages)
{
e.HasMorePages = true;
}
else
e.HasMorePages = false;
pageNumber++;
}//end pd_PrintPage Method
}//end BarcodePrinter Class
}//end namespace
最佳答案
我想通了。我需要在打印页面处理程序中遍历我的列表。我通过对每一页进行计数来做到这一点。我根据列表中的项目数知道有多少页。这是我的工作代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace BarcodeTest
{
class BarcodePrinter
{
public BarcodePrinter(List<DocumentType> type, string number)
{
docType = type;
flightNumber = number;
}
//Attributes
private List<DocumentType> docType = new List<DocumentType>();
private string flightNumber;
//helper variables
string docTypeNumber;
string docTypeDescription;
int pageNumber = 1;
int numberOfPages;
Font barcodeFont = new Font("3 of 9 Barcode", 36);
Font printFont = new Font("Arial", 24);
int i = 0;
public void Print()
{
numberOfPages = docType.Count; //# of List elements = # of pages
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
#if DEBUG
PrintPreviewDialog printPreview = new PrintPreviewDialog();
printPreview.Document = pd;
printPreview.Show();
#else
pd.Print();
#endif
}// end Print() method
public void pd_PrintPage(Object sender, PrintPageEventArgs e)
{
docTypeNumber = docType[i].DocumentTypeNumber; // This is a get/set Property
docTypeDescription = docType[i].DocumentDescription; // This is a get/set Property
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
Graphics g = e.Graphics;
e.Graphics.PageUnit = GraphicsUnit.Inch;
Brush br = new SolidBrush(Color.Black);
RectangleF rec1 = new RectangleF(.9375f, 0, 6, 1);
RectangleF rec2 = new RectangleF(1.9375f, .5f, 4, 1);
RectangleF rec3 = new RectangleF(1.9375f, 1f, 4, 1);
RectangleF rec4 = new RectangleF(.9375f, 2, 6, 1);
RectangleF rec5 = new RectangleF(1.9375f, 2.5f, 4, 1);
g.DrawString("Air - " + docTypeDescription, printFont, br, rec1, stringFormat);
// '*' Must Preceed and Follow Information for a bar code to be scannable
g.DrawString("*" + docTypeNumber + "*", barcodeFont, br, rec2, stringFormat);
g.DrawString(docTypeNumber, printFont, br, rec3, stringFormat);
// '*' Must Preceed and Follow Information for a bar code to be scannable
g.DrawString("*" + flightNumber + "*", barcodeFont, br, rec4, stringFormat);
g.DrawString(flightNumber, printFont, br, rec5, stringFormat);
if (pageNumber < numberOfPages)
{
e.HasMorePages = true;
i++;
pageNumber++;
}
else
{
e.HasMorePages = false;
}
}//end pd_PrintPage Method
}//end BarcodePrinter Class
}//end namespace
关于c# - 需要帮助打印列表中的多页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7212324/
扩展 SVG 标准以支持多个页面(又名 pageSet)的状态如何? 我看到几年前 SVG 1.2 和 SVG Print 计划慢慢停止,所以我想知道是否有人有关于 SVG future 功能的最新信
我是 PHP 的新手,在插入多个页面时使用 FPDI 有点困难。 我有一个包含 3 页的 .pdf 文件。我最终将第 1 页保存为第 3 页中的一个单独页面,并且与我的代码一起使用,但那是因为我的代码
有没有支持多页的 jQuery 画廊?我的问题是,每个页面包含不同数量的图像。我正在使用 Lightbox 2,但我看不到任何方法来配置多页画廊。我可以创建 5-6 个静态 HTML 页面,一页可以包
我正在开始使用 scrapy。我的 items.py 包含: class ParkerItem(scrapy.Item): account = scrapy.Field() m = s
我编写了一个代码来将单个 tiff 文件合并为多页 tiff。但输出最后带有空白页。如果输入文件是黑白的,但对于彩色的 .tiff 文件,代码工作正常。例如,如果我提供 100 个文件,作为输入输出,
我对 UIScrollView 中的 UITableView 有疑问。 情况是这样的: 我有一个 ListViewController,它在 UITableView 中显示一些事件。如果用户点击一个事
我想创建一个用于更改页面的按钮。我的问题是,我有一个我以前写的代码,但它不是我想要的那样工作。 代码如下: function loadingPage() { $(function () {
我希望对 1 个页面上的元素进行样式设置,并且不影响另一个页面上的相同元素。 我在每个元素上都有 class="homepage"。 有更好的方法吗? 为简单起见,这里是该页面上的 DIV。 h1.h
这是 jQuery 代码 $("#register-form").submit(function (e) { e.preventDefault(); }).validate({ rul
我的简单移动应用程序有 3 个页面,全部用 divs/data-role="page" 划分,并且位于同一文档 (.html) 中。页面加载完美,但如果我导航到第二页,按钮上的一个非常简单的单击事件将
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我是 python 新手。我目前正在研究网络抓取。任务是抓取戴尔社区 Inspiron 问题的前 5 页。我有运行并返回我需要的信息的代码。但是,我无法仅获取文本。我当前的代码返回文本 + html。
我目前正在为我已经完成的 m.file 开发一个 GUI。 GUI 将是一个具有多个页面的页面,每个页面都是一个独立的 GUI。 在主 GUI 上,用户将在具有 2 个选项的单选按钮组上进行选择。根据
我需要从我的程序中保存多页 TIFF,但它似乎是 Qt doesn't support multipage TIFF .尽管如此,我还是需要这样做。从我的程序开始执行此操作的最佳方法是什么? 到目前为
我遇到了尝试将几个多页 html 文件与 jquery mobile 链接的问题,发现使用 ajax 时,jquery mobile 不会显示完整文档,而是第一页。 我查找了问题并找到了 todd t
我是桌面应用程序开发的新手,有一个非常基本的问题。我有一个名为 MainWindow 的 WPF 窗体,我应该如何在上面设置多个页面,例如“用户管理”、“管理内容”等。 我想我有以下选择: 使用多种形
我看到了一些关于多页 tiff 的问题和一些关于压缩的问题,但没有(我看到的)将两者联系起来。 This question和我见过的一样近,让我非常接近,所以我希望如此。我进入了提到的 Oracle
我正在尝试建立一个简单的多页表单,使用 session 稍后存储在数据库中的多个表中。 然而,我似乎遇到了问题。虽然最后一页的值被发布到数据库,但 session 变量却没有。 请记住.. 我和我的项
我正在尝试构建一个多页面 Dash 应用程序。当我运行以下代码时,一切正常,除了它不会路由到我的/dash_1 或/dash_2 url。想知道是否有人可以帮助我。 我的结构是这样的: 破折号项目/
search_1=raw_input('search criteria 1? ') search_2=raw_input('search criteria 2? ') br = mechanize.B
我是一名优秀的程序员,十分优秀!