Jump to content

pdf writing problem ?


plodos

Recommended Posts

pdf.php

<?php
  set_time_limit( 90 ); // this script can be very slow

  //create short variable names
  $name = "Mamas";

  function pdf_replace( $pattern, $replacement, $string )
  {
    $len = strlen( $pattern );
    $regexp = '';
    for ( $i = 0; $i<$len; $i++ )
    {
      $regexp .= $pattern[$i];
      if ($i<$len-1)
        $regexp .= "(\)\-{0,1}[0-9]*\(){0,1}";
    }
    return ereg_replace ( $regexp, $replacement, $string );
  }
  
    //generate the headers to help a browser choose the correct application
    header( 'Content-Disposition:  filename=cert.pdf');
    header( 'Content-type: application/pdf' );
  
    $date = date( 'F d, Y' );
  
    // open our template file
    $filename = 'pdfMake.pdf';
    $fp = fopen ( $filename, 'r' );
    //read our template into a variable
    $output = fread( $fp, filesize( $filename ) );

    fclose ( $fp );

    // replace the place holders in the template with our data  
    $output = pdf_replace( '<<NAME>>', strtoupper( $name ), $output );
    $output = pdf_replace( '<<mm/dd/yyyy>>', $date, $output );
   
    // send the generated document to the browser
    echo $output;
?>

 

I want to change the name, you can see the name <<NAME>> variable in the attachment pdf file.

 

When I click the pdf.php file, I got an error "the file is damaged and could not be repaired."

 

what can be the problem ?

 

[attachment deleted by admin]

Link to comment
Share on other sites

see comments on http://us.php.net/pdf for a couple libraries that may help.

Don't think you can pull what you are trying to do though... but maybe I'm wrong.

I'm wrong atleast partially... tested your script without the

    $output = pdf_replace( '<<NAME>>', strtoupper( $name ), $output );
    $output = pdf_replace( '<<mm/dd/yyyy>>', $date, $output );

chunk and it worked.

Link to comment
Share on other sites

  //  $output = pdf_replace( '<<NAME>>', strtoupper( $name ), $output );
  //  $output = pdf_replace( '<<mm/dd/yyyy>>', $date, $output );

 

when I click the pdf.php without these codes, scipt is showing me the pdfMake.pdf

 

but how can I change the <<NAME>> to Mamas ? I need another codes:S

 

pdf_replace() function is not working?

 

what is the solution ways/codes ?

Link to comment
Share on other sites

comment those headers out and run the page... then come back and finishing reading.

 

 

 

As you can see, you can't find <<NAME>> anywhere... its been made into another language.

If you find out which language that is specifically, you may be able to pinpoint the strings that makes that word and the figure out a way to convert given strings into that language.

Best of luck

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.