LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2009, 10:08 AM   #1
maryamabd
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
writting shell script and save in PDF file


Very helloo to all

my question is in how to writ a shell script that read data from user input such as:ID,cohort,GPA...etc and then save them in PDF file contains a logo(image has been saved in desktop).

great thanks for any help....
 
Old 04-23-2009, 10:34 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
I would start by getting the script to write the output file in HTML.

There are a number of utilities to convert from x,y,z to PDF
 
Old 04-23-2009, 10:51 AM   #3
ssaha
Member
 
Registered: Feb 2009
Location: Kolkata,India
Distribution: Fedora 8,Ubuntu 8.04, 8.10, 9.04, 9.10
Posts: 108

Rep: Reputation: 18
open the shell script in any text editor., select the whole document, copy and paste to openoffice word processor..
click on file->export as pdf and get the pdf form of the file.
 
Old 04-23-2009, 11:26 AM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Quote:
Originally Posted by ssaha View Post
open the shell script in any text editor., select the whole document, copy and paste to openoffice word processor..
click on file->export as pdf and get the pdf form of the file.
Yes, but that would be a manual process, and if I understand correctly, the OP is after getting the bash script to ask the end user a couple of questions and then automatically create a PDF file based on the results.
 
Old 04-23-2009, 12:07 PM   #5
namit
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 355

Rep: Reputation: 30
Quote:
Originally Posted by Disillusionist View Post
I would start by getting the script to write the output file in HTML.

There are a number of utilities to convert from x,y,z to PDF
I agree! this would be great start, then at lease you could position everything and then convert the temp html to pdf.
 
Old 04-24-2009, 06:53 AM   #6
maryamabd
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
thanks to all who replaeed to me...
ok is there any code to test it?,
actually am a biggener in writting shell script i want to get benifits from all of you.
 
Old 04-25-2009, 05:31 AM   #7
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
To ask for input in bash:

Code:
read -p "Enter your name: " l_name
Creating a basic HTML file might look something like:
Code:
echo "<html>
   <body>
      <table>
         <tr><td>Hello $l_name</td><td><img src='logo.png'/></td></tr>
      </table>
      Rest of message...
   </body>
</html>" > /tmp/output.html
To convert from HTML to PDF (two step process)
Requires installation of html2ps and cups-pdf

Code:
html2ps /tmp/output.html|lp -dPDF
This should create a file ~/PDF/_stdin_.pdf which can be moved and renamed.

Obviously, your specific HTML file might look quite different from this example.

Last edited by Disillusionist; 04-25-2009 at 05:33 AM.
 
Old 04-25-2009, 05:37 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Unless you need specific formatting only HTML provides why would you want to transmogrify to HTML first? You could hold entered data in an array or tempfile (do use mktemp), then send it to any Postscript capable printer and make it output to .ps file and then use 'ps2pdf' to create the PDF... OK, I'm not sure about the image but since Postscript and PDF can be edited I'm pretty sure it can have some image inserted as well.

Last edited by unSpawn; 04-25-2009 at 05:38 AM.
 
Old 04-25-2009, 10:45 AM   #9
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Quote:
Originally Posted by unSpawn View Post
Unless you need specific formatting only HTML provides why would you want to transmogrify to HTML first? You could hold entered data in an array or tempfile (do use mktemp), then send it to any Postscript capable printer and make it output to .ps file and then use 'ps2pdf' to create the PDF... OK, I'm not sure about the image but since Postscript and PDF can be edited I'm pretty sure it can have some image inserted as well.
I do take your point, and ps2pdf is a better utility to create the PDF than using cups-pdf.

My initial reasoning for creating the file in HTML was that I would find it easier to create the layout in HTML, especially as it would need a logo and that it would be completely scripted.

I am not sure what other file formats could be created straight from a bash script to provide the layout requirements that were intimated by the OP
 
Old 04-25-2009, 11:22 AM   #10
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
I'd say that the natural tool for that is LaTeX. So if you have anyone around you who can help you with preparing the LaTeX form for your PDFs, go with it. pdflatex will happily produce text-based PDF (i.e. text copying just works and file size is sane)
 
Old 04-25-2009, 11:34 AM   #11
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
Quote:
Originally Posted by Disillusionist View Post
Code:
echo "<html>
   <body>
      <table>
         <tr><td>Hello $l_name</td><td><img src='logo.png'/></td></tr>
      </table>
      Rest of message...
   </body>
</html>" > /tmp/output.html
Security problem there, what if someone else has created /tmp/output.html as a symlink pointing to one of the users files?

Use mktemp to create a temporary file.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to wget a webpage, and save as PDF (like cups-pdf) ? frenchn00b Programming 3 11-18-2008 04:48 PM
Shell Script to save/restore files and dir permissions joangopan Fedora 1 09-09-2007 03:51 AM
How to print/save a bundle of .png files as a single .pdf file satimis Linux - Software 24 08-04-2007 07:05 AM
Shell Script: Reading Pdf files funkymunky Programming 8 06-18-2004 04:34 PM
writting a backup shell script yenonn Slackware 2 03-18-2004 08:49 PM


All times are GMT -5. The time now is 04:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration