PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 4:23 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: MigraDoc and spaces
PostPosted: Wed Dec 03, 2008 4:24 pm 
Offline

Joined: Wed Dec 03, 2008 10:07 am
Posts: 4
Hi

I add my text using

paragraph.AddFormattedText(_text, "Normal");

My problem is that my input rtf is formated with spaces, but this spaces are deleted by MigraDoc. Is there a flag which I can set to "switch off" this behavior.

I could convert my input text to a chararray and look for spaces inside but I think that would be a overkill.

Thanks MB


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 04, 2008 8:41 am 
Offline
PDFsharp Guru
User avatar

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

MigraDoc treats spaces much like HTML - and therefore you can use the same trick: if spaces must be kept use non-breakable spaces (NBSP, keyboard: Alt+<255>).
Replace ordinary spaces (Alt+<32>) with NBSP before adding text.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 04, 2008 9:17 am 
Offline

Joined: Wed Dec 03, 2008 10:07 am
Posts: 4
Hi Thomas

Thank you very much, its works great! I love PDFSharp!

MB


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDoc and spaces
PostPosted: Thu Mar 18, 2010 2:16 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi

i am trying to replace "1 2" with "1&nbsp;&nbsp;&nbsp;1"

but the text is showing as "1&nbsp;&nbsp;&nbsp;1" in the PDF and not using the non breakable spaces?

Mike


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDoc and spaces
PostPosted: Thu Mar 18, 2010 2:33 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
mikesowerbutts wrote:
i am trying to replace "1 2" with "1&nbsp;&nbsp;&nbsp;1"
but the text is showing as "1&nbsp;&nbsp;&nbsp;1" in the PDF and not using the non breakable spaces?


MigraDoc is not HTML, try the character:
Thomas Hoevel wrote:
NBSP, keyboard: Alt+<255>

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDoc and spaces
PostPosted: Thu Mar 18, 2010 3:07 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
sorry i feel really stupid, but i am literally typing "NBSP" and i get this:

"Yes < X >NBSP NBSP NBSP No <NBSP NBSP NBSP>in the pdf

?


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDoc and spaces
PostPosted: Thu Mar 18, 2010 4:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Alt+<255> means: hold down Alt while you type 255 on the numeric keypad and you'll get the blank you need.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: MigraDoc and spaces
PostPosted: Fri Jun 04, 2010 10:13 pm 
Offline

Joined: Fri Jun 04, 2010 9:22 pm
Posts: 1
Howdy,
I hate to resurrect and old thread, but I'd rather do that than start a new that's really an extension of this one.

The advice about Alt-255 has gotten me further along -- thank you! -- but I am still losing white space in lines that, normally, are created as such:
Code:
longInfo = string.Format("{0,-25}{1,-15}{2,-8}{3,-8}{4,-7}{5,-5}{6,-5}{7,-10}{8,-5}{9,-7}{10,-7}{11,-20}{12,-25}{13,-8}{14,-100}{15}",
                                  sInfo[0],sInfo[1],sInfo[2],sInfo[3],sInfo[4],sInfo[5],sInfo[6],sInfo[7],
                                  sInfo[8],sInfo[9],sInfo[10],sInfo[11],sInfo[12],sInfo[13],sInfo[14],"\r\n");

Now, this is fine for the RTF documents that are produced, but the MigraDoc PDF output, of course, strips out the trailing spaces. I have tried:
Code:
longPDFInfo = sInfo[0].PadRight(25,' ') + sInfo[1].PadRight(15,' ') +
            sInfo[2].PadRight(8,' ') + sInfo[3].PadRight(8,' ') + sInfo[4].PadRight(7,' ') +
            sInfo[5].PadRight(5,' ') + sInfo[6].PadRight(5,' ') + sInfo[7].PadRight(10,' ') +
            sInfo[8].PadRight(5,' ') + sInfo[9].PadRight(7,' ') + sInfo[10].PadRight(7,' ') +
            sInfo[11].PadRight(20,' ') + sInfo[12].PadRight(25,' ') + sInfo[13].PadRight(8,' ') +
            sInfo[14].PadRight(100,' ') + "\r\n";


Now this, to me, seems a touch cumbersome and there is probably a better way, however, for now, the issue is that the space that is in the .PadRight(xx,' ') is indeed an Alt-255 and I'm still getting text in the produced PDF with no trailing white spaces.

My question revolves around whether I need to make a specific call to the PdfDocumentRenderer. I have tried both
Code:
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

and with unicode set to false, and neither has output what I need. So, with my logic, it's either how I'm feeding it or what I'm telling it when it saves it out to the PDF. I am using monospaced fonts (either Quick Mono or Raavi) and both seem to support the Alt-255 spacing when I tested. So, I'm kind of at a loss. Any help would be greatly appreciated.

Phil


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 46 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