コード例 #1
0
ファイル: PdfCrowdGenerator.php プロジェクト: albe/Famelo.PDF
 public function generate($content)
 {
     $instance = new \Pdfcrowd($this->username, $this->apiKey);
     $instance->setHeaderHtml($this->header);
     $instance->setFooterHtml($this->footer);
     $instance->setPageMargins($this->options['margin-top'] * 2, $this->options['margin-right'], $this->options['margin-bottom'] * 2, $this->options['margin-left']);
     return $instance->convertHtml($content);
 }
コード例 #2
0
    $productDiameter = $apiRequests->getProduct($productId)[0][D_diametro];
    $numPages = count($apiRequests->getViews($_GET['IDcus']));
    $pageWidth = 450;
    // 600 * 72 / 96
    $pageHeight = (int) $apiRequests->getCustomization($_GET['IDcus'])[0]['Height'] * 72 / 96;
    //pixels to points conversion
    if ($realSize == true) {
        if ($productWidth !== null && $productHeight !== null && $productDiameter == null || $productWidth == null && $productHeight == null && $productDiameter !== null) {
            $scaleFactor = floatval($productWidth / 158.75);
            // 600 pixles * 72 / 96 => becomes points then 1 pint is 0.35 mm => therefor 600px are 158.75 mm in 72 pixels per inch
            $pageWidth = str_replace('.00', $productUnits, $productWidth);
            $pageHeight = -1;
            $pdf = $client->setPdfScalingFactor($scaleFactor);
        } else {
            exit;
        }
    }
    $pdf = $client->setPageWidth($pageWidth);
    $pdf = $client->setPageHeight($pageHeight);
    $pdf = $client->setPageMargins(0, 0, 0, 0);
    $pdf = $client->setMaxPages($numPages);
    $pdf = $client->convertURI('http://www.sellosyrotulos.com/pdf_custom.php?IDcus=' . $idCus . '&type=' . $type);
    header('Content-Type: application/pdf');
    header('Cache-Control: no-cache');
    header('Accept-Ranges: none');
    header('Content-Disposition: attachment; filename=\'custom-' . $idCus . '.pdf\'');
    echo $pdf;
} catch (PdfcrowdException $e) {
    echo 'Pdfcrowd Error: ' . $e->getMessage();
}
//}
コード例 #3
0
ファイル: test.php プロジェクト: ahamed07sajeeb/pdfcrowd-php
}
$tests = array('setPageWidth' => 500, 'setPageHeight' => -1, 'setHorizontalMargin' => 0, 'setVerticalMargin' => 72, 'setEncrypted' => True, 'setUserPassword' => 'userpwd', 'setOwnerPassword' => 'ownerpwd', 'setNoPrint' => True, 'setNoModify' => True, 'setNoCopy' => True, 'setPageLayout' => Pdfcrowd::CONTINUOUS, 'setPageMode' => Pdfcrowd::FULLSCREEN, 'setFooterText' => '%p/%n | source %u', 'enableImages' => False, 'enableBackgrounds' => False, 'setHtmlZoom' => 300, 'enableJavaScript' => False, 'enableHyperlinks' => False, 'setDefaultTextEncoding' => 'iso-8859-1', 'usePrintMedia' => True, 'setMaxPages' => 1, 'enablePdfcrowdLogo' => True, 'setInitialPdfZoomType' => Pdfcrowd::FIT_PAGE, 'setInitialPdfExactZoom' => 113, 'setPdfScalingFactor' => 0.5, 'setFooterHtml' => '<b>bold</b> and <i>italic</i> <img src="http://s3.pdfcrowd.com/test-resources/logo175x30.png" />', 'setFooterUrl' => 'http://s3.pdfcrowd.com/test-resources/footer.html', 'setHeaderHtml' => 'page %p out of %n', 'setHeaderUrl' => 'http://s3.pdfcrowd.com/test-resources/header.html', 'setAuthor' => 'Custom Author', 'setPageBackgroundColor' => 'ee82EE', 'setTransparentBackground' => True, 'setUserAgent' => "test user agent");
try {
    foreach ($tests as $method => $arg) {
        $client = new Pdfcrowd($argv[1], $argv[2]);
        $client->{$method}($arg);
        $client->setVerticalMargin('1in');
        $client->convertFile($test_dir . '/in/simple.html', out_stream(strtolower($method), False));
    }
} catch (PdfcrowdException $e) {
    echo "EXCEPTION: " . $e->getMessage();
    exit(1);
}
// margins
$client = new Pdfcrowd($argv[1], $argv[2]);
$client->setPageMargins('0.25in', '0.5in', '0.75in', '1.0in');
$client->convertHtml('<div style="background-color:red;height:100%">4 margins</div>', out_stream('4margins', False));
// expected failures
$failures = array(array("convertHtml", "", "must not be empty"), array("convertFile", "does-not-exist.html", "not found"), array("convertFile", "/", "not a directory"), array("convertFile", $test_dir . "/in/empty.html", "must not be empty"), array("convertURI", "domain.com", "must start with"), array("convertURI", "HtTp://s3.pdfcrowd.com/this/url/does/not/exist/", "Received a non-2xx response"));
$client = new Pdfcrowd($argv[1], $argv[2]);
$client->setFailOnNon200(True);
foreach ($failures as $failure) {
    try {
        $client->{$failure}[0]($failure[1]);
        echo "FAILED expected an exception: {$failure}\n";
        exit(1);
    } catch (PdfcrowdException $e) {
        if (!strstr($e->getMessage(), $failure[2])) {
            echo "error message [" . $e->getMessage() . "] is expected to contain [" . $failure[2] . "]\n";
            exit(1);
        }