帮助创建 PrintDocument 的工具?
我有一个 PrintDocument 及其 PrintPage 事件,该事件与使用 Graphics 对象绘制页面的函数相关联。
但这是非常乏味的。我在设置文件中有一些公司数据,我需要以格式良好的方式将其放在页面上,你知道,左上角是徽标,右上角是日期,然后中间还有更多数据......
目前,我是这样做的:
private void handlePrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("Foo", font, brush, new PointF(10, 10));
e.Graphics.DrawString("Bar", font, brush, new PointF(10, 30));
}
现在它不完全像那样,我有一些变量,例如 pageWidth、pageHeight,我可以将它们除以 2 并打印在文档的中心或者到最右边等等。
但是,这又太乏味了。有没有更好的方法来获取页面上的数据进行打印?
I have a PrintDocument and its PrintPage event tied to a function that uses the Graphics object to draw to the page.
But this is very tedious. I have some company data in a settings file that I need to put on the page in a nicely formatted manner, you know, upper left is the logo, upper right is the date and then some more data in the middle...
Currently, here is how I do it:
private void handlePrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("Foo", font, brush, new PointF(10, 10));
e.Graphics.DrawString("Bar", font, brush, new PointF(10, 30));
}
Now its not exactly like that, I have some variables like pageWidth, pageHeight that I can divide by 2 and print on the centre of the document or to the far right etc. etc.
But again, this is so tedious. Is there any better way to get data on a page for printing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试通过 COM 使用 Word,非常简单,无需计算,而且只需使用模板,您就可以将文档视为某种数组:)
这是一篇非常好的文章,我已将其与 Office 2010 一起使用,即使它很漂亮旧:
http://www.c-sharpcorner.com/UploadFile/amrish_deep /WordAutomation05102007223934PM/WordAutomation.aspx
希望有帮助:)
Try using Word via COM, pretty easy, no calculations required, also, just use a template and you can treat the document as some sort of array :)
This is a really good article and i have used it with Office 2010 even if its pretty old:
http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx
Hope it helps :)