Re: PDF generation in D?

2016-11-22 Thread o3o via Digitalmars-d

On Thursday, 10 November 2016 at 22:30:34 UTC, Karabuta wrote:
Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)


Try http://code.dlang.org/packages/harud, a D binding to libharu.



Re: PDF generation in D?

2016-11-22 Thread Vasudev Ram via Digitalmars-d

On Tuesday, 22 November 2016 at 18:49:51 UTC, Vasudev Ram wrote:


- check out libharu - it is an open source C library for PDF


P.S. I just saw here:

http://code.dlang.org/packages/fpdf

that they say "If you don't need to be able to import PDFs, you 
may want to check out harud"  - which by the name is probably a D 
wrapper for libharu.





Re: PDF generation in D?

2016-11-22 Thread Vasudev Ram via Digitalmars-d

On Thursday, 10 November 2016 at 22:30:34 UTC, Karabuta wrote:
Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)


Hi,

I did read all the replies posted up to now. Posting a few 
alternative methods I thought of, some of which involve calling C 
libraries from D - not sure how suitable they will be for your 
specific needs, some checking will be required:


- check out libharu - it is an open source C library for PDF 
generation. If you can call it from D, it may work for your needs.


http://libharu.org/ . Libharu needs a new maintainer now, but the 
site says it still works.


- check out PDFlib(.com). PDFlib is a paid product, and the core 
is a C library. However it has an open source version IIRC, and 
may be free for personal use (not sure if you want this for 
personal or commercial use). Again, would need to call it's (C) 
functions from D. PDFlib is a mature product which has been 
around for many years. It also has binding to some other 
languages.


(I've tried both the above libs at least a bit, and they do work.)

- this one is an obvious, though roundabout method: if the D- and 
C-based ones are not suitable for whatever reason, there are 
generic methods applicable to calling (a program that uses) a 
PDF-generation library (or any library for that matter) in any 
other language, such as via XML-RPC (if D has a client library 
for that, or if D can call a C client XML-RPC library), REST or 
sockets.


- an even simpler method than above (though, of course, less 
efficient for multiple calls) may be to shell out to some 
executable [1] written in another language which has a PDF 
generation library, pass the necessary inputs on the command line 
(as command-line options,  an input file name, and an output PDF 
filename.


[1] By executable here, I don't only mean a compiled user 
executable such as a C or C++ or Java app. It could also be a 
call to a language interpreter (the executable) taking a script 
in that language, as an argument to run, and the script name 
could be followed by arguments for the script itself (e.g. python 
pdf_gen_prog.py arg1 arg2 ...) . Using this approach, for 
example, one could shell out to Python, run a Python script that 
uses ReportLab, and use that to do the job, since ReportLab is 
fairly powerful for PDF generation, though a bit low-level. 
However, it does have things like Paragraphs, Stories, Styles, 
and Platypus which are a bit higher-level. And if your PDF output 
involves only text (i.e. no images, charts, varying fonts, etc.), 
then you can even consider shelling out to a Python program you 
write, that uses xtopdf - which is my PDF generation toolkit 
written in Python, which uses ReportLab internally, and provides 
a somewhat higher abstraction for a subset of ReportLab's 
functionality, namely generation of text-only line-oriented PDF 
output, with automatic headers, footers, page numbering and 
pagination). xtopdf is quite easy to use: With low-level 
Reportlab features, you have to write your PDF generation logic 
in terms of operations on a Canvas object, not lines of text, so 
you have to say things like writeString(x, y, string), and 
calculate each x and y, reset the font to the same value after 
each new page (a limitation), but with xtopdf you get the higher 
level abstraction of something like a text file (a PDFWriter 
object), and you just write lines of text to the PDFWriter object 
using its writeLine(string) method, until you are done. Just have 
to set the header and footer and font once, first (3 lines for 
that). Total for a simple file is under 10 or so lines of Python 
code, to generate a PDF from text input, using xtopdf - with some 
amount of simple customized formatting of the text possible, in 
terms of left-or-right-justifying, centering, etc., using 
Python's easy string handling, with a few more lines of code.


ReportLab main site: http://reportlab.com

ReportLab open source version: http://reportlab.com/ftp

Good high-level overview of xtopdf: 
http://slides.com/vasudevram/xtopdf (including uses, users, 
supported input formats, supported platforms, example programs, 
etc.)


xtopdf on Bitbucket: https://bitbucket.org/vasudevram/xtopdf

xtopdf examples on my blog: 
http://jugad2.blogspot.com/search/label/xtopdf


Guide to installing and using xtopdf:

http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html

HTH,
Vasudev
jugad2.blogspot.com
vasudevram.github.io




Re: PDF generation in D?

2016-11-16 Thread Adrian Matoga via Digitalmars-d

On Wednesday, 16 November 2016 at 01:22:33 UTC, Jot wrote:


What's your point?


My point is that PS as a textual format can be easily generated 
without external libraries or tools, and then converted to an 
identically looking PDF.




Re: PDF generation in D?

2016-11-15 Thread Jot via Digitalmars-d

On Tuesday, 15 November 2016 at 15:23:29 UTC, Adrian Matoga wrote:

On Tuesday, 15 November 2016 at 11:13:54 UTC, Jot wrote:
On Tuesday, 15 November 2016 at 09:39:09 UTC, Adrian Matoga 
wrote:
On Friday, 11 November 2016 at 09:47:21 UTC, Robert burner 
Schadek wrote:
I used text files and LaTeX in the past, it works with 
everything


textfile -> process -> LaTeX -> pdf


This.

Another (a bit lower-level) option would be to produce a 
PostScript file and pass it to (e)ps2pdf.



Then that begs the question about how to generate ps in D and 
just kicks the can down the road.


PostScript is a programming language and PS files are plain 
text files with programs written in it, so formatted file 
output is your friend here.


"Lower-level" means that you need to take care of the layout of 
items on a page manually, using physical positions. It's quite 
straightforward for simple vector graphics, but not so much for 
multi-page text documents with figures and tables.


What's your point?

"PDF is largely based on PostScript but simplified to remove flow 
control features like these, while graphics commands such as 
lineto remain.


As a document format, PDF has several advantages over PostScript:

PDF contains tokenized and interpreted results of the 
PostScript source code, for direct correspondence between changes 
to items in the PDF page description and changes to the resulting 
page appearance.
PDF (from version 1.4) supports true graphic transparency; 
PostScript does not.
PostScript is an interpreted programming language with an 
implicit global state, so instructions accompanying the 
description of one page can affect the appearance of any 
following page. Therefore, all preceding pages in a PostScript 
document must be processed to determine the correct appearance of 
a given page, whereas each page in a PDF document is unaffected 
by the others. As a result, PDF viewers allow the user to quickly 
jump to the final pages of a long document, whereas a PostScript 
viewer needs to process all pages sequentially before being able 
to display the destination page (unless the optional PostScript 
Document Structuring Conventions have been carefully complied 
with).

"




Re: PDF generation in D?

2016-11-15 Thread lobo via Digitalmars-d

On Tuesday, 15 November 2016 at 15:23:29 UTC, Adrian Matoga wrote:

On Tuesday, 15 November 2016 at 11:13:54 UTC, Jot wrote:
On Tuesday, 15 November 2016 at 09:39:09 UTC, Adrian Matoga 
wrote:
On Friday, 11 November 2016 at 09:47:21 UTC, Robert burner 
Schadek wrote:
I used text files and LaTeX in the past, it works with 
everything


textfile -> process -> LaTeX -> pdf


This.

Another (a bit lower-level) option would be to produce a 
PostScript file and pass it to (e)ps2pdf.



Then that begs the question about how to generate ps in D and 
just kicks the can down the road.


PostScript is a programming language and PS files are plain 
text files with programs written in it, so formatted file 
output is your friend here.


"Lower-level" means that you need to take care of the layout of 
items on a page manually, using physical positions. It's quite 
straightforward for simple vector graphics, but not so much for 
multi-page text documents with figures and tables.


Cairo can render to a postscript surface and PDF surface[1]. 
Maybe there is something in gtkd that suits your needs[2]?


[1] https://www.cairographics.org/manual/cairo-PDF-Surfaces.html
[2] http://gtkd.org/


Re: PDF generation in D?

2016-11-15 Thread Adrian Matoga via Digitalmars-d

On Tuesday, 15 November 2016 at 11:13:54 UTC, Jot wrote:
On Tuesday, 15 November 2016 at 09:39:09 UTC, Adrian Matoga 
wrote:
On Friday, 11 November 2016 at 09:47:21 UTC, Robert burner 
Schadek wrote:
I used text files and LaTeX in the past, it works with 
everything


textfile -> process -> LaTeX -> pdf


This.

Another (a bit lower-level) option would be to produce a 
PostScript file and pass it to (e)ps2pdf.



Then that begs the question about how to generate ps in D and 
just kicks the can down the road.


PostScript is a programming language and PS files are plain text 
files with programs written in it, so formatted file output is 
your friend here.


"Lower-level" means that you need to take care of the layout of 
items on a page manually, using physical positions. It's quite 
straightforward for simple vector graphics, but not so much for 
multi-page text documents with figures and tables.




Re: PDF generation in D?

2016-11-15 Thread Jot via Digitalmars-d

On Tuesday, 15 November 2016 at 09:39:09 UTC, Adrian Matoga wrote:
On Friday, 11 November 2016 at 09:47:21 UTC, Robert burner 
Schadek wrote:
I used text files and LaTeX in the past, it works with 
everything


textfile -> process -> LaTeX -> pdf


This.

Another (a bit lower-level) option would be to produce a 
PostScript file and pass it to (e)ps2pdf.



Then that begs the question about how to generate ps in D and 
just kicks the can down the road.


Re: PDF generation in D?

2016-11-15 Thread Adrian Matoga via Digitalmars-d
On Friday, 11 November 2016 at 09:47:21 UTC, Robert burner 
Schadek wrote:
I used text files and LaTeX in the past, it works with 
everything


textfile -> process -> LaTeX -> pdf


This.

Another (a bit lower-level) option would be to produce a 
PostScript file and pass it to (e)ps2pdf.


Re: PDF generation in D?

2016-11-13 Thread Bauss via Digitalmars-d

On Thursday, 10 November 2016 at 23:42:46 UTC, Daniel Kozak wrote:

Dne 10.11.2016 v 23:30 Karabuta via Digitalmars-d napsal(a):

Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)


It depends what you need, for eg. we are using wkhtmltopdf with 
no problem. We generate some html with css and js and use 
wkhtmltopdf to generate pdf file.


I do this as well and it works elegant


Re: PDF generation in D?

2016-11-11 Thread Karabuta via Digitalmars-d
On Friday, 11 November 2016 at 09:10:38 UTC, Edwin van Leeuwen 
wrote:

On Thursday, 10 November 2016 at 22:30:34 UTC, Karabuta wrote:
Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)




Thanks everyone. I will try the various options you suggested.

Personally I would generate markdown and use a command line 
tool (pandoc) to compile it to pdf. Of course ggplotd can save 
figures in pdf format (using cairod)


I want to generated invoice in PDF format. I think markdown and 
HTML-to-pdf approach sounds manageable to me. Too bad fpdf does 
not support Unicode (has a potential though).


Re: PDF generation in D?

2016-11-11 Thread Robert burner Schadek via Digitalmars-d

I used text files and LaTeX in the past, it works with everything

textfile -> process -> LaTeX -> pdf


Re: PDF generation in D?

2016-11-11 Thread Edwin van Leeuwen via Digitalmars-d

On Thursday, 10 November 2016 at 22:30:34 UTC, Karabuta wrote:
Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)


Personally I would generate markdown and use a command line tool 
(pandoc) to compile it to pdf. Of course ggplotd can save figures 
in pdf format (using cairod)


Re: PDF generation in D?

2016-11-11 Thread Ali Çehreli via Digitalmars-d

On 11/10/2016 02:30 PM, Karabuta wrote:

Hello community, does anyone have on something for PDF generation in D?
I may need a PDF generation library in a vibe.d project I'm working on. :)


Last time I checked, there was nothing even close to the quality of 
Prince XML when it comes to print media. I use it to produce the PDF 
version of Programming in D:



https://bitbucket.org/acehreli/ddili/src/45c2eccfa97d7e2245e9f5b165aae1ea905a3cf2/src/Makefile.ders.in?at=master=file-view-default#Makefile.ders.in-264

Prince is free for personal use. Like Daniel Kozak, I give 
ddoc-generated HTML and CSS to prince.


Ali



Re: PDF generation in D?

2016-11-11 Thread qznc via Digitalmars-d

On Thursday, 10 November 2016 at 22:30:34 UTC, Karabuta wrote:
Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)


You can pull in Gtk with Cairo and Pango. Cairo can generate pdf. 
Pango is necessary for advanced text rendering.


Re: PDF generation in D?

2016-11-10 Thread Daniel Kozak via Digitalmars-d

Dne 10.11.2016 v 23:30 Karabuta via Digitalmars-d napsal(a):

Hello community, does anyone have on something for PDF generation in 
D? I may need a PDF generation library in a vibe.d project I'm working 
on. :)


It depends what you need, for eg. we are using wkhtmltopdf with no 
problem. We generate some html with css and js and use wkhtmltopdf to 
generate pdf file.




Re: PDF generation in D?

2016-11-10 Thread Guillaume Piolat via Digitalmars-d

On Thursday, 10 November 2016 at 22:30:34 UTC, Karabuta wrote:
Hello community, does anyone have on something for PDF 
generation in D? I may need a PDF generation library in a 
vibe.d project I'm working on. :)


AFAIK the only one existing is http://code.dlang.org/packages/fpdf


PDF generation in D?

2016-11-10 Thread Karabuta via Digitalmars-d
Hello community, does anyone have on something for PDF generation 
in D? I may need a PDF generation library in a vibe.d project I'm 
working on. :)