Php imagick在pdf信函上覆盖文本
我有一封pdf设计的信。现在使用php,我想获取地址并将其放在pdf信函中,然后动态生成另一个带有该地址的pdf文件Php imagick在pdf信函上覆盖文本,php,imagick,Php,Imagick,我有一封pdf设计的信。现在使用php,我想获取地址并将其放在pdf信函中,然后动态生成另一个带有该地址的pdf文件 我怎样才能做到这一点 对于许可证来说很昂贵,但它是为这样的事情而设计的:打开template.pdf文件并动态添加新项目以生成输出pdf。还有其他免费的PDF操作库,例如它可能也可以做同样的事情。许可证费用很高,但它是为这些事情而设计的-打开模板.PDF文件并动态添加新项目以生成输出PDF。还有其他免费的PDF操作库,例如它可能也可以做同样的事情。使用imagick/imagic
我怎样才能做到这一点 对于许可证来说很昂贵,但它是为这样的事情而设计的:打开template.pdf文件并动态添加新项目以生成输出pdf。还有其他免费的PDF操作库,例如它可能也可以做同样的事情。许可证费用很高,但它是为这些事情而设计的-打开模板.PDF文件并动态添加新项目以生成输出PDF。还有其他免费的PDF操作库,例如它可能也可以做同样的事情。使用imagick/imagickdraw(ext:php-imagick)在windows下进行设置是一件痛苦的事情,但是如果您运行的是linux,它非常快且简单
$Imagick = new Imagick();
$Imagick->setResolution(300,300);
$Imagick->readImage('my.pdf[' . $page_number . ']');
$width = $Imagick->getImageWidth();
$height = $Imagick->getImageHeight();
$height *= (float) (2550 / $width);
$Imagick->scaleImage(2550, $height);
if (0 != $rotation)
$Imagick->rotateImage(new ImagickPixel(), $rotation);
$scaled_ratio = (float)$Imagick->getImageWidth() / 850;
// put white boxes on image
$ImagickDraw = new ImagickDraw();
$ImagickDraw->setFillColor('#FFFFFF');
$ImagickDraw->rectangle($x1, $y1, $x2, $y2);
$Imagick->drawImage($ImagickDraw);
// put text in white box (really on canvas that has already been modified)
$ImagickDraw = new ImagickDraw();
/* Font properties for text */
$ImagickDraw->setFont('times');
$ImagickDraw->setFontSize(42); // 10 * 300/72 = 42
$ImagickDraw->setFillColor(new ImagickPixel('#000000'));
$ImagickDraw->setStrokeAntialias(true);
$ImagickDraw->setTextAntialias(true);
// add text to canvas (pdf page)
$Imagick->annotateImage(
$ImagickDraw,
$x1 + 4, // 1 * 300/72 = 4
$y1 + 42, // 10 * 300/72 = 42
0,
$the_text // do not use html.. strip tags and replace <br> with \n if you got the text rom an editable div. (which is what I'm doing)
);
$Imagick->writeImage($filename);
---2012年5月1日编辑的另一项新增内容---
找到了一种从pdf到tif的灰度转换方法,看起来很糟糕。
只要一个命令。
---编辑结束5/1/2012---
使用imagick/imagickdraw(ext:php-imagick)在windows下进行设置是一件痛苦的事情,但是如果您运行的是linux,那么它非常快速和简单
$Imagick = new Imagick();
$Imagick->setResolution(300,300);
$Imagick->readImage('my.pdf[' . $page_number . ']');
$width = $Imagick->getImageWidth();
$height = $Imagick->getImageHeight();
$height *= (float) (2550 / $width);
$Imagick->scaleImage(2550, $height);
if (0 != $rotation)
$Imagick->rotateImage(new ImagickPixel(), $rotation);
$scaled_ratio = (float)$Imagick->getImageWidth() / 850;
// put white boxes on image
$ImagickDraw = new ImagickDraw();
$ImagickDraw->setFillColor('#FFFFFF');
$ImagickDraw->rectangle($x1, $y1, $x2, $y2);
$Imagick->drawImage($ImagickDraw);
// put text in white box (really on canvas that has already been modified)
$ImagickDraw = new ImagickDraw();
/* Font properties for text */
$ImagickDraw->setFont('times');
$ImagickDraw->setFontSize(42); // 10 * 300/72 = 42
$ImagickDraw->setFillColor(new ImagickPixel('#000000'));
$ImagickDraw->setStrokeAntialias(true);
$ImagickDraw->setTextAntialias(true);
// add text to canvas (pdf page)
$Imagick->annotateImage(
$ImagickDraw,
$x1 + 4, // 1 * 300/72 = 4
$y1 + 42, // 10 * 300/72 = 42
0,
$the_text // do not use html.. strip tags and replace <br> with \n if you got the text rom an editable div. (which is what I'm doing)
);
$Imagick->writeImage($filename);
---2012年5月1日编辑的另一项新增内容---
找到了一种从pdf到tif的灰度转换方法,看起来很糟糕。
只要一个命令。
---编辑结束5/1/2012---
我曾经和你在一起。这对我很管用。我几乎毫无问题地覆盖了数千个文件 我用过。这对我很管用。我几乎毫无问题地覆盖了数千个文件 是的,我使用了tcpdf,但没有找到任何方法在现有的pdf文件上覆盖文本。可能我需要使用tcpdf设计新的pdf。是的,我使用过tcpdf,但没有找到任何方法在现有的pdf文件上覆盖文本。可能我需要使用tcpdf设计新的pdf。你是如何解决褪色的颜色的?请看我的问题你是如何解决褪色的颜色的?请看我的问题
$Imagick->blackThresholdImage('grey');
$Imagick->setImageFormat("pdf");
$Imagick->writeImage($filename);