简体   繁体   English

使用iTextSharp PDF进行连续标记

[英]Continuous Labelling using iTextSharp PDF

I have working iTextsharp code for printing labels. 我有用于打印标签的iTextsharp代码。 Now the problem is, I have a requirement to print the labels in Continuous paper which i am not able to select in iTextsharp configuration ( iTextSharp.text.PageSize.A4 ). 现在的问题是,我需要在我无法在iTextsharp配置( iTextSharp.text.PageSize.A4 )中选择的Continuous paper打印标签。 Please advice how can i select the page size according to my current scenario. 请建议我如何根据当前情况选择页面大小。

Thanks 谢谢

Your problem is related to PDF as a document format. 您的问题与PDF作为文档格式有关。 In PDF, the content is distributed over different pages. 在PDF中,内容分布在不同的页面上。 You can define the size of such a page yourself. 您可以自己定义此类页面的大小。 You mention iTextSharp.text.PageSize.A4 , but you can define the page size as a Rectangle object yourself. 您提到了iTextSharp.text.PageSize.A4 ,但是您可以自己将页面大小定义为Rectangle对象。 See iTextsharp landscape document 请参阅iTextsharp景观文档

If you want a long, narrow page, you could define the page size like this: 如果您想要一个长而狭窄的页面,则可以这样定义页面大小:

Document Doc = new Document(new Rectangle(595f, 14400f));

There are some implementation limits though. 虽然有一些实现限制。 The maximum height or width of a page is 14,400 user units. 页面的最大高度或宽度为14,400个用户单位。 See the blog post Help, I only see blank pages in my PDF! 请参阅博客文章“ 帮助”,我的PDF只看到空白页!

However, I am pretty sure that you don't want to create a long narrow page. 但是,我很确定您不想创建一个狭长的页面。 If you want to print labels on "continuous paper", you want to create a PDF document in which every page has the size of exactly one label. 如果要在“连续纸”上打印标签,则要创建一个PDF文档,其中每个页面的大小正好是一个标签。 Your PDF will have as many pages as there are labels. 您的PDF将具有与标签一样多的页面。

Suppose that the size of one label is 5 by 2 inch (width: 12.7cm; height: 5.08cm), then you should create a document like this: 假设一个标签的大小为5 x 2英寸(宽度:12.7cm;高度:5.08cm),那么您应该创建一个像这样的文档:

Document Doc = new Document(new Rectangle(360, 144));

And you should make sure that all the content of a label fits on a single page. 并且,您应确保标签的所有内容都适合于单个页面。 Your label printer should know that each page in the PDF should be printed on a separate label. 您的标签打印机应该知道PDF中的每一页都应打印在单独的标签上。

(Thank you @amedeeVanGasse for correcting my initial answer.) (感谢@amedeeVanGasse更正了我的初步答案。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM