#1 2015-03-02 11:10:58

mogulza
Member
Registered: 2015-03-02
Posts: 13

Adding an index at the end of a PDF document

Hi all,

I have been investigating the library for creating PDF documents of my TRichEdit content.  I came upon the sample at http://synopse.info/forum/viewtopic.php?id=76 and things seem to be good so far.

I would now like to add an index of selected words to the end of the PDF but I do not understand how to do this from any of the documentation and there does not seem to be any sample code.  Can anyone help me out with this please?

Regards

Last edited by mogulza (2015-03-02 11:12:00)

Offline

#2 2015-03-02 12:23:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Adding an index at the end of a PDF document

The easiest is to use TGDIPages methods:
- a table using AddColumns() + DrawTextAcrossCols()
- row text using AddText()

Take a look at sample "05 - Report created from code".

Offline

#3 2015-03-03 07:45:05

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

Thanks ab .... your suggestion can work for adding the entries.  The problem would then be ... how do I know on which page (or pages) each of the index entries has ended up on, after feeding the TRichEdit content to TGDIPages ..... ?

Offline

#4 2015-03-03 08:12:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Adding an index at the end of a PDF document

You would have to hack TGDIPages.AppendRichEdit() so that you get the LastChar index value of each page, and process the internal text.

Offline

#5 2015-03-03 08:52:07

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

Thanks ab ... will look into this

Offline

#6 2015-03-03 11:19:30

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

Hi ab ... managed to get it all done!  The heart of the changes is redefining AppendRichEdit by adding an lst parameter as follows:

    procedure AppendRichEdit(RichEditHandle: HWnd; lst : TList = NIL);   // rev change by mogulza

The first line of AppendRichEdit() code has the following line added:

  if lst <> NIL then lst.Clear; // rev line added by mogulza

and further down

        LastChar := SendMessage(RichEditHandle, EM_FORMATRANGE, 1, Integer(@Range));
        if lst <> NIL then lst.Add(pointer(LastChar)); // rev line added by mogulza

On return from AppendRichEdit, each entry of the lst variable represents a page and each page value contains the lastchar value for the page i.e. the lastchar for page 1 would be integer(lst.Items[0]) and page 2 would be integer(lst.Items[1])  etc.

Hope this all makes sense

Thanks for your help

Offline

#7 2015-03-03 12:37:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Adding an index at the end of a PDF document

I've added an optional EndOfPagePositions parameter to TGDIPages.AppendRichEdit().
See http://synopse.info/fossil/info/d1e476884d

It could be handy in your case - a TIntegerDynArray does make better sense to me than casting a TList to integers.
Thanks for sharing!

Offline

#8 2015-03-03 13:02:35

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

Thanks AB .... downloaded your update and amended my code accordingly !!

Offline

#9 2015-03-04 06:21:21

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

Hi ab ... I decided to bite the bullet and bypass the TRichEdit component by writing directly to the TGDIPages component.  The issue I have at the moment is that I am unable to write multi-coloured lines.

I have lines that typically have red text followed by blue text followed black text .... but the DrawText() method always adds a new line and so each of my colored texts appear on a separate line.  Is there any way to achieve multicolored text lines? Essentially we need a new DrawText method that is able to able to draw text from the current YPos and XPos without adding a new line after each call.

The other thought I had was adding a method called:

DrawColouredText(const StringArray: array of SynUnicode; const Color: array of integer)

which could happily add a new line at the end

Are you able to do something along these lines for us?

Regards

Offline

#10 2015-03-04 16:17:40

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

Hi ab ...

I have been moving on with respect to replacing TRichEdit with TGDIPages ... still have not resolved the issue above ... but the next issue is DrawTextAcrossCols for my index, whereby I would like each index entry to hot link to a bookmark.  It turns out we need

   procedure DrawTextAcrossCols(const StringArray: array of SynUnicode; const BookmarkArray: array of string; BackgroundColor: TColor=clNone);

I am really trying my best to add this new methods to the as well as

   procedure DrawColouredText(const StringArray: array of SynUnicode; const Color: array of integer)

as mentioned previously but it I am really battling

Regards

and

Offline

#11 2015-03-05 08:17:56

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

Hi ab ...

I have succeeded in implementing multicolored lines by changing

procedure TGDIPages.DrawText(const s: string);

to

procedure TGDIPages.DrawText(const s: string; bWithNewLine : Boolean = TRUE);

and thereafter changing all subsequent calls to contain the bWithNewLine parameter as required.  I have also had to add a new class member variable that keeps the remembers the last leftOffset.

Question : would you be interested in these changes?  If so .... please email me and I will send you the original and changed mormotreport.pas files

Offline

#12 2015-03-05 08:36:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Adding an index at the end of a PDF document

Sounds like a good and simple implementation pattern.

I've emailed you. smile

Offline

#13 2015-03-05 11:55:02

mogulza
Member
Registered: 2015-03-02
Posts: 13

Re: Adding an index at the end of a PDF document

ab,

I just want to be sure that you have received my emails.  First email with changes as discussed above.  Second email which also contains code for adding link support to DrawTextAcrossCols

Regards
Mike

Offline

#14 2015-03-05 12:58:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Adding an index at the end of a PDF document

Yes, I received the emails.

Should be implemented by http://synopse.info/fossil/info/525eb2f95b

I've modified your patch a little, so that it would be more compatible with existing code.
Thanks a lot!

Offline

Board footer

Powered by FluxBB