473,462 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding text to PDF file download

384 256MB
I was wondering if its possible to add text on the fly on a PDF download when using the below code, I've been unable to get it to work, I've tried echoing it and adding it to the var that the files being stored to with no luck, any ideas?
Expand|Select|Wrap|Line Numbers
  1. $chunksize = 1*($fileChunkSize);
  2. $bytes_send = 0;
  3. if ($file = fopen($file, 'r')) {
  4.     if(isset($_SERVER['HTTP_RANGE']))
  5.     fseek($file, $range);
  6.  
  7.     while(!feof($file) && (!connection_aborted()) && ($bytes_send<$new_length)) {
  8.         $buffer = fread($file, $chunksize);
  9.         print($buffer);
  10.         flush();
  11.         $bytes_send += strlen($buffer);
  12.     }
  13.     fclose($file);
  14. } else die('Error - can not open file.');
Jul 20 '11 #1
6 2107
johny10151981
1,059 1GB
Do you want to create new PDF file or do you want to add text to existing file?
Jul 20 '11 #2
ziycon
384 256MB
Its to add to an existing PDF, the above script allows the file to be downloaded but I need to be able to add a disclaimer to files downloaded.
The best option if possible would be to be able to add a page at the begining of the PDF with the disclaimer info!?
Jul 20 '11 #3
ziycon
384 256MB
Anyone any ideas on how to go about this?
Jul 22 '11 #4
johny10151981
1,059 1GB
Search this forum, i have answered this question several time
Jul 23 '11 #5
ziycon
384 256MB
I've been unable to find the topic your referring to, I've search under your posts/replies and by pdf but unable to find it, any chance you could link me please?
Jul 25 '11 #6
johny10151981
1,059 1GB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     session_start();
  3.     require_once('webapp/lib/globalfunctions/common.function.php');
  4.     function ShowFileName($filepath)
  5.     {
  6.         preg_match('/[^?]*/', $filepath, $matches);
  7.         $string = $matches[0];
  8.         #split the string by the literal dot in the filename
  9.         $pattern = preg_split('/\./', $string, -1, PREG_SPLIT_OFFSET_CAPTURE);
  10.         #get the last dot position
  11.         $lastdot = $pattern[count($pattern)-1][1];
  12.         #now extract the filename using the basename function
  13.         $filename = basename(substr($string, 0, $lastdot-1));
  14.         #return the filename part
  15.         return $filename;
  16.     } 
  17.     $res=Varification();
  18.     if($res==false)
  19.     {
  20.         echo "Authentication failed";
  21.         exit;
  22.     }
  23.     if($_GET['filename']==NULL)
  24.     {
  25.         echo "Error File name";
  26.         exit;
  27.     }
  28.  
  29.     $filename=$_GET['filename']; 
  30.  
  31.     $rfilename = $filename; 
  32.     $base=ShowFileName($filename);
  33.  
  34.     $file_extension = substr(strrchr($rfilename,"."),1);
  35.  
  36.     switch( $file_extension )
  37.     {
  38.         case "pdf": $ctype="application/pdf"; break;
  39.         case "exe": $ctype="application/octet-stream"; break;
  40.         case "zip": $ctype="application/zip"; break;
  41.         case "doc": $ctype="application/msword"; break;
  42.         case "xls": $ctype="application/vnd.ms-excel"; break;
  43.         case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
  44.         case "gif": $ctype="image/gif"; break;
  45.         case "png": $ctype="image/png"; break;
  46.         case "jpe": 
  47.         case "jpeg":
  48.         case "jpg": $ctype="image/jpg"; break;
  49.         default: $ctype="application/force-download";
  50.     }
  51.  
  52.     header("Pragma: public"); // required
  53.     header("Expires: 0");
  54.     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  55.     header("Cache-Control: private",false); // required for certain browsers
  56.     header("Content-Type: $ctype");
  57.     header("Content-Disposition: attachment; filename=".$base.";" );
  58.     header("Content-Transfer-Encoding: binary");
  59.     header("Content-Length: ".@filesize($rfilename));
  60.     @readfile($rfilename);
  61.     unlink($rfilename);
This is the code i use to force the browser to open save option instead of built in action
Jul 26 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom Youngquist | last post by:
I am trying to download a text file that my .NET page has just created based on entered parameters on the web page. Everything seems to work and the file is created. I am using the following code...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
5
by: Tim_Mac | last post by:
hi, i read that by adding the following code to by aspx pages, it would not store temporary internet files: Response.Cache.SetCacheability(HttpCacheability.NoCache); it didn't actually work...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
3
by: tshad | last post by:
I have a function that downloads a file to the users computer and it works fine. The problem is that I then want the program to rename the file (file.move) to the same name plus todays date. ...
1
by: R.A.M. | last post by:
Hello, I am learning PHP5. I have little experience. I have created a website in which I want to put a link to download a text file. When I used simple <a href="Dir/File.txt">Download file</a> I...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
8
by: jyaseen | last post by:
I used the follwing code to download the text file from my server location. my php file to read the following code name is contacts.php it is downloading the text file but , this text file...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.