TCPDF 页面旋转

发布于 2024-10-29 05:23:14 字数 261 浏览 7 评论 0 原文

我正在尝试生成一个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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(7

剪不断理还乱 2024-11-05 05:23:14

在构建页面时将其设置为横向怎么样?

TCPDF::__construct($orientation = 'L',
$   unit = 'mm',
$   format = 'A4',
$   unicode = true,
$   encoding = 'UTF-8',
$   diskcache = false)

$方向(字符串)页面方向。可能的值是(情况不敏感):

  • P或PROTAIT(默认)
  • L或Landscape
  • ''(空字符串)用于自动定向

http://www.tcpdf.org/doc/classTCPDF.html#a5420ac8b0726a604260780d8f4185fc1

How about setting it to landscape when building the page?

TCPDF::__construct($orientation = 'L',
$   unit = 'mm',
$   format = 'A4',
$   unicode = true,
$   encoding = 'UTF-8',
$   diskcache = false)

$orientation (string) page orientation. Possible values are (case insensitive):

  • P or Portrait (default)
  • L or Landscape
  • '' (empty string) for automatic orientation

http://www.tcpdf.org/doc/classTCPDF.html#a5420ac8b0726a604260780d8f4185fc1

我ぃ本無心為│何有愛 2024-11-05 05:23:14

我在 1.5 版本中所做的

    $pdf->AddPage(); // Orientation for the first page is defined into configuration file.

    $pdf->writeHTML("Portrait 1");

    $pdf->AddPage('L');

    $pdf->writeHTML("Landscape !");

    $pdf->AddPage('P');

    $pdf->writeHTML("Portrait 2");

    $pdf->Output();

工作效果很好。

What I've done with version 1.5

    $pdf->AddPage(); // Orientation for the first page is defined into configuration file.

    $pdf->writeHTML("Portrait 1");

    $pdf->AddPage('L');

    $pdf->writeHTML("Landscape !");

    $pdf->AddPage('P');

    $pdf->writeHTML("Portrait 2");

    $pdf->Output();

And this is working well.

萌面超妹 2024-11-05 05:23:14

Rotate 很奇怪。文档没有告诉您的是,您必须先执行 StartTransform,然后执行 Rotate,然后再执行 StopTransform。您只能在以某种方式设置 X/Y 位置后才能执行 StartTransform 调用(例如,我使用 SetXY 来初始定位页面,然后您可以调用 <代码>开始变换)。因此,请尝试这样做:

  $this->pdfinvoice->StartTransform();
  $this->pdfinvoice->Rotate(-90);

然后添加您的内容,然后

  $this->pdfinvoice->StopTransform();

在完成后致电。看看这对你有什么作用。

Rotate is odd. What the docs don't tell you is that you have to do a StartTransform first and then do a Rotate, then do a StopTransform afterwards. You can only do the StartTransform call after you have somehow set the X/Y position (so for example, I use SetXY to initially position the page, then you can call StartTransform). So try to do:

  $this->pdfinvoice->StartTransform();
  $this->pdfinvoice->Rotate(-90);

then add your content, then call

  $this->pdfinvoice->StopTransform();

when you're done. See how that works for you.

守不住的情 2024-11-05 05:23:14

构造函数中的 format 参数具有多种可选参数,包括 Rotate 以及对任意页面 widthheight 的支持- 示例:

// page A4 rotated clockwise 90 deg.
$pdf = new TCPDF('L', 'pt', ['format' => 'A4', 'Rotate' => 90]); 

// page with custom size rotated clockwise 270 deg.
$pdf = new TCPDF('L', 'pt', ['format' => [$width, $height], 'Rotate' => 270]);

文档此处

The format argument in constructor has wide range of optional parameters, including Rotate and support for arbitrary page width and height - example:

// page A4 rotated clockwise 90 deg.
$pdf = new TCPDF('L', 'pt', ['format' => 'A4', 'Rotate' => 90]); 

// page with custom size rotated clockwise 270 deg.
$pdf = new TCPDF('L', 'pt', ['format' => [$width, $height], 'Rotate' => 270]);

Documentation here.

还在原地等你 2024-11-05 05:23:14

景观最​​简单的方法是:
首先转到您的 tcpdf.config 文件
然后转到该行

 * Page orientation (P=portrait, L=landscape).
 */
define ('PDF_PAGE_ORIENTATION', 'L','P');

只需将“P”更改为“L”保存并运行它。

The simplest and easy way to Landscape is:
First go to your tcpdf.config file
then go to the line

 * Page orientation (P=portrait, L=landscape).
 */
define ('PDF_PAGE_ORIENTATION', 'L','P');

Just change the "P" to 'L' save and run it.

記柔刀 2024-11-05 05:23:14

最简单的选项是将页面设置为横向模式“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.

_畞蕅 2024-11-05 05:23:14

这是一篇旧文章,但如果有人遇到此问题,我建议您首先尝试该页面的横向模式。

这对我有用:

这是设置 A4 横向的代码:

$pdf->AddPage('L', '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:

$pdf->AddPage('L', 'A4');

Visit
https://tcpdf.org/examples/example_028/ to learn more.

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