PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Aug 21, 2018 4:10 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Feb 07, 2018 5:30 pm 
Offline

Joined: Wed Feb 07, 2018 5:09 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 07, 2018 10:10 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 388
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 08, 2018 7:55 pm 
Offline

Joined: Wed Feb 07, 2018 5:09 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 09, 2018 4:22 pm 
Offline

Joined: Wed Feb 07, 2018 5:09 pm
Posts: 3
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 51 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group