(单元)测试pdf生成 [英] (Unit)test pdf generation

查看:18
本文介绍了(单元)测试pdf生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们实现了一个 magento 模块 https://github.com/firegento/firegento-pdf/ 我打算为模块编写测试.

We implemented a magento module https://github.com/firegento/firegento-pdf/ and I plan to write tests for the module.

问题是:扩展生成pdf.

The problem is: The extension generates pdfs.

是否有任何框架,或任何测试 pdf 的东西?如果我可以检查 pdf 中的文本,那就太好了.我不想检查正确的位置.

Is there any framework, or whatever to test pdfs? It would be totally fine if I can check for text in the pdf. I don't want to check the correct placement.

安迪的想法?

这看起来很有希望,但感觉太大了.http://webcheatsheet.com/php/reading_clean_text_from_pdf.php

This looks promising but feels oversized. http://webcheatsheet.com/php/reading_clean_text_from_pdf.php

推荐答案

我将 PdfBox 用于类似的模块,这是一个基于 Java 的命令行实用程序,可以从 PDF 中提取文本并可选择将其转换为 HTML:http://pdfbox.apache.org/commandline/#extractText

I use PdfBox for a similar module, a Java based command line utility that extracts text from a PDF and optionally converts it to HTML: http://pdfbox.apache.org/commandline/#extractText

为了在 PHPUnit 测试中使用它,我为相关的 PdfBox 方法编写了一个 PHP 接口:https://github.com/schmengler/PdfBox

To use it within PHPUnit tests, I wrote a PHP interface for the relevant PdfBox methods: https://github.com/schmengler/PdfBox

use SGHPdfBox;

//$pdf = GENERATED_PDF;
$converter = new PdfBox;
$converter->setPathToPdfBox('/usr/bin/pdfbox-app-1.7.0.jar');
$text = $converter->textFromPdfStream($pdf);

进一步阅读:使用 PHPUnit 和 PDFBox 进行单元测试生成的 PDF

这篇关于(单元)测试pdf生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆