我正在尝试生成一个PDF文件,其中包含202mm宽乘50mm的标签。我设法做到了这一点,并添加了所需的文本和条形码,但我的问题是,标签首先打印出狭窄的边缘,因此整页需要旋转90度。
我可以轻松地在Adobe阅读器中进行此操作,通过简单的右键单击页面上并选择顺时针旋转(shift+ctrl ++),但我确实需要在代码中执行此操作。
有人知道如何使用TCPDF做到这一点吗?我尝试了旋转功能,但似乎无法使其正常工作。任何代码的示例都会有所帮助。
I'm trying to generate a PDF file containing labels which are 202mm wide by 50mm heigh. I have managed to do this and added the required text and a barcode but my problem is that the labels print out narrow edge first so the whole page need rotating 90 degrees.
I can do this in Adobe Reader with ease by simple right clicking on the page and selecting Rotate Clockwise (Shift+Ctrl++) but I really need to do it in the code.
Does anyone know how to do this with TCPDF? I have tried the Rotate function but can't seem to get it working. Any examples of code would be helpful.
发布评论
评论(7)
在构建页面时将其设置为横向怎么样?
$方向(字符串)页面方向。可能的值是(情况不敏感):
http://www.tcpdf.org/doc/classTCPDF.html#a5420ac8b0726a604260780d8f4185fc1
How about setting it to landscape when building the page?
$orientation (string) page orientation. Possible values are (case insensitive):
http://www.tcpdf.org/doc/classTCPDF.html#a5420ac8b0726a604260780d8f4185fc1
我在 1.5 版本中所做的
工作效果很好。
What I've done with version 1.5
And this is working well.
Rotate
很奇怪。文档没有告诉您的是,您必须先执行StartTransform
,然后执行Rotate
,然后再执行StopTransform
。您只能在以某种方式设置 X/Y 位置后才能执行StartTransform
调用(例如,我使用SetXY
来初始定位页面,然后您可以调用 <代码>开始变换)。因此,请尝试这样做:然后添加您的内容,然后
在完成后致电。看看这对你有什么作用。
Rotate
is odd. What the docs don't tell you is that you have to do aStartTransform
first and then do aRotate
, then do aStopTransform
afterwards. You can only do theStartTransform
call after you have somehow set the X/Y position (so for example, I useSetXY
to initially position the page, then you can callStartTransform
). So try to do:then add your content, then call
when you're done. See how that works for you.
构造函数中的
format
参数具有多种可选参数,包括Rotate
以及对任意页面width
和height
的支持- 示例:文档此处。
The
format
argument in constructor has wide range of optional parameters, includingRotate
and support for arbitrary pagewidth
andheight
- example:Documentation here.
景观最简单的方法是:
首先转到您的 tcpdf.config 文件
然后转到该行
只需将“P”更改为“L”保存并运行它。
The simplest and easy way to Landscape is:
First go to your tcpdf.config file
then go to the line
Just change the "P" to 'L' save and run it.
最简单的选项是将页面设置为横向模式“L”(如果您需要的话)。
否则,如果您需要纵向模式但具有旋转对象的页面,则可以创建 XObject 模板并将内容放在那里,包括图形转换。
检查 http://www.tcpdf.org 上的默认示例以了解图形转换和 XObject 模板。
The simplest option is to set the page on Landscape mode 'L' if this is what you need.
Otherwise, if you need a page in portrait mode but with rotated objects, then you can create an XObject template and put your content there, including graphical transformations.
Check the default examples at http://www.tcpdf.org for graphical transformations and XObject templates.
这是一篇旧文章,但如果有人遇到此问题,我建议您首先尝试该页面的横向模式。
这对我有用:
这是设置 A4 横向的代码:
访问
https://tcpdf.org/examples/example_028/ 了解更多信息。
This is an old post but if anyone has this issue, I would suggest you first try out the landscape mode for the page.
This works for me:
Here is the code for setting A4 landscape:
Visit
https://tcpdf.org/examples/example_028/ to learn more.