PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 9:05 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 20 posts ] 
Author Message
PostPosted: Mon Oct 18, 2010 9:36 am 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
how can i create something like bookmark but in the text of pdf?


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 18, 2010 11:29 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
You can create a Table of Contents (see HelloMigraDoc sample) or work with Hyperlinks (viewtopic.php?p=1976#p1976).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 18, 2010 11:51 am 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
the main problem- i'm confused of idea using pdfsharp and MigraDoc together. pdfsharp is so easy, but MigraDoc in my see not easy, or may be i wrong. i using pdfsharp because it simply can add new pdf document to main pdf, but i can't see how to add existing pdf to migradoc


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 18, 2010 2:09 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
webdvlp wrote:
the main problem- i'm confused of idea using pdfsharp and MigraDoc together.

I couldn't tell from your first post that you'd prefer to use PDFsharp.

AddHyperlink is PDFsharp - and a Table of Contents from MigraDoc finally leads to AddHyperlink.

So AddHyperlink is a solution for you.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 18, 2010 2:30 pm 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
AddHyperlink is from migradoc, not from pdfsharp


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 18, 2010 2:47 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Shame on me, you're right.

The PdfPage class offers:
  • AddDocumentLink
  • AddWebLink
  • AddFileLink

And AddDocumentLink is what you need to create links within a document.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 6:12 am 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
thx for AddDocumentLink, but last adobe reader don't display this area


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 8:24 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
webdvlp wrote:
thx for AddDocumentLink, but last adobe reader don't display this area

Adobe Reader only changes the mouse cursor when it's over this area. It's up to you to draw a frame or underlined text or whatever you want.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 9:34 am 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
yes, it change cursor but when i click on area, it not redirecting to need page


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 9:49 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
webdvlp wrote:
when i click on area, it not redirecting to need page

We use it to create our Table of Contents - and it works.

Destination page is one-based so you must specify 2 to go to the second page.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 12:24 pm 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
thanks for you supporting
here is my test code

Code:
PdfDocument document = new PdfDocument();
            XFont font = new XFont("Verdana", 10);

            // Create first page
            PdfPage page = document.AddPage();
           
            XGraphics gfx = XGraphics.FromPdfPage(page);
            //XRect link = new XRect(new PdfSharp.Drawing.XPoint(20, 50), new PdfSharp.Drawing.XPoint(200, 200));
            //PdfRectangle lin = new PdfRectangle(link);
            page.AddDocumentLink(new PdfRectangle(new PointF(10, 10), new PointF(50, 30)), 1);
            gfx.DrawString("first page", font, XBrushes.Black, 20, 50, XStringFormats.Default);
           

            page = document.AddPage();
            gfx = XGraphics.FromPdfPage(page);
            gfx.DrawString("second page", font, XBrushes.Black, 20, 50, XStringFormats.Default);
           
            page = document.AddPage();
            gfx = XGraphics.FromPdfPage(page);
            gfx.DrawString("third page", font, XBrushes.Black, 20, 50, XStringFormats.Default);


           


            string filename = "Bookmarks.pdf";
            document.Save(filename);



here is result pdf file
http://rapidshare.com/files/425963196/Bookmarks.pdf (can't attach it)

but there no redirects through document, also it create link zone in bottom of document, not in top.
how can it be solved?


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 2:12 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
webdvlp wrote:
Code:
            page.AddDocumentLink(new PdfRectangle(new PointF(10, 10), new PointF(50, 30)), [color=#FF0000][i][b]1[/b][/i][/color]);

but there no redirects through document, also it create link zone in bottom of document, not in top.
how can it be solved?


First page creates a link to first page. Nothing happens coz first page is already on the screen when you click the link on the first page.

Sorry, I didn't know that links use untransformed co-ordinates.
Here's the line that MigraDoc calls before adding the link:
Code:
XRect rect = this.gfx.Transformer.WorldToDefaultPage(this.hyperlinkRect);

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 2:42 pm 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
great! thx a lot for helping!


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 20, 2010 7:12 am 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
ok
all works fine, but i found i strange bug or something. here is sample pdf http://rapidshare.com/files/426108539/Bookmarks.pdf
second page (with cat), so if you scroll the cat top
Attachment:
Untitled.jpg
Untitled.jpg [ 43.51 KiB | Viewed 19782 times ]


and then click to link, it redirecting to middle of page, not top
can it be solved? i want to redirect to top


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 20, 2010 7:51 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
webdvlp wrote:
can it be solved? i want to redirect to top

In file PdfSharp\PdfSharp.Pdf.Annotations\PdfLinkAnnotation.cs locate the line
Code:
Elements[Keys.Dest] = new PdfLiteral("[{0} 0 R/XYZ null null 0]", dest.ObjectNumber);

"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.

Disclaimer: I haven't tried that myself.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 20, 2010 9:00 am 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
thanks
works perfectly!


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 20, 2010 9:02 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
webdvlp wrote:
works perfectly!

What do you use? "null 0" or "null 841"?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 20, 2010 4:35 pm 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
Thomas Hoevel wrote:
webdvlp wrote:
works perfectly!

What do you use? "null 0" or "null 841"?


i used "null 0"


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 22, 2010 8:09 am 
Offline

Joined: Mon Oct 18, 2010 9:34 am
Posts: 14
Thomas Hoevel wrote:
webdvlp wrote:
can it be solved? i want to redirect to top

In file PdfSharp\PdfSharp.Pdf.Annotations\PdfLinkAnnotation.cs locate the line
Code:
Elements[Keys.Dest] = new PdfLiteral("[{0} 0 R/XYZ null null 0]", dest.ObjectNumber);

"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.

Disclaimer: I haven't tried that myself.



hi
how fix the same problem, but in bookmarks? also not redirect at top of page? when click on bookmark


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 05, 2011 7:31 am 
Offline

Joined: Fri Mar 04, 2011 1:28 pm
Posts: 4
webdvlp wrote:
Thomas Hoevel wrote:
webdvlp wrote:
can it be solved? i want to redirect to top

In file PdfSharp\PdfSharp.Pdf.Annotations\PdfLinkAnnotation.cs locate the line
Code:
Elements[Keys.Dest] = new PdfLiteral("[{0} 0 R/XYZ null null 0]", dest.ObjectNumber);

"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.

Disclaimer: I haven't tried that myself.



hi
how fix the same problem, but in bookmarks? also not redirect at top of page? when click on bookmark



I tried the same way placing null 0 in place of "null null" it is not working for.
i had a pdf file of 200 page. when create the link and click on the link of page 1 referenced to 7th page it is focusing on other pages ie( 26th page)

but when i set the mode of view to fit, it is working perfect.

but i need it to work on normal mode of view. the problem is at
Elements[Keys.Dest] = new PdfLiteral("[{0} 0 R/A null null 0]", dest.ObjectNumber);

what sould i keep to work both fit and normal mode for indexing and bookmark.

Thanks
nagarjuna


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 151 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