Results 1 to 5 of 5

Thread: how to print pdf from string?

  1. #1
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default how to print pdf from string?

    Is there a method somewhere that will take $mystring="hello there", and print it as a pdf to the browser?
    I don't want to save the file to system, just print it to screen for download.

    I've done it once using

    Code:
    require_once('../plugins/tcpdf/config/lang/eng.php');
    require_once('../plugins/tcpdf/tcpdf.php');
    
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
    
    // set document information
    //THESE ARE META in pdf
    //GET FROM SETTINGS
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Nicola Asuni');
    $pdf->SetTitle('TCPDF Example 005');
    $pdf->SetSubject('TCPDF Tutorial');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    etc, but is there another way?

    eg: printStringAsPDFAndOutputToBrowser( $mystring)

  2. #2
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: how to print pdf from string?

    What is the problem with your method? You can create a function with that code and use that function exactly as you ask for.

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: how to print pdf from string?

    No problem with it - its just rather long-winded and I was wondering if it is the only way.

  4. #4
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: how to print pdf from string?

    Well, any function that does about the same thing will probably go through a similar process. I'm not aware of such a function existing, but that by no means indicates it doesn't.

    If it doesn't just add the function to a class you created accessible to the place you need it and then you can run it exactly the way you ask for.

    Where are you planning to use this?

  5. #5
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: how to print pdf from string?

    Its in a module I'm making for leasing accommodation.
    i have a bunch of reports being printed to screen that are formatted with html, but i'm adding buttons to allow save as csv, txt and pdf.

    All good, I know how to go about it using tcpdf, i was just hoping to replace breaks with newlines, strip all the html off the formatted records, and use the ImBeingLazyIJustWantMyPDFInstantlyGeneratedWithout AnyFuss() method that Leo may or may not have written to write a simple PDF.
    Even better would be if it converted the html into a PDF.

    Its just I thought I came acroos something like this once in the API, but can't find it again.
    No matter.
    Cheers.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •