PDFGen icon indicating copy to clipboard operation
PDFGen copied to clipboard

Is inline colouring possible?

Open ghost opened this issue 1 year ago • 6 comments

Lets say I wanted to emphasis or colourize mid part of the sentence.

[default black]This is an example[now red]of inline colouring[now black]within the same sentence in a PDF document.

I'm asking since you're supposed to position manually just like how it is with postscript (and in turn, PDF) creation, I feel it would be a pain to manually place multiple strings on the same line.

ghost avatar Oct 20 '24 19:10 ghost

Hey. Yes, that would be a good feature. The absolute positioning makes that pretty tricky at the moment, so it would be better to be done automatically under the hood. It would require some kind of markdown-like parser, which might be a bit involved. Is there a simple syntax that already exists that might suit (to cover things like underline, strike through, colour etc...)?

Right now there isn't a trivial answer - you'd have to break it up yourself externally and then build each element separately with absolute positioning. Possible, but awkward.

AndreRenaud avatar Oct 23 '24 00:10 AndreRenaud

I can't think of any markup-like format that would perfect fit this library's needs. A custom format might be a reasonable choice though. Something as simple as pairs of square brackets. Content in the first square brackets dictate what the style is, and content in the second is the text. This would make writing a parser easy. So:

[bold][This text is bold]
[italic][This text is italic]
[24][This text is font size 24]
[blue][This text is blue]
[#ff0000][This text is red]
[https://example.com][This text is a link]
[bold red 32][This text is large bold red]

SamWindell avatar Jan 04 '25 14:01 SamWindell

That markdown system seems ok. It'd be nice if there was something semi-standard that we could use, rather than inventing another new one. But traditional markdown is too complex for this scenario I think.

I don't have time at the moment to implement this parser though, so I'm not sure when this will get actioned.

AndreRenaud avatar Jan 15 '25 01:01 AndreRenaud

https://www.bbcode.org/ looks like a good fit, and I believe it's pretty much standardised. A subset could be implemented, and that subset specified.

AnonymouX47 avatar Jun 13 '25 19:06 AnonymouX47

Yes, using bbcode would make the most sense, it's very similar to what @SamWindell was suggesting already, and writing a minimal parser for it probably isn't too terrible. I might have a play with this, but very likely that I'll run out of time on it, so any PR/assistance would be welcome. Based on https://www.bbcode.org/reference.php, I think bold, italic, underline, strikethrough & colour are all reasonable. font-size, and alignment are plausible, although probably best skipping initially.

AndreRenaud avatar Jun 16 '25 00:06 AndreRenaud

Just to mention that bbcode is indeed a good fit, I made a very simple AGS Script module that had a dumbed down syntax inspired by bbcode, and the parse was very simple to implement.

ericoporto avatar Jul 16 '25 22:07 ericoporto