You are not logged in.
Pages: 1
I am trying to implement PDF export for our TRichView editor using SynPDF.
Everything is ok, except for links.
I do not understand which coordinates should I pass to CreateLink.
I assumed that pixels, but I am obviously wrong.
For example, for a test, I am trying to put a hyperlink around the whole page inside margins ((76, 76, 718, 1047) at 96 dpi).
The result is completely out of place and has wrong size:
Can you help me?
Offline
The PDF coordinates is not the same at all as Windows GDI coordinates.
It uses a 75 dpi resolution for the 1.0 value, but floating-point coordinates.
As such, there is no "pixel" in PDF.
There are several method helpers in SynPDF to change the pixel-like integer coordinates into proper PDF double coordinates.
How do you generate the pdf page? Using TMetaFile content?
Offline
I assign FPdfDoc.DefaultPaperSize (FPdfDoc is TPdfDocumentGDI)
Additionally, I assign FPdfDoc.ScreenLogPixels (currently to Screen.PixelsPerInch, but in future it may be another value).
Then call FPdfDoc.AddPage.
Then I draw onto FPdfDoc.VCLCanvas using pixel coordinates.
I have pixels positions of bookmarks and links (relative to the top of the page), how to convert them to coordinates for CreateLink and CreateBookmark?
I tried Value * 75 / 96, the results are close, but not exactly correct:
Last edited by TRichView (2016-04-21 10:00:21)
Offline
Well, probably I need to provide mode information.
Here is the example, I want to make a hyperlink around "Prep" text.
Content is made by drawing on VCLCanvas. The origin of coordinates is moved to the point marked with a green circle (using SetWindowOrgEx).
In the code below, I draw a red rectangle around the link area, and create the link.
Input:
R - link rectangle, in pixels, relative to the origin.
DocRect - rectangle of document inside the margin
// drawing a red rectangle
FPdfDoc.VCLCanvas.Brush.Style := bsClear;
FPdfDoc.VCLCanvas.Pen.Width := 1;
FPdfDoc.VCLCanvas.Pen.Style := psSolid;
FPdfDoc.VCLCanvas.Pen.Color := clRed;
FPdfDoc.VCLCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
// adding a link
OffsetRect(R, DocRect.Left, DocRect.Top);
dpi := Screen.PixelsPerInch;
PdfRect.Left := R.Left * 72 / dpi;
PdfRect.Top := R.Top * 72 / dpi;
PdfRect.Right := R.Right * 72 / dpi;
PdfRect.Bottom := R.Bottom * 72 / dpi;
FPdfDoc.CreateLink(PdfRect, StringToUTF8(Copy(Target, 2, MaxInt)));
The result is below:
Everything is correct except for Y coordinates. You can see that the link is shifted down a lot.
Last edited by TRichView (2016-04-28 08:04:01)
Offline
From a quick overview of your screenshot, it looks like the Y is simply inverted for the link.
Perhaps the CreateLink's reference point is the bottom left of the document while the rectangle's reference is the top left ? Not sure why.
Offline
While the issue is solved, I have some suggestions for future versions:
- to add explanations that sizes are measured in points, and coordinates are measured from the bottom left corner
- an option to suppress a black border for links
- ability to add links to external URLs and files; yes, URLs are auto-detected, but a visible text and a link target are not necessary identical.
By the way, I created a demo for making PDF files from RTF and RVF files using Synopse PDF Engine and our components:
http://www.trichview.com/forums/viewtopic.php?p=30151
Last edited by TRichView (2016-04-28 18:34:32)
Offline
Great!
Perhaps you should create tickets: http://synopse.info/fossil/reportlist
Those would be great additions indeed.
Offline
Pages: 1