#1 2012-03-28 14:55:34

Preddy2012
Member
Registered: 2012-03-28
Posts: 2

Hyperlinks in PDF

Hello,

so far the project looks pretty awesome.
Thank you for the effort you have spent developing the whole synopse project.

I've been using the htm2pdf unit to convert a newsletter from html to pdf.
I have added the event to fetch images from the server and everything seems fine.

The only thing I can't get to work are hyperlinks.
Does the converter support hyperlinks?

Or do I have to manually use the PDF-Class(es) from the synopse framework
to create pages and hyperlinks from hand?

I have looked into the source code, but to be honest,
it is a little bit too complicated for me...

Thank you for your help in advance

Matthew

Offline

#2 2012-03-28 15:13:13

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

Re: Hyperlinks in PDF

The PDF engine is able to recognize EMR_GDICOMMENT blocks inside the TMetaFile content, to embedd some SynPDF related data (like bookmarks, links, and document outline) in the source TMetaFile.

This feature is used e.g. by TSQLite3Pages.

You can use the following methods:

/// append a EMR_GDICOMMENT message for handling PDF bookmarks
// - will create a PDF destination at the current position (i.e. the last Y
// parameter of a Move), with some text supplied as bookmark name
procedure GDICommentBookmark(MetaHandle: HDC; const aBookmarkName: RawUTF8);

/// append a EMR_GDICOMMENT message for handling PDF outline
// - used to add an outline at the current position (i.e. the last Y parameter of
// a Move): the text is the associated title, UTF-8 encoded and the outline tree
// is created from the specified numerical level (0=root)
procedure GDICommentOutline(MetaHandle: HDC; const aTitle: RawUTF8; aLevel: Integer);

/// append a EMR_GDICOMMENT message for creating a Link into a specified bookmark
procedure GDICommentLink(MetaHandle: HDC; const aBookmarkName: RawUTF8; const aRect: TRect);

This should be done at rendering time, when the content is written from the THTmlView into the internal TMetaFile canvas.

Offline

#3 2012-03-29 10:50:02

Preddy2012
Member
Registered: 2012-03-28
Posts: 2

Re: Hyperlinks in PDF

Thanks for your help.
But I still dont understand how those two Classes can be combined.
I have absolutely no idea where I have to insert the code.

Here is my code:

     With THtml2Pdf.Create do
      begin
          DefaultPaperSize := psA4;
          CompressionMethod := cmFlateDecode;
          ForceJPEGCompression := StrToInt(CompressionRate.Text);
          Viewer := Thtmlviewer.Create(self);
          Viewer.Parent := Self;
          Viewer.Visible := False;
          Viewer.OnImageRequest := HTMLViewerImageRequest; // Assign event to get images from server
          Viewer.LoadFromFile(IncludeTrailingPathDelimiter(TempPath.Text) + NewsletterNameFile + '.html');
          Execute;
          SaveToFile(IncludeTrailingPathDelimiter(PDFPath.Text) + NewsletterNameFile + '.pdf');
          Free;
        end;

Where do I need to intercept?
How do I get the metahandle...
There seems to be no way to get specific text in the pdf.
Maybe I am doing something wrong.

Thanks in advance for your help.

Last edited by Preddy2012 (2012-03-29 10:50:49)

Offline

#4 2012-03-29 11:50:49

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

Re: Hyperlinks in PDF

You'll have to change the THtmlView classes rendering, and add the expected comments within the TMetaFile canvas, during the rendering itself.

This is something to do on the THtmlView side, not on the SynPdf side, which does not need to be modified.
SynPdf does not know what is a link in the supplied page content, and where it points to (only exception is http links).

Offline

#5 2014-12-11 14:38:55

Vivi
Member
Registered: 2014-10-16
Posts: 5

Re: Hyperlinks in PDF

hi
i am trying to use comments.. and i changed thtmlviewe render to CreateWithComment and it does that ok, but do i need to add something on synopse side to make it visible?

Offline

#6 2014-12-11 15:01:25

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

Re: Hyperlinks in PDF

I do not think so.
But I'm not sure.

Offline

#7 2014-12-11 15:15:50

Vivi
Member
Registered: 2014-10-16
Posts: 5

Re: Hyperlinks in PDF

ab wrote:

I do not think so.
But I'm not sure.

well, it is not visible in newly created PDF file, and if you dont know, who does? ;-)

Offline

#8 2014-12-11 16:41:45

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

Re: Hyperlinks in PDF

What did you include?
Links? Outlines? BookMarks?

We used and tested outline and bookmark without any problem.

What is not "visible" in your end pdf?

Offline

#9 2014-12-11 17:13:02

Vivi
Member
Registered: 2014-10-16
Posts: 5

Re: Hyperlinks in PDF

ab wrote:

What did you include?
Links? Outlines? BookMarks?

We used and tested outline and bookmark without any problem.

What is not "visible" in your end pdf?

i think we misunderstood, i just added TMetaFileCanvas.CreateWithComment in htmlviewer part, and that should appear like bookmark or i understood wrong?

Offline

#10 2014-12-11 17:49:15

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

Re: Hyperlinks in PDF

As I wrote above, you should use GDICommentBookmark to produce the right comment.
TMetaFileCanvas.CreateWithComment has nothing to do with SynPDF AFAIK.

Offline

Board footer

Powered by FluxBB