Options for paper output?

Started by HPW, October 28, 2003, 12:20:51 AM

Previous topic - Next topic

HPW

#15
Thanks Nigel for this small and nice code!

Quite usefull when simple text-generation is needed.



Sam, thanks for the file-wrapper.
Hans-Peter

Lutz

#16
I also have been busy putting somethig around Nigel's code, here are some rotuines, which also do page numbers and footer text:



http://newlisp.org/download/development/txt2pdf.lsp">http://newlisp.org/download/development/txt2pdf.lsp



scroll th the end to see the interface routines. Perhaps I should rewrite line aquisition to 'read-line' style like Sam is doing, for less memory consumption. The whole thing goes on the news site one of these days.



Also a note to Sam's/HPW's 'loops' benchmark exchange: that is typical for benchmarks: you change the hardware / SW environment and everything comes out different. I think in this case it was Pentium versus Celeron, because on my Celeron things go in the same direction as on Sam's laptop, on my machine even more dramatic: 1.24 for 'for' and 0.80 for 'dotimes'.



Anyway I was happy to see that newLISP generally comes out of this strong and will continue to add more translations from Doug Bagley's test suite as I find time.



Lutz

nigelbrown

#17
Thanks for expanding the pdf stuff.



A point on the newLISP version vs C version : note that newLISP uses (seek to keep track of the internal position within the pdf file so internal cross references can be made while the original code uses ftell e.g.



(setq stream_len (- (seek pdfout) stream_start))

vs.

stream_len = ftell(stdout) - stream_start;



Ftell will work on stdout and thus the original program could use commandline piping, however seek won't (from my tests on windows

> (seek (device))

0

> (print "hello")

hello"hello"

> (seek (device))

0

>

) so that is why I forced writing to a file. If someone could make the output method more flexible, or perhaps open stdout in a way that seek returns a position, or implements ftell (Lutz?), then txt2pdf could be more flexible

(you may remember from posts above that I like toolchains).



Nigel

HPW

#18
Lutz,



some observations with your code:



;       (TXT2PDF:file "this is a test page 1n12nThis on page 2n" "demo.pdf")



should be



;       (TXT2PDF:text "this is a test page 1n12nThis on page 2n" "demo.pdf")



But when I call it it goes in a endless loop and produces and endless, wrong PDF.

Have not found the glitsh yet.



(define (file inFileName outFileName ff-lines footer-lines preNr postNr)
(setq object_id 1
num_pages 0
pages '()
formFeedLines nil
footerLines nil
countLines 0
countPages 0
prePagNr nil
postPageNr nil
outOfLines nil)
(get-params)
(setq input-lines (parse (read-file inFileName) "n|rn" 0))
(txt2pdf get-lines outFileName))

(define (text inBuffer outFileName ff-lines footer-lines preNr postNr)
(setq object_id 1
num_pages 0
pages '()
formFeedLines nil
footerLines nil
countLines 0
countPages 0
prePagNr nil
postPageNr nil
outOfLines nil)
(get-params)
(setq input-lines (parse inBuffer "n|rn" 0))
(txt2pdf get-lines outFileName))

Initialisation should be inside the functions or subseqeunt calls will fail.
Hans-Peter

Lutz

#19
Seems like my function doesn't work without specifying at least the form feed lines, but the page numbering still has problems on the short text buffer example. The file function seems to work fine but will probably also do wrong paging on very short files where it inserts empty lines to fill the page.



The problem is with the 'get-lines' function, it should just give a line and not do anything else if no form-feed lines are specified.



Lutz

Lutz

#20
On 7.5.3 (seek 0) or (seek (device))  for device=stdio will return the 'ftell(stdout)' value, but it only works on LINUX/BSD, on Win32 it will always give a -1.



Lutz