TCPDF output through JSON












0















Now that the blob problem has been resolved in Download of jQuery Ajax request contents is empty
, I'd like to send the TCPDF output through JSON.
The best I came up with is this:



session_set_cookie_params(0, '/', '.kairosplanner.com');
@session_start();
include '../inc/db.inc.php';
include '../inc/functions.inc.php';
include '../inc/encdec.inc.php';
require_once('../inc/tcpdf/tcpdf.php');
$pdf = new TCPDF('L', 'mm', 'A4', false, 'ISO-8859-1', false);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetCreator('KairosPlanner.com');
$pdf->SetAuthor('Albert van Harten');
$pdf->SetTitle('KairosPlanner.com');
$pdf->SetMargins(0, 0, 0);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetFont('helvetica', 'B', 9, '', true);
$pdf->AddPage();
$pdf->SetTextColor(64,48,117); //darkblue
$pdf->SetFillColor(255,255,255);
$pdf->SetXY(5, 5);
$pdf->Cell(65, 5, date("H:i:s"), '', 0, 'L', 'fill');
$result=array();
$result['response']="1";
$result['pdfdata']=$pdf->Output('name.pdf', 'E');
$result['filename']="filename.pdf";
$response["result"]=$result;
echo json_encode($response);


I've tried the other output types on TCPDF, but this is the only one that returned a string in stead of actual PDF output.



But this string is not the same as the Blob content in the other thread, I referred to.



So my question is: how do I send the PDF data through JSON back to my web app?










share|improve this question























  • I added the following right above $result=array(); $filename=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); $pdf->Output(__DIR__ . '/'.$filename.'.pdf', 'F'); $string=file_get_contents(__DIR__ . '/'.$filename.'.pdf'); unlink(__DIR__.'/'.$filename.'.pdf'); Then I get the data as a string - but that string cannot be sent as JSON. Anyone?

    – Kairos
    Nov 25 '18 at 18:58
















0















Now that the blob problem has been resolved in Download of jQuery Ajax request contents is empty
, I'd like to send the TCPDF output through JSON.
The best I came up with is this:



session_set_cookie_params(0, '/', '.kairosplanner.com');
@session_start();
include '../inc/db.inc.php';
include '../inc/functions.inc.php';
include '../inc/encdec.inc.php';
require_once('../inc/tcpdf/tcpdf.php');
$pdf = new TCPDF('L', 'mm', 'A4', false, 'ISO-8859-1', false);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetCreator('KairosPlanner.com');
$pdf->SetAuthor('Albert van Harten');
$pdf->SetTitle('KairosPlanner.com');
$pdf->SetMargins(0, 0, 0);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetFont('helvetica', 'B', 9, '', true);
$pdf->AddPage();
$pdf->SetTextColor(64,48,117); //darkblue
$pdf->SetFillColor(255,255,255);
$pdf->SetXY(5, 5);
$pdf->Cell(65, 5, date("H:i:s"), '', 0, 'L', 'fill');
$result=array();
$result['response']="1";
$result['pdfdata']=$pdf->Output('name.pdf', 'E');
$result['filename']="filename.pdf";
$response["result"]=$result;
echo json_encode($response);


I've tried the other output types on TCPDF, but this is the only one that returned a string in stead of actual PDF output.



But this string is not the same as the Blob content in the other thread, I referred to.



So my question is: how do I send the PDF data through JSON back to my web app?










share|improve this question























  • I added the following right above $result=array(); $filename=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); $pdf->Output(__DIR__ . '/'.$filename.'.pdf', 'F'); $string=file_get_contents(__DIR__ . '/'.$filename.'.pdf'); unlink(__DIR__.'/'.$filename.'.pdf'); Then I get the data as a string - but that string cannot be sent as JSON. Anyone?

    – Kairos
    Nov 25 '18 at 18:58














0












0








0








Now that the blob problem has been resolved in Download of jQuery Ajax request contents is empty
, I'd like to send the TCPDF output through JSON.
The best I came up with is this:



session_set_cookie_params(0, '/', '.kairosplanner.com');
@session_start();
include '../inc/db.inc.php';
include '../inc/functions.inc.php';
include '../inc/encdec.inc.php';
require_once('../inc/tcpdf/tcpdf.php');
$pdf = new TCPDF('L', 'mm', 'A4', false, 'ISO-8859-1', false);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetCreator('KairosPlanner.com');
$pdf->SetAuthor('Albert van Harten');
$pdf->SetTitle('KairosPlanner.com');
$pdf->SetMargins(0, 0, 0);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetFont('helvetica', 'B', 9, '', true);
$pdf->AddPage();
$pdf->SetTextColor(64,48,117); //darkblue
$pdf->SetFillColor(255,255,255);
$pdf->SetXY(5, 5);
$pdf->Cell(65, 5, date("H:i:s"), '', 0, 'L', 'fill');
$result=array();
$result['response']="1";
$result['pdfdata']=$pdf->Output('name.pdf', 'E');
$result['filename']="filename.pdf";
$response["result"]=$result;
echo json_encode($response);


I've tried the other output types on TCPDF, but this is the only one that returned a string in stead of actual PDF output.



But this string is not the same as the Blob content in the other thread, I referred to.



So my question is: how do I send the PDF data through JSON back to my web app?










share|improve this question














Now that the blob problem has been resolved in Download of jQuery Ajax request contents is empty
, I'd like to send the TCPDF output through JSON.
The best I came up with is this:



session_set_cookie_params(0, '/', '.kairosplanner.com');
@session_start();
include '../inc/db.inc.php';
include '../inc/functions.inc.php';
include '../inc/encdec.inc.php';
require_once('../inc/tcpdf/tcpdf.php');
$pdf = new TCPDF('L', 'mm', 'A4', false, 'ISO-8859-1', false);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetCreator('KairosPlanner.com');
$pdf->SetAuthor('Albert van Harten');
$pdf->SetTitle('KairosPlanner.com');
$pdf->SetMargins(0, 0, 0);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetFont('helvetica', 'B', 9, '', true);
$pdf->AddPage();
$pdf->SetTextColor(64,48,117); //darkblue
$pdf->SetFillColor(255,255,255);
$pdf->SetXY(5, 5);
$pdf->Cell(65, 5, date("H:i:s"), '', 0, 'L', 'fill');
$result=array();
$result['response']="1";
$result['pdfdata']=$pdf->Output('name.pdf', 'E');
$result['filename']="filename.pdf";
$response["result"]=$result;
echo json_encode($response);


I've tried the other output types on TCPDF, but this is the only one that returned a string in stead of actual PDF output.



But this string is not the same as the Blob content in the other thread, I referred to.



So my question is: how do I send the PDF data through JSON back to my web app?







php jquery json blob tcpdf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 13:40









KairosKairos

63




63













  • I added the following right above $result=array(); $filename=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); $pdf->Output(__DIR__ . '/'.$filename.'.pdf', 'F'); $string=file_get_contents(__DIR__ . '/'.$filename.'.pdf'); unlink(__DIR__.'/'.$filename.'.pdf'); Then I get the data as a string - but that string cannot be sent as JSON. Anyone?

    – Kairos
    Nov 25 '18 at 18:58



















  • I added the following right above $result=array(); $filename=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); $pdf->Output(__DIR__ . '/'.$filename.'.pdf', 'F'); $string=file_get_contents(__DIR__ . '/'.$filename.'.pdf'); unlink(__DIR__.'/'.$filename.'.pdf'); Then I get the data as a string - but that string cannot be sent as JSON. Anyone?

    – Kairos
    Nov 25 '18 at 18:58

















I added the following right above $result=array(); $filename=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); $pdf->Output(__DIR__ . '/'.$filename.'.pdf', 'F'); $string=file_get_contents(__DIR__ . '/'.$filename.'.pdf'); unlink(__DIR__.'/'.$filename.'.pdf'); Then I get the data as a string - but that string cannot be sent as JSON. Anyone?

– Kairos
Nov 25 '18 at 18:58





I added the following right above $result=array(); $filename=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); $pdf->Output(__DIR__ . '/'.$filename.'.pdf', 'F'); $string=file_get_contents(__DIR__ . '/'.$filename.'.pdf'); unlink(__DIR__.'/'.$filename.'.pdf'); Then I get the data as a string - but that string cannot be sent as JSON. Anyone?

– Kairos
Nov 25 '18 at 18:58












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468056%2ftcpdf-output-through-json%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468056%2ftcpdf-output-through-json%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno