1

PDFでcropMarkを作成しようとしていますが、サンプルドキュメントを確認しました。

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

そして、そのコードをダウンロードして、それらのクロップマークを機能させることができましたが、他の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 を使用している場合、このシェル スクリプトはクロップ マーク (レジストレーション マーク) を 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 に答える