1

我正在尝试在我的 PDF 中制作cropMark,我已经看过示例文档:

http://www.tcpdf.org/examples/example_056.phps

而且我已经下载了该代码并设法使这些cropMarks 工作,但是我似乎无法将裁剪标记添加到我的其他PDF 代码中。为了使cropMark 方法起作用,对PDF 的先前要求是什么?

我正在制作这样的cropMark(右50mm,从0,0向下50mm):

$pdf->cropMark(50,50, 10, 10, 'TL', array(255,0,0));

我尝试在添加内容之前和之后添加此代码。内容是 Cell、writeHTMLCell 和 SVG 内容的组合。

我添加这样的页面:

$pdf->AddPage('L', $page_format, true, false);

我设置页面的边距

$pdf->SetMargins(0,0,0);

而且我没有设置任何页眉或页脚边距。我究竟做错了什么?

更新:我应该提到我没有收到任何错误,我只是没有看到任何裁剪标记,我的背景是蓝色的,并且(我相信)裁剪标记应该是红色的。我也尝试过添加新页面(AddPage())并尝试在新页面上绘制裁剪标记,但仍然没有运气。到目前为止,我发现这些文档有用且一致,所以我一定做错了什么。

4

3 回答 3

2

我很难弄清楚坐标是如何工作的。以下方法最终为我解决了,并为任何 tcpdf 文档绘制标记和出血:

/**
 * Enlarges the MediaBox by the slug of the document in all directions and draws cropmarks,
 * registrations marks and color bars
 *
 * @param $tcpdf the internal tcpdf object
 *
 * @access public
 */
public function drawCropbox($tcpdf, $slug = 6)
{
  for ($i = 1; $i <= $tcpdf->getNumPages(); $i++) {
    $tcpdf->setPage($i);
    $width = $tcpdf->getPageWidth();
    $height = $tcpdf->getPageHeight();
    $outerWidth = $width + 2 * $slug;
    $outerHeight = $height + 2 * $slug;
    $barHeight = min($slug - 1, 6);
    $barWidth = min(9 * $barHeight, ($width - $barHeight * 4)/ 2);
    $barHeight = max(1, $barWidth / 9);
    $registrationHeight  = $barHeight / 2;

    $tcpdf->setPageFormat(
      array(
        $outerWidth,
        $outerHeight,
        'Rotate'   => 0,
        'MediaBox' => array(
          'llx' => -$slug, 'lly' => $height + $slug, 'urx' => $width + $slug, 'ury' => -$slug
        ),
      )
    );

    //Crop left top
    $tcpdf->cropMark(
      $x = 0,
      $y = $outerWidth - $height,
      $w = $slug,
      $h = $slug,
      $type = 'A',
      $color = array(0, 0, 0)
    );

    //Crop right top
    $tcpdf->cropMark(
      $x = $width,
      $y = $outerWidth - $height,
      $w = $slug,
      $h = $slug,
      $type = 'B',
      $color = array(0, 0, 0)
    );

    //Crop left bottom
    $tcpdf->cropMark(
      $x = 0,
      $y = $outerWidth,
      $w = $slug,
      $h = $slug,
      $type = 'C',
      $color = array(0, 0, 0)
    );

    //Crop right bottom
    $tcpdf->cropMark(
      $x = $width,
      $y = $outerWidth,
      $w = $slug,
      $h = $slug,
      $type = 'D',
      $color = array(0, 0, 0)
    );

    //Registration left
    $tcpdf->registrationMark(
      $x = -$slug / 2,
      $y = $width - $height / 2 + 2 * $slug,
      $registrationHeight,
      FALSE,
      array(0, 0, 0),
      array(255, 255, 255)
    );

    //Registration top
    $tcpdf->registrationMark(
      $x = $width / 2,
      $y = $outerWidth - $height - $slug / 2,
      $registrationHeight,
      FALSE,
      array(0, 0, 0),
      array(255, 255, 255)
    );

    //Registration right
    $tcpdf->registrationMark(
      $x = $width + $slug / 2,
      $y = $width - $height / 2 + 2 * $slug,
      $registrationHeight,
      FALSE,
      array(0, 0, 0),
      array(255, 255, 255)
    );

    //Registration bottom
    $tcpdf->registrationMark(
      $x = $width / 2,
      $y = $outerWidth + $slug / 2,
      $registrationHeight,
      FALSE,
      array(0, 0, 0),
      array(255, 255, 255)
    );

    //Color Registration Bar
    $tcpdf->colorRegistrationBar(
      $x = $width - $barWidth - $barHeight,
      $y = $outerWidth - $outerHeight + $slug,
      $w = $barWidth,
      $h = $barHeight,
      FALSE,
      TRUE,
      'A,W,R,G,B,C,M,Y,K'
    );

    //Gray Registration Bar
    $tcpdf->colorRegistrationBar(
      $x = $barHeight,
      $y = $outerWidth - $outerHeight + $slug,
      $w = $barWidth,
      $h = $barHeight,
      TRUE,
      FALSE,
      'A'
    );
  }
}
于 2013-09-19T20:21:13.293 回答
1

不幸的是,我无法找出为什么裁剪标记不起作用,但我通过使用该Line方法自己绘制它们来解决它。这是代码:

// set the crop marks to be same color as the text, so that they always show up
$pdf->SetLineStyle(array('width' => 0.25, 'color' => $myRGBColor));

// set quarter of an inch and 3/16 of an inch to mm
$qmm = 6.35;
$smQmm = 4.7625;
$cw = $pdf->getPageWidth();
$ch = $pdf->getPageHeight();

// Top left
$pdf->Line($qmm, 0, $qmm, $smQmm);
$pdf->Line(0, $qmm, $smQmm, $qmm);

// Top right
$pdf->Line($cw - $qmm, 0, $cw - $qmm, $smQmm);
$pdf->Line($cw, $qmm, $cw - $smQmm, $qmm);

// Bottom right
$pdf->Line($cw, $ch - $qmm, $cw - $smQmm, $ch - $qmm);
$pdf->Line($cw - $qmm, $ch, $cw - $qmm, $ch - $smQmm);

// Bottom left
$pdf->Line(0, $ch - $qmm, $smQmm, $ch - $qmm);
$pdf->Line($qmm, $ch, $qmm, $ch - $smQmm);
于 2013-01-11T21:25:01.963 回答
1

如果使用 linux,此 shell 脚本会在 pdf 中添加裁剪标记(也称为注册标记)。

#!/bin/bash
# takes two arguments, both pdf filenames.
# add cropmarks to  pdf file given as first argument, and writes result to pdf file, given as second argument.
# uses: pdfinfo, ps2pdf, pdftk
# koen 2013

# get bounding box
BOX=`pdfinfo -box $1 | grep 'MediaBox' | head -1`
LEFT=`echo $BOX | awk '{print $2}'`
BOTTOM=`echo $BOX | awk '{print $3}'`
RIGHT=`echo $BOX | awk '{print $4}'`
TOP=`echo $BOX | awk '{print $5}'`
WIDTH=`echo $BOX | awk '{print $4-$2}'`
HEIGHT=`echo $BOX | awk '{print $5-$3}'`

# add postscript code for crop marks
cat >> cropmarks.ps <<EOD
% length of crop mark, in inches
/Crop .5 def 
% length of crop mark, in points
/CropLen Crop 72 mul def 

0 setlinewidth 
$LEFT $BOTTOM moveto CropLen 0 rmoveto 0 CropLen rlineto stroke
$LEFT $BOTTOM moveto 0 CropLen rmoveto CropLen 0 rlineto stroke
$LEFT $TOP moveto CropLen 0 rmoveto 0 CropLen neg rlineto stroke
$LEFT $TOP moveto 0 CropLen neg rmoveto CropLen 0 rlineto stroke
$RIGHT $BOTTOM moveto CropLen neg 0 rmoveto 0 CropLen rlineto stroke
$RIGHT $BOTTOM moveto 0 CropLen rmoveto CropLen neg 0 rlineto stroke
$RIGHT $TOP moveto CropLen neg 0 rmoveto 0 CropLen neg rlineto stroke
$RIGHT $TOP moveto 0 CropLen neg rmoveto CropLen neg 0 rlineto stroke

showpage
EOD
ps2pdf -dDEVICEWIDTHPOINTS=$WIDTH -dDEVICEHEIGHTPOINTS=$HEIGHT cropmarks.ps cropmarks.pdf
pdftk $1 stamp cropmarks.pdf output $2
rm -f cropmarks.ps cropmarks.pdf
#not truncated
于 2013-01-31T14:15:24.220 回答