Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #5376

Re: convert text mit tab stops to table

From The Natural Philosopher <tnp@invalid.invalid>
Newsgroups comp.os.linux.misc
Subject Re: convert text mit tab stops to table
Date 2012-05-21 13:14 +0100
Organization albasani.net
Message-ID <jpdbk1$pt4$1@news.albasani.net> (permalink)
References <a1ul3cF3b9U1@mid.individual.net>

Show all headers | View raw


ekkardgerlach wrote:
> Hi,
> any tool available to convert a ascii-text with tab stops to a table
> according to tabs?
> 

cc ? :-)

Seriously there is a free PDF library - PDFlibLite - that will in 
principle work if you parse the stuff you want using a language like C 
or PHP and then you can write functions to place simple text anywhere 
you want.

I have used it to formulate invoices and the like. Its limited, but its 
solid in what it can do.

http://www.pdflib.com/download/pdflib-family/pdflib-lite-7/


> a2ps considers tab stops but squeezes two short text sections with two
> tabs to  *one* column. I need a strict a conversion to a table where any
> tab stop starts a new column.
> 
> The aim is a postscript file that is printable.
> 

yep. been there done that got the T-shirt.

I have a few bits of php library that work up a slightly better 
interface to the Lite library than are supplied.

Its a few days work to do what you want: also you are probably 
restricted to inbuilt PDF fonts ..I cant remember..anyway I used 
helvetica throughout.

Tools are provided to decide the size of strings that you want to print 
so you can do wrapped columns, text centering.right justification and 
the like..but it all gets a bit fraught.


If its any use, heres a waste of bandwidth...

<?php
// Here we go then. Simple functions to  set up text an images into PDF 
format.
// Probably worth having some global variables../

$font=0; //current font handle
$fontstyle="normal";
$fontpoint=10;
$pdf=""; // the current resource.

function setfont($size,$weight)
{
	global $fontpoint;
	$fontpoint=$size;
	global $fontstyle;
	global $font;
	global $pdf;
	if ($fontstyle!=$weight)
		{
		if ($weight=='normal')
			$font=pdf_load_font($pdf,"Helvetica","iso8859-1","");
		else if ($weight=='bold')
			$font=pdf_load_font($pdf,"Helvetica-Bold","iso8859-1","");
		else if ($weight=='italic')
			$font=pdf_load_font($pdf,"Helvetica-Oblique","iso8859-1","");	
		else if ($weight=='bold-italic')
			$font=pdf_load_font($pdf,"Helvetica-BoldOblique","iso8859-1","");
		$fontstyle=$weight;
		}
pdf_setfont($pdf,$font,$fontpoint);
}

function end_page()
	{
	global $pdf;
	PDF_end_page($pdf);
	}
function close_document()
	{
	global $pdf;
	pdf_close($pdf);
	}
function new_page($title)
	{
	global $font,$fontweight,$fontstyle,$fontpoint,$pdf;
	pdf_begin_page($pdf,595,842);
	box(15,750,565,50,"#D0D0D0",0);
	setfont(14,'bold');
	$img=pdf_load_image($pdf,"gif","../Images/Logo2.gif","" );
	pdf_place_image($pdf,$img,25,777,0.10);
	text(297.5,760,$title,'centre');
	setfont(8,'normal');
	date_default_timezone_set ("Europe/London");
	text(470,790,date("G:i T: D M d Y"),'left');
	}
function new_document()
	{
	global $pdf;
	$pdf=PDF_new();
	pdf_begin_document($pdf,"","compatibility=1.5");
	}

function text($x,$y,$text,$align)
	{
	global $pdf,$font,$fontpoint;
	pdf_setfont($pdf,$font,$fontpoint);
	 // $text=mb_convert_encoding($text, "ISO-8859-1","UTF-8");
	if($align=='right')
		$x-=pdf_stringwidth($pdf,$text,$font,$fontpoint);
	else if ($align=='centre')
		$x-=pdf_stringwidth($pdf,$text,$font,$fontpoint)/2;
	pdf_show_xy($pdf,$text,$x,$y);
	return pdf_stringwidth($pdf,$text,$font,$fontpoint);
	}

function box($x,$y,$width,$height,$color) // color is #XXXXXX
	{
	global $pdf;
	setcolor($color);
	pdf_rect($pdf,$x,$y,$width,$height);
	pdf_fill($pdf);
	setcolor("#000000"); // back to black.
	}
function setcolor($color)
	{
	global $pdf;
	$string = str_replace("#","",$color);
	$red = hexdec(substr($string,0,2)) / 255;
	$green = hexdec(substr($string,2,2)) / 255;
	$blue = hexdec(substr($string,4,2)) / 255;
	pdf_setcolor($pdf,"fill",'rgb', $red, $green, $blue,0);
	}
function send_pdf_file($name)
	{
	global $pdf;
	 $buf = PDF_get_buffer($pdf);
      $len = strlen($buf);
      header("Content-type: application/pdf");
      header("Content-Length: $len");
      header("Content-Disposition: inline; filename=\"".$name.".pdf\"");
      print $buf;
	}
function print_pdf_file($printer)
	{
	global $pdf;
	$buf = PDF_get_buffer($pdf);	
	$len=strlen($buf);
	$handle=popen("/usr/bin/lp -o sides=one-sided -d ".$printer." -- -", 'w');
	fwrite($handle,$buf);
	}
	
function mail_pdf_file($email, $subject,$from,$return_path,$body,$filename)
{
	global $pdf;
	$buf=PDF_get_buffer($pdf);
	$attach=chunk_split( base64_encode($buf),72, "\n");
	$boundary = md5( time() );
	$headers = sprintf("From: %s\nMIME-Version: 1.0\nContent-Type: 
multipart/mixed; boundary=\"%s\"",
				$from, $boundary);
	 $message = sprintf("\nThis is a multi-part message in MIME 
format.\n--%s\nContent-Type: text/plain; charset=UTF-8; 
format=flowed\nContent-Transfer-Encoding: 
7bit\n\n%s\n\n--%s\nContent-Type: application/pdf; 
name=\"%s\"\nContent-Disposition: inline; 
filename=\"%s\"\nContent-Transfer-Encoding: base64\n\n%s\n\n--%s--\n",
      $boundary,$body,$boundary,$filename, $filename,$attach,$boundary);
      mail($email, $subject, $message, $headers, "-f ".$return_path );
     }
?>


> tia
> Ekkard


-- 
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

convert text mit tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-21 12:52 +0200
  Re: convert text with tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-21 12:54 +0200
  Re: convert text mit tab stops to table Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-05-21 14:05 +0200
  Re: convert text mit tab stops to table The Natural Philosopher <tnp@invalid.invalid> - 2012-05-21 13:14 +0100
  Re: convert text mit tab stops to table David Brown <david@westcontrol.removethisbit.com> - 2012-05-21 15:03 +0200
  Re: convert text mit tab stops to table "Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at> - 2012-05-22 11:46 +0000
    Re: convert text mit tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-23 10:50 +0200
      Re: convert text mit tab stops to table Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-05-23 12:48 +0200
        Re: convert text mit tab stops to table ekkardgerlach <egerlach@aiai.de> - 2012-05-23 14:21 +0200

csiph-web