CropMarks в TCPDF

Я пытаюсь сделать cropMark в моем PDF, я видел пример документа:

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

И я скачал этот код и сумел заставить работать эти Марки культур, однако я не могу добавить метки обрезки к своему другому PDF-коду. Каковы предыдущие требования к PDF для работы метода cropMark?

Я делаю кадрирование следующим образом (50 мм справа, 50 мм вниз от 0,0):

$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()) и попытался нарисовать метки обрезки на новой странице, но все равно не повезло. До сих пор я находил документы полезными и последовательными, поэтому, должно быть, я что-то не так делаю.

3 ответа

Решение

К сожалению, я не мог выяснить, почему метки обрезки не работали, но я справился с этим, нарисовав их сам, используя 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);

Мне было невероятно сложно выяснить, как работают координаты. Следующий метод сработал для меня, наконец, и рисует метки и кровотечения для любого документа 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'
    );
  }
}

При использовании Linux этот сценарий оболочки добавляет метки обрезки (или регистрационные метки) в 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
Другие вопросы по тегам