RML ใช้ กับ PHP ได้ไหมค่ะ
Moderators: mindphp, ผู้ดูแลกระดาน
- thatsawan
- PHP VIP Members
- Posts: 28523
- Joined: 31/03/2014 10:02 am
- Contact:
RML ใช้ กับ PHP ได้ไหมค่ะ
RML ใช้ กับ PHP ได้ไหมค่ะ
- mindphp
- ผู้ดูแลระบบ MindPHP
- Posts: 27183
- Joined: 22/09/2008 6:18 pm
- Contact:
Re: RML ใช้ กับ PHP ได้ไหมค่ะ
rml กับ php
ลองดูตามลิงค์ นี้ครับ
เพิ่มเติมที่ http://www.reportlab.com/documentation/ ... -with-php/
ลองดูตามลิงค์ นี้ครับ
Code: Select all
<?php
/*
This is a sample project which takes user input from an HTML form and generates a PDF containing what the user submitted. An RML file is read which contains the structure of the PDF document. A simple 'str_replace' replaces a variable name in the RML source with the value submitted by the user.
A similar principal could be used for generating personalised documents and mail merges by adding more fields such as address and post/zip code. For more advanced uses such as conditionals and for loops, users will probably want make use of a template engine such as Smarty or ReportLab's own Preppy.
*/
$PYTHON = "python"; # You can use a custom python build/version
$PYTHONPATH = "\$PYTHONPATH"; # Override PYTHONPATH if you installed somewhere unusual
$RML2PDF_DIR = "/path/to/rlextra/rml2pdf/"; # Where you installed rlextra
$RML2PDF_EXE = "rml2pdf.pyc"; # RML2PDF compiled python file
$RML_INPUT = "hello.rml"; # RML document source
$RML_OUTPUT = "output.rml"; # temporary location for RML after template processing
# If a GET parameter is supplied, generate and return a PDF, otherwise show a form where the user can fill in their name.
if ($_GET['q']) {
# Call function that reads RML file and does templating replacements
$rml_fn = getRML($RML_INPUT, $RML_OUTPUT, $_GET['q']);
# Execute the python command with rml2pdf.pyc and relevant arguments
exec("PYTHONPATH=$PYTHONPATH $PYTHON $RML2PDF_DIR$RML2PDF_EXE $rml_fn");
# Output file name
$fn = str_replace(".rml", ".pdf", $RML_INPUT);
# Check a PDF file was created
$fh = fopen($RML_OUTPUT, 'r') or die("Can't open PDF file $fn");
fclose($fh);
# Send PDF file to browser and appropriate headers
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=$fn");
readfile($fn);
}
else {
?>
<html>
<head>
<title>Create a PDF</title>
</head>
<body>
<h1>Create a dynamic PDF!</h1>
<p>Enter your name:</p>
<form action="." method="get">
<input type="text" name="q" />
<br />
<input type="submit" value="Make a PDF" />
</form>
</body>
</html>
<?php
}
function getRML($RML_INPUT, $RML_OUTPUT, $name) {
# Get content of the RML file
$rml = file_get_contents($RML_INPUT) or die("Can't open input RML file $RML_INPUT");
# Replace special string '##NAME##' with the variable submitted as GET request
# This is the simplest example of templating. You can use your preferred templating system here instead (e.g. Smarty or Preppy) for more control such as iteration loops.
$rml = str_replace("##NAME##", $name, $rml);
# Write the new RML string to a temporary file so it can be passed in as an argument to the RML2PDF script
$fh = fopen($RML_OUTPUT, 'w') or die("Can't open output RML file $RML_OUTPUT");
fwrite($fh, $rml);
fclose($fh);
return $RML_OUTPUT;
}
?>
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
-
- Similar Topics
- Replies
- Views
- Last post
-
-
อยากทราบว่าเราสามารถทึ alert เหมือน PM โดย PHP ได้ไหมค่ะ
by ทราย PHP » 29/06/2011 11:30 am » in Programming - PHP - 4 Replies
- 2335 Views
-
Last post by dexjanghan
09/08/2011 4:28 pm
-
-
-
รบกวนสอบถามหน่อยคะว่าไฟล์รูปภาพจะ save ให้เป็นไฟล์ pdf ได้ไหมคะ
by pimkuan » 20/06/2014 10:39 am » in ถาม - ตอบ คอมพิวเตอร์ - 3 Replies
- 1625 Views
-
Last post by mindphp
20/06/2014 10:48 am
-
-
-
insert รูปภาพ ทางด้านหน้าเว็บไซต์ของ Virturemart ได้ไหมค่ะ
by mindphp » 20/08/2012 9:10 pm » in ปัญหาการใช้ phpBB3, SMF, Joomla, Wordpress, CMS, CRM - 2 Replies
- 1798 Views
-
Last post by mindphp
21/08/2012 2:18 pm
-
-
-
อยากทราบ ว่าเราสามรถเก็บค่าใน text field ได้ไหมค่ะ
by pharanya » 04/02/2015 12:49 pm » in Software testing - 0 Replies
- 720 Views
-
Last post by pharanya
04/02/2015 12:49 pm
-
-
-
ไฟล์สกุล python กับ html สามารถนำมารันใน php ได้ไหมคะ
by mstsksmstsks » 28/10/2019 9:29 am » in Programming - PHP - 14 Replies
- 651 Views
-
Last post by mstsksmstsks
29/10/2019 11:15 am
-
-
-
สอบถาม ImageMagick สามารถใช้งานร่วมกับ HTML ได้ไหมค่ะ
by eange08 » 25/12/2020 7:56 pm » in Programming - PHP - 6 Replies
- 323 Views
-
Last post by eange08
26/12/2020 4:37 pm
-
Who is online
Users browsing this forum: Bing [Bot] and 13 guests