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:47 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Nov 04, 2019 12:02 am 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
Hi

I'm switching from pdfsharp to migradoc.
I used this code example to make bookmarks using pdfsharp:

http://www.pdfsharp.net/wiki/Bookmarks-sample.ashx

How do I make bookmarks (that work in adobe reader) using migradoc?
Can somebody give a code example for migradoc, similar to the code example for pdfsharp?

Thanks
Jessica


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 04, 2019 9:41 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!
Jessica wrote:
How do I make bookmarks (that work in adobe reader) using migradoc?
Check this sample:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

IIRC it is the OutlineLevel that creates bookmarks and the standard headings have it by default.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 04, 2019 3:39 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
Hi

I have a strange problem creating bookmarks using the OutlineLevel in MigraDoc. I'm using MigraDoc 1.50.5147, installed using nuget (Visual Studio 2019, latest updates). (I don't have PDFSharp installed separately in my project)

The code I use to make a bookmark is this ("text" is a long string"):

Code:
Paragraph paragraph = section.AddParagraph(text);
paragraph.Format.OutlineLevel = OutlineLevel.Level1;
paragraph.AddBookmark("bookmark test");


Things that work:

- the paragraph is added in the PDF, the string "text" is displayed correctly
- the outlinelevel is working (visible in Adobe Reader)

Things that don't work:

- instead of using "bookmark test" as bookmark, I see in Adobe Reader that MigraDoc is using a part of the beginning of string "text" to use as bookmark text.

Why is it not using "bookmark test"? How can I tell MigraDoc to use a specific string as bookmark string (visible in Adobe Reader)?
Which method to call for this? It seems AddBookmark() doesn't work.


In PDFSharp I used this code to add outlines (as written in the code example):

Code:
PdfOutline outline = document.Outlines.Add("Root", page, true, PdfOutlineStyle.Bold, XColors.Red);


If I want to use this code in MigraDoc, the error I get is:

Code:
Error   CS1061   'Document' does not contain a definition for 'Outlines' and no accessible extension method 'Outlines' accepting a first argument of type 'Document' could be found (are you missing a using directive or an assembly reference?)


I'm using following "using" statements in my source code:

Code:
//MigraDoc
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;

//PDFSharp
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Drawing.Layout;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;


Can anybody help please? I can't find the solution for adding a new outline to a MigraDoc PDF file, by telling which string to use as outline text (visible in Adobe Reader)

Thanks in advance!
Jessica


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 05, 2019 9:11 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!

MigraDoc is designed for documents and the text you use for various headings is automatically used for the outlines (called bookmarks in Adobe Reader). The MigraDoc bookmarks can be used for intra-document links and references, the name of the bookmark must be unique, but won't be shown to the reader.

Possible workaround: Use paragraphs with OutlineLevel, very small font (like 0.0001) and white or transparent text color. I used that trick for start pages that have a MigraDoc image, but no MigraDoc text - I added this ultra-small text to add the page to the outlines.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 05, 2019 1:04 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
Hi

I'm a beginner and I don't understand what you mean!

I want to do this:

1) make a new paragraph

2) for that paragraph I want a outline in adobe reader, that when clicked, the document navigates automatically to the paragraph created in 1)
The outline must have a name I can specify with a string (like pdfsharp)

What method do I have to call for this in migradoc? Is a small code example possible (just to create the outline)?


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 05, 2019 1:33 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
When using MigraDoc, the text on the PDF page is the text used in the bookmark treeview in Adobe Reader.
If you want to make it look like different texts, use very small white text on the PDF page for the text the reader should see in the treeview only. Use ordinary black text for the text the reader should read on the PDF page.

It's a hack, it's a workaround - but I don't have a better idea at the moment.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 05, 2019 3:52 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
Hi

So I need to add a paragraph with invisible text and outline level set, in order to let migradoc use this for outline (but invisible in the PDF to read)?

And the other paragraphs that don't need outlines I have to set to OutlineLevel.BodyText ?

Is that correct? Please confirm!

Is there no correct method like SetOutline() on a paragraph or why is this not implemented? It's a basic feature I think.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 06, 2019 9:13 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Jessica wrote:
It's a basic feature I think.
MigraDoc is much like Word. It was made for documents, not just for PDF.
Can Word handle this?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 06, 2019 5:07 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
If you support PDF, then there must be a way to set an outline to a user-defined string.
That's what I mean! PDFSharp can do it, but ... MigraDoc can't. Weird to me :-)


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

All times are UTC


Who is online

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