PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Oct 20, 2017 7:42 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Invisible paragraph
PostPosted: Mon Aug 14, 2017 6:08 am 
Offline

Joined: Tue Apr 26, 2016 8:24 pm
Posts: 20
It is possible to add an invisible text in the page without modifying the layout of the rest of the items.

Reason: I use hidden text as bookmark in XPS document to pin point the document viewer to the exact location of a paragraph, table, image and I need to make something hidden, adding a paragraph and modifying the style or any other option to 0 still creates a small gap between the items.


Top
 Profile  
Reply with quote  
 Post subject: Re: Invisible paragraph
PostPosted: Mon Aug 14, 2017 7:43 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2720
Location: Cologne, Germany
Using a font size of e.g. 0.001 with white text color (assuming pages are white) or 100% transparency will make the text virtually invisible.

It's a hack, but I get "invisible" bookmarks this way.

I do not fully understand what you need. Maybe an empty paragraph can be used to get a clean solution. You can use the Tag property of the paragraph to identify it.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Invisible paragraph
PostPosted: Mon Aug 14, 2017 11:16 am 
Offline

Joined: Tue Apr 26, 2016 8:24 pm
Posts: 20
I have being doing that but adding a paragraph with an invisible text (font size =0.01 and white font color) will still reserve in the final document a few millimeters.

It is for a project where i have a document structure made in a tree view something like:
chapter
-chapter
--paragraph
--paragraph
-chapter
....
And whenever I click one of the items from the treeview I want the document viewer to move to the corresponding document component in the viewer.
And one way of doing, as far I could think of, is to search in the generated XPS document the hacky bookmark that I made with invisible text but doing those kind of invisible paragraphs alters the layout of other component by few millimeters.


Top
 Profile  
Reply with quote  
 Post subject: Re: Invisible paragraph
PostPosted: Mon Aug 14, 2017 1:42 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2720
Location: Cologne, Germany
MariusIonut wrote:
I have being doing that but adding a paragraph with an invisible text (font size =0.01 and white font color) will still reserve in the final document a few millimeters.
Not when you do it the right way. You can (and should) set the absolute height of the paragraph.
Code:
paragraph.Format.LineSpacingRule = LineSpacingRule.Exactly;
paragraph.Format.LineSpacing = 0.001;
You may have to set SpaceBefore and SpaceAfter to 0.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Invisible paragraph
PostPosted: Tue Aug 22, 2017 7:34 am 
Offline

Joined: Tue Apr 26, 2016 8:24 pm
Posts: 20
Hello Thomas,
Sorry for late response, I was on a small vacation. Even with your latest suggestion it is still somehow reserving space.
Here are the DDLs:
Wanted layout: (No hidden paragraphs)
Code:
\document
{
  \styles
  {
    Normal
    {
      Font
      {
        Name = "Times New Roman"
      }
      ParagraphFormat
      {
        LeftIndent = "0mm"
        FirstLineIndent = "0mm"
        RightIndent = "0mm"
        SpaceBefore = "4mm"
        SpaceAfter = "4mm"
        LineSpacing = "0mm"
      }
    }

    HiddenBookmark : Normal
    {
      Font
      {
        Size = 0.01
      }
      ParagraphFormat
      {
        SpaceBefore = "0mm"
        SpaceAfter = "0mm"
        LineSpacingRule = Exactly
        LineSpacing = "0.001mm"
        KeepTogether = false
        KeepWithNext = false
      }
    }

    Paragraph : Normal
    {
    }
  }
  \section
  [
    PageSetup
    {
      PageHeight = 842
      PageWidth = 595
      Orientation = Portrait
      LeftMargin = "20mm"
      RightMargin = "16mm"
      TopMargin = "15mm"
      BottomMargin = "20mm"
      FooterDistance = "10mm"
      HeaderDistance = "8mm"
      OddAndEvenPagesHeaderFooter = false
      DifferentFirstPageHeaderFooter = false
      SectionStart = BreakNextPage
      PageFormat = A4
      MirrorMargins = false
      HorizontalPageBreak = false
    }
  ]
  {
    \paragraph
    [
      Style = "Paragraph"
      Format
      {
        LeftIndent = 0
        RightIndent = 0
      }
    ]
    {
      \font("Normal"){asdasd}
    }
    \paragraph
    [
      Style = "Paragraph"
      Format
      {
        LeftIndent = 0
        RightIndent = 0
      }
    ]
    {
      \font("Normal"){asdasda}
    }
  }
}

Actual layout:(with hidden paragraph)
Code:
\document
{
  \styles
  {
    Normal
    {
      Font
      {
        Name = "Times New Roman"
      }
      ParagraphFormat
      {
        LeftIndent = "0mm"
        FirstLineIndent = "0mm"
        RightIndent = "0mm"
        SpaceBefore = "4mm"
        SpaceAfter = "4mm"
        LineSpacing = "0mm"
      }
    }

    HiddenBookmark : Normal
    {
      Font
      {
        Size = 0.01
      }
      ParagraphFormat
      {
        SpaceBefore = "0mm"
        SpaceAfter = "0mm"
        LineSpacingRule = Exactly
        LineSpacing = "0.001mm"
        KeepTogether = false
        KeepWithNext = false
      }
    }

    Paragraph : Normal
    {
    }
  }
  \section
  [
    PageSetup
    {
      PageHeight = 842
      PageWidth = 595
      Orientation = Portrait
      LeftMargin = "20mm"
      RightMargin = "16mm"
      TopMargin = "15mm"
      BottomMargin = "20mm"
      FooterDistance = "10mm"
      HeaderDistance = "8mm"
      OddAndEvenPagesHeaderFooter = false
      DifferentFirstPageHeaderFooter = false
      SectionStart = BreakNextPage
      PageFormat = A4
      MirrorMargins = false
      HorizontalPageBreak = false
    }
  ]
  {
    \paragraph
    [
      Style = "HiddenBookmark"
    ]
    {
      | →ParagraphCommandxELEMENTxUNIQUExIDx1 |
    }
    \paragraph
    [
      Style = "Paragraph"
      Format
      {
        LeftIndent = 0
        RightIndent = 0
      }
    ]
    {
      \font("Normal"){asdasd}
    }
    \paragraph
    [
      Style = "HiddenBookmark"
    ]
    {
      | →ParagraphCommandxELEMENTxUNIQUExIDx2 |
    }
    \paragraph
    [
      Style = "Paragraph"
      Format
      {
        LeftIndent = 0
        RightIndent = 0
      }
    ]
    {
      \font("Normal"){asdasds}
    }
  }
}


Changing the space before and space after for style Paragraph to 0 creates the correct layout, but when any other value is used (in my case is inherited from NORMAL style) then the space after and before doubles.


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 10 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:  
Powered by phpBB® Forum Software © phpBB Group