Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:36:36+00:00 2026-05-31T05:36:36+00:00

I’m trying to send a Json array over using an AJAX call to a

  • 0

I’m trying to send a Json array over using an AJAX call to a controller function which processes the data using a FPDF library which is already implemented into Codeigniter. I can see the PDF data being returned, but how would I go about opening this PDF data in a new window so the PDF can be saved. It doesn’t matter if the PDF cant be viewed i just need to save the generated file.

Here’s the code I have so far:

Jquery Code

<script defer="defer" type="text/javascript">
$(document).ready(function() {
    $('a#export').click(function(exportRecord) {    
        var postData = {
            'record_type'   : 1,
            'title' : 'Some Title Here',
            'content' : 'Some content here',
        };
        $.ajax({
                url: "<?php echo base_url().'admin/pdf/createPDF';?>",
                type:'POST',
                data: postData,
                dataType: 'json',
                success: function(data){
                        window.open(
                            'data:application/pdf,'+encodeURIComponent(data),
                            'Batch Print',
                            'width=600,height=600,location=_newtab'
                        );
                    } // End of success function of ajax form
        }); // End of ajax call
        return false;
    });
});
</script>

The Controller Function

<?php
    function createPDF(){       
            $content = $this->input->post('content');
            $font_directory = './assets/fpdf_fonts/';
            set_realpath($font_directory);
            define('FPDF_FONTPATH',$font_directory);
            $data = $this->fpdf->Open();
            $data = $this->fpdf->AddPage();
            $data = $this->fpdf->SetFont('Arial','',8);
            $data = $this->fpdf->Cell(80);
            $data = $this->fpdf->Cell(0,0,$content,0,1,'R');
            $data = $this->fpdf->Output();
    }

The JSON Response

%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 72>>
stream
x�3R��2�35W(�r
Q�w3T��30PISp
��陛)X��(��(hx����+���i*�d�����F
endstream
endobj
1 0 obj
<</Type /Pages
/Kids [3 0 R ]
/Count 1
/MediaBox [0 0 595.28 841.89]
>>
endobj
5 0 obj
<</Type /Font
/BaseFont /Helvetica
/Subtype /Type1
/Encoding /WinAnsiEncoding
>>
endobj
2 0 obj
<<
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/Font <<
/F1 5 0 R
>>
/XObject <<
>>
>>
endobj
6 0 obj
<<
/Producer (FPDF 1.7)
/CreationDate (D:20120309201958)
>>
endobj
7 0 obj
<<
/Type /Catalog
/Pages 1 0 R
>>
endobj
xref
0 8
0000000000 65535 f 
0000000228 00000 n 
0000000411 00000 n 
0000000009 00000 n 
0000000087 00000 n 
0000000315 00000 n 
0000000515 00000 n 
0000000590 00000 n 
trailer
<<
/Size 8
/Root 7 0 R
/Info 6 0 R
>>
startxref
639
%%EOF
""
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:36:37+00:00Added an answer on May 31, 2026 at 5:36 am

    Save the generated file where? On the users computer? On the server?

    Looks like $data in the createPFD method is the PDF.

    For the former, check http://codeigniter.com/user_guide/helpers/download_helper.html

    force_download('coolPDF.pdf', $data);
    

    For the latter, check http://codeigniter.com/user_guide/helpers/file_helper.html

    write_file('/path/to/these/PDFs/fileName.pdf', $data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want to construct a data frame in an Rcpp function, but when I
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.