Question

I have made good progress with producing pdf's with Zend PDF.

I am now integrating a web service into the application i am building. Everything has gone smoothly, but am now struggling to render a dynamically produced pdf that is to contain a pdf label returned via web service. Consider the following :

1.) An action to print the pdf is called. 2.) the pdf will contain n pages (n objects/items) of dynamic information about the item/shipment. 3.) each of the n shipments contains a shipment number, that when passed as a parameter to a specific method of the web-service, returns a pdfstring (which i can save as pdf). 4.) i have to resize and add each label to the bottom of the appropriate page.

so far, i have been able to use an already saved pdf, and have managed to load the pdfstring thats returned from the web service, and "merge" it into a final pdf. this works fine. but i would actually like to do the following:

1.) start a new pdf and add all other content to it. 2.) make the SOAP call and extract the returned Pdf string.

i have already done that, and now i would like to :

3.) resize the "label" 4.) rotate it 90 degrees 5.) add it to the pdf thats being built. (not merge with an already existing pdf).

so if i :

$returnedFromWebServicePDF = Zend_Pdf::parse($pdfLabel, 1);

I am able to save it on its own or even merge it (via cloning see here) but would like to resize, rotate and the add it to the pdf im building.

could someone guide me in the right direction as im pretty stumped. if someone could simply show me how to add this to a dynamic document, that would suffice as an answer to this question.

thanks in advance

EDIT

My efforts this far have been fruitless. i am now trying to change major parts of the applications processes, in order to already have stored the pdf, before this action is called. which means i could merge a static pdf into a dynamically generated one. will keep this problem updated.

Was it helpful?

Solution

Just to clarify, your goal is to download a PDF created by the service, load it back into Zend_PDF and make a change to content which exists in the pdf.

Zend_PDF is good at adding content to an existing pdf but doesn't have the ability to change content already on the page.

It does let you add new content which layers on-top of existing content. If you don't have control over the service, you can redact the content your trying to change with a shape filled with the background color and add a new text block over the shape.

We use something similar to make personalized certificates.

Its tricky getting it in just the right spot. I use a grid overlay on the pdf to get my bearings on the pdf.

/**
 * Creates a grid overlay on a pdf. Useful for positioning text on a page.
 * @param integer intPage The page number to operate on.
 * @param integer intInterval. Lines on the page will be drawn at this interval. Value is in points.
 * @return boolean TRUE for success.
 */
public function addGridLines($intPage = 0, $intInterval = 25)
{
    $this->objPdf->pages[$intPage]->saveGS();
    $pageWidth = $this->objPdf->pages[$intPage]->getWidth();
    $pageHeight = $this->objPdf->pages[$intPage]->getHeight();
    $this->objPdf->pages[$intPage]->setStyle($this->arrStyles['defaultLine']);
    $this->objPdf->pages[$intPage]->setStyle($this->arrStyles['defaultText']);
    //draw lines across the page.
    for($a = 0; $a < $pageHeight; $a+= $intInterval){
        $x = 0;
        $y = $a;
        $this->objPdf->pages[$intPage]->drawLine($x, $y, $pageWidth, $y);
        $this->objPdf->pages[$intPage]->drawText($a, $x, $y);
    }
    //Draw lines up the page.
    for($a = 0; $a < $pageHeight; $a+= $intInterval){
        $x = $a;
        $y = 0;
        $this->objPdf->pages[$intPage]->drawLine($x, $y, $x, $pageHeight);
        $this->objPdf->pages[$intPage]->drawText($a, $x, $y);
    }
    $this->objPdf->pages[$intPage]->restoreGS();

    return TRUE;
}

This method is in another object with pdf related methods, but you get the idea. The 'objPdf' is a Zend_PDF object I'm working with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top