PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Overriding DocumentLink Page Display defaults in PDFSharp
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3727
Page 1 of 1

Author:  dave-cti [ Wed Feb 07, 2018 5:30 pm ]
Post subject:  Overriding DocumentLink Page Display defaults in PDFSharp

Good morning,

I'm trying to override the default page targeting in the PdfPage.AddDocumentLink, where it doesn't change the page display to the top of the page. I found the following on a really old post:

["null null" tells Adobe Reader not to change the display of the current page. You can try "null 0" or "null 841" (for DIN A 4) instead of "null null". Or replace "/XYZ null null 0" with "/FitB" to have Reader display the complete page.]

My question would be if I want to modify the targeting within my application's code (not by modifying the line in the PdfLinkAnnotation.cs file), is that possible?

I have two current test cases:

Case A (Build a link manually):
// targetPage = PdfPage object
// pdfRefBox = PdfRectangle object

PdfLinkAnnotation refLink = new PdfLinkAnnotation();
refLink.Elements["/Type"] = new PdfLiteral("/Annot");
refLink.Elements["/Subtype"] = new PdfLiteral("/Link");
refLink.Elements["/Rect"] = new PdfLiteral(pdfRefBox.ToString());
refLink.Elements["/M"] = new PdfLiteral("D:" + DateTime.Now.ToString("yyyyMMddhhmmss") + "-06'00'");
refLink.Elements["/NM"] = new PdfLiteral("(" + Guid.NewGuid().ToString().ToLower() + ")");
refLink.Elements["/BS"] = new PdfLiteral("[0 0 0]");*/
PdfPage linkPage = targetPage.Owner.Pages[6];
refLink.Elements["/Dest"] = new PdfLiteral("[{0} 0 R/XYZ null 0 0]", linkPage.Internals.ObjectNumber);
targetPage.Annotations.Add(refLink);

// refLink.ToString() = << /BS [0 0 0] /Dest [102 0 R/XYZ null 0 0] /M D:20180207103135-06'00' /NM (b46394f3-fa1c-440e-a217-19bf1fa672ff) /Rect [97.2 202.32 214.56 210.24] /Subtype /Link /Type /Annot >>

Case B (use the AddDocumentLink function):

// targetPage = PdfPage object
// pdfRefBox = PdfRectangle object

PdfLinkAnnotation refLink = targetPage.AddDocumentLink(pdfRefBox, 6);
PdfPage linkPage = targetPage.Owner.Pages[6];
refLink.Elements["/Dest"] = new PdfLiteral("[{0} 0 R/XYZ null 0 0]", linkPage.Internals.ObjectNumber);

// refLink.ToString() = << /Dest [102 0 R/XYZ null 0 0] /M D:20180207110436-06'00' /NM (937cdbac-1398-42bb-a081-e596017bbba9) /Rect [97.2 202.32 214.56 210.24] /Subtype /Link /Type /Annot >>

Case A doesn't work at all, while case B ignores the "null 0" command. Any thoughts - particularly on case B and getting it to change the targeting?

Thanks,
Dave

Author:  TH-Soft [ Wed Feb 07, 2018 10:10 pm ]
Post subject:  Re: Overriding DocumentLink Page Display defaults in PDFShar

Hi, Dave,

Not my area of expertise.

Check what you find in the PDF file and make sure you do not have duplicate entries.

Maybe start with PdfDictionary instead of PdfLinkAnnotation and fill everything yourself.
See also:
http://pdfsharp.net/wiki/WorkOnPdfObjects-sample.ashx

Also check Adobe's PDF reference to find out which entries are needed.

Author:  dave-cti [ Thu Feb 08, 2018 7:55 pm ]
Post subject:  Re: Overriding DocumentLink Page Display defaults in PDFShar

Well, it is supposed to be the only link annotation in the document. So I'll hope that I don't have duplicates.

I saw the WorkOnPdfObjects example and while instructive, I didn't see a way to assign that dictionary to the correct page. Hence case A started with the LinkAnnotation, which can be assigned directly to the page object. Is there a way to add a dictionary object directly to a page (or perhaps I am misunderstanding the structure)?

Case A also lists all of the items required by the Adobe spec (section 12.3.2.2). Or so I think based on my reading. I'll re-read that section to make sure I am not missing something.

Thanks,
Dave

Author:  dave-cti [ Fri Feb 09, 2018 4:22 pm ]
Post subject:  Re: Overriding DocumentLink Page Display defaults in PDFShar

I have two files (zipped into one) modified here that may allow for the custom targeting.

The PdfLinkAnnotation.cs file is complete, and has the custom targeting.

The PdfPage.cs file is a very small partial, and is meant to have the custom targeting AddDocumentLink extended function added to the original PdfPage.cs file (I didn't feel the need to duplicate the entire file).

Could these get added to the source code, and included in the next NuGet Package release?

Thanks,
Dave

Attachments:
PdfLinkAnnotation-CustomLinkDisplay.zip [5.16 KiB]
Downloaded 312 times

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/