| Thread overview | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 17, 2010 Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Apparently, it is fairly simple to convert plain text files to PDF. http://re-factor.blogspot.com/2010/10/text-to-pdf.html Which suggests to me it should be equally simple to create a Ddoc macro file to allow Ddoc to emit pdf files directly. Anyone want a nice weekend project to product this? | ||||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 17/10/2010 18:45, Walter Bright wrote:
> Apparently, it is fairly simple to convert plain text files to PDF.
>
> http://re-factor.blogspot.com/2010/10/text-to-pdf.html
>
> Which suggests to me it should be equally simple to create a Ddoc macro
> file to allow Ddoc to emit pdf files directly.
>
> Anyone want a nice weekend project to product this?
I read the PDF spec once*, I can see in my mind what a PDF generated by DDoc could look like, and I'm quite confident in saying that it is nothing like as pretty or simple to produce as the current, most basic HTML output.
The "Hello Worlrd" for PDF (found in appendix H of the spec) makes DNA look simple and concise**.
When generating a PDF, one has to to do all the layout, calculating when to place line breaks and begin new pages. When generating HTML, all this work is left to the web browser instead, which is why PDFs always look the same, but web pages are rendered 11 different ways by 7 different browsers.
PDFs do have a tree like structure, but they are not laid out like a html file. Instead, there is a stream of cross referenced objects, each with a unique reference number and a reference to its parent and a list of its children. This means that paragraphs which span pages need to be broken up into pieces contained within different objects.
Doing a layout for an unstructured stream of text in a fixed width typeface (such as in the link you posted) is quite simple, but - as far as I can fathom - is still beyond the current DDoc. Using variable width typefaces, indentation, borders, emphasis, etc. to try and produce a PDF with the same visual style as that which can be easily achieved using the current HTML macros would be very difficult (though I'm not going to go so far as saying its impossible). I think something quite pleasing could be generated with minimal post processing, but not by using DDoc alone, after all, there is post processing for DDoc right now, every time its HTML output is loaded into a browser.
So, what enhancements do I think DDoc needs to be able to support the generation of PDFs?
After a lot of thought, I have come to the conclusion that giving DDoc the power required to calculate layout in a way that is general enough to be used not only by PDF but by any other layout technology, and the ability to work with a flattened tree, is a non starter.
Alternatively, I can't help wondering if it would be possible to use Ds compile time abilities to perform the post processing necessary? Well, I know its powerful enough, but there are a few issues with letting code from another source play in your sandbox when all one wanted to do was read the instructions... But, if the DDoc macro file specified on the command line could contain D code for post processing that is run by the CTFE engine and passed the expanded DDoc, then it could be flattened, parsed to calculate line length, generate all the cross references, split it all into pages and spat out as a PDF.
I still think it would be more than 1 weekend's work though***.
CAVEAT LECTOR!
I'm not an expert at PDFs or DDoc, so I'd be very happy to be proven wrong, the wronger**** the better ^^
A...
* Not as crazy as reading it twice would be.
** I will admit that this is possibly a slight exaggeration.
*** I, however, code slower than the average bear.
**** I know that is not a real word, so don't complain ><
| |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Alix Pexton | On Mon, 18 Oct 2010 12:54:13 +0100, Alix Pexton wrote:
> On 17/10/2010 18:45, Walter Bright wrote:
>> Apparently, it is fairly simple to convert plain text files to PDF.
>>
>> http://re-factor.blogspot.com/2010/10/text-to-pdf.html
>>
>> Which suggests to me it should be equally simple to create a Ddoc macro file to allow Ddoc to emit pdf files directly.
>>
>> Anyone want a nice weekend project to product this?
>
> I read the PDF spec once*, I can see in my mind what a PDF generated by DDoc could look like, and I'm quite confident in saying that it is nothing like as pretty or simple to produce as the current, most basic HTML output.
>
> The "Hello Worlrd" for PDF (found in appendix H of the spec) makes DNA
> look simple and concise**.
>
> [...]
>
> I still think it would be more than 1 weekend's work though***.
I, too, suspect it would be quite a lot of work. The path of least resistance would probably be to go via LaTeX. Making DDOC macros for LaTeX output sounds more like a one-weekend mini project.
-Lars
| |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Alix Pexton | On 10/18/2010 06:54 AM, Alix Pexton wrote:
> On 17/10/2010 18:45, Walter Bright wrote:
>> Apparently, it is fairly simple to convert plain text files to PDF.
>>
>> http://re-factor.blogspot.com/2010/10/text-to-pdf.html
>>
>> Which suggests to me it should be equally simple to create a Ddoc macro
>> file to allow Ddoc to emit pdf files directly.
>>
>> Anyone want a nice weekend project to product this?
>
> I read the PDF spec once*, I can see in my mind what a PDF generated by
> DDoc could look like, and I'm quite confident in saying that it is
> nothing like as pretty or simple to produce as the current, most basic
> HTML output.
There's no need for all that. It took me a short time to produce a set of macros that would generate LaTeX files from ddoc. I'm sure I have it somewhere, or I could rewrite it. From there you get to produce high quality PDFs.
Andrei
| |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | > There's no need for all that. It took me a short time to produce a set of macros that would generate LaTeX files from ddoc. I'm sure I have it somewhere, or I could rewrite it. From there you get to produce high quality PDFs.
In my modest opinion, I agree: the optimal way would be LaTeX, so you post-pone rendering and processing just like you already do for HTML, as Alix noted.
| |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Alix Pexton | Alix Pexton wrote:
> After a lot of thought, I have come to the conclusion that giving DDoc the power required to calculate layout in a way that is general enough to be used not only by PDF but by any other layout technology, and the ability to work with a flattened tree, is a non starter.
Perhaps you're right. But it strikes me as possible that a Ddoc template that emits the text in some custom format, which is then read by a custom pdf generator program, could work. In other words, a two step process.
| |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu wrote:
> There's no need for all that. It took me a short time to produce a set of macros that would generate LaTeX files from ddoc. I'm sure I have it somewhere, or I could rewrite it. From there you get to produce high quality PDFs.
I think this would be great to include in the D distribution, with a web page with step-by-step instructions.
| |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 10/18/10 11:13 AM, Walter Bright wrote: > Alix Pexton wrote: >> After a lot of thought, I have come to the conclusion that giving DDoc >> the power required to calculate layout in a way that is general enough >> to be used not only by PDF but by any other layout technology, and the >> ability to work with a flattened tree, is a non starter. > > Perhaps you're right. But it strikes me as possible that a Ddoc template > that emits the text in some custom format, which is then read by a > custom pdf generator program, could work. In other words, a two step > process. Presuming that custom format is HTML then this is close to actuality. During the look 'n' feel changes for d-programming-language.org I experimented with using wkhtmltopdf (http://code.google.com/p/wkhtmltopdf/) to generate PDF versions of the documentation using the print CSS styles. Besides a couple of defects to do with page numbering the results looked very good. | |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright Attachments: | On Mon, 18 Oct 2010 11:14:54 -0700 >>>>>> "Walter" == Walter Bright <newshound2@digitalmars.com> wrote: Walter> I think this would be great to include in the D distribution, Walter> with a web page with step-by-step instructions. May I ask here whether Ddoc is recommended way to document D code over e.g. Doxygen etc.? I'm starting and would like to adopt proper tools... Sincerely, Gour -- Gour | Hlapicina, Croatia | GPG key: CDBF17CA ---------------------------------------------------------------- | |||
October 18, 2010 Re: Ddoc to PDF | ||||
|---|---|---|---|---|
| ||||
Posted in reply to David Gileadi Attachments: | On Mon, 18 Oct 2010 11:19:59 -0700 >>>>>> "David" == David Gileadi <gileadis@NSPMgmail.com> wrote: David> Presuming that custom format is HTML then this is close to David> actuality. During the look 'n' feel changes for David> d-programming-language.org I experimented with using wkhtmltopdf David> (http://code.google.com/p/wkhtmltopdf/) to generate PDF versions David> of the documentation using the print CSS styles. Besides a David> couple of defects to do with page numbering the results looked David> very good. +1 wkhtmltopdf looks very good, although I had problem with it or let's say with php-wkhtmltox extension. Sincerely, Gour -- Gour | Hlapicina, Croatia | GPG key: CDBF17CA ---------------------------------------------------------------- | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply