PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Normal Style justification
https://forum.pdfsharp.net/viewtopic.php?f=2&t=811
Page 1 of 1

Author:  sbilo [ Mon Jul 27, 2009 8:12 pm ]
Post subject:  Normal Style justification

I have a table of contents style defined and it appears that the contents is being displayed as JUSTIFIED, there are some extra embeded spaces being added. How do I find what the "Normal" style is and how can I override it to be Left Justifed ?


// Create a new style called TOC2 based on style Normal
style = document.Styles.AddStyle("TOC2", "Normal");
style.Font.Name = "Arial";
style.Font.Size = 7;
style.ParagraphFormat.AddTabStop("2.5cm", TabAlignment.Left);
style.ParagraphFormat.AddTabStop("8.5cm", TabAlignment.Right);
style.ParagraphFormat.Font.Color = Colors.Black;

thanks

Author:  sbilo [ Tue Jul 28, 2009 12:35 pm ]
Post subject:  Re: Normal Style justification

in the following code snippet:

thisRowCtr = ctr + 1;
row = table.Rows[thisRowCtr];
cell = row.Cells[0];
paragraph = cell.AddParagraph();
paragraph.Style = "TOC2";
hyperlink = paragraph.AddHyperlink(trucksection.bom + " " + trucksection.description);
hyperlink.AddText(trucksection.bom + "\t" + trucksection.description + "\t");
hyperlink.AddPageRefField(trucksection.bom + " " + trucksection.description);
}

when I break in the code where a table cell is assigned a value I get the following string that has no embedded spaces which is what I expect:

? trucksection.bom
"21800-K01393"

? trucksection.description
"ENGINE SUPPORTS"


However, when the table is displayed in the pdf there is magically a space between the - and the K. This space occurs in every cell that has the same pattern of data ... where there is a series of numeric characters followed by a DASH followed by a series of characters. The pdf table ends up looking like this:

21800- K01393 ENGINE SUPPORTS 9


So I'm thinking that somehow the contents of the cell is being formatted to spread it across the cell (justify?). Where can I see what the justification default is and how can I set it explicitly.

I tried to use without success: paragraph.Format.Alignment = ParagraphAlignment.Left;

The style is defined like this:

// Create a new style called TOC2 based on style Normal
style = document.Styles.AddStyle("TOC2", "Normal");
style.Font.Name = "Arial";
style.Font.Size = 7;
style.ParagraphFormat.AddTabStop("2.5cm", TabAlignment.Left);
style.ParagraphFormat.AddTabStop("8.5cm", TabAlignment.Right);
style.ParagraphFormat.Font.Color = Colors.Black;

thanks for any assistance!

Author:  Thomas Hoevel [ Tue Jul 28, 2009 12:43 pm ]
Post subject:  Re: Normal Style justification

Left alignment is default.

There should be no blank.
I'll check this ...

Author:  sbilo [ Tue Jul 28, 2009 1:22 pm ]
Post subject:  Re: Normal Style justification

thanks, there must be something that happens when a "-" is encountered.

I created a loop to write out a series of image locations and everywhere there is an embeded dash I get an extra space.


W:\Images\21800- 0034.GIF



//lets try a loop
// the pattern is: 21800-0001.gif thru 21800-0058.gif

string apic;
for (int a = 0; a < 59; a++)
{
apic = String.Format("{0:00}", a);

completeFilename = "W:\\Images\\21800-00" + apic + ".GIF";
document.LastSection.AddPageBreak();
document.LastSection.AddParagraph(completeFilename);
document.LastSection.AddImage(completeFilename);

}

Author:  Thomas Hoevel [ Tue Jul 28, 2009 2:40 pm ]
Post subject:  Re: Normal Style justification

I tried both GDI+ and WPF builds - and I don't see the extra space.

Maybe a font problem.
This can occur if the font used for measuring is not the font used for display.
There could be typo in the font name or the font is not supported by PDFsharp (e. g. Postscript outlines in OpenType fonts).

Words can be broken at hyphens and both parts are measured separately.
This could also explain your justification problem: words "look" big when measured, but are small when displayed causing large gaps between words and after hyphens.

Try Arial or another TrueType font that comes with Windows for a start.

Author:  sbilo [ Tue Jul 28, 2009 3:32 pm ]
Post subject:  Re: Normal Style justification

I am using Arial. My VS2008 C# project must be set up wrong?? I have a small project that just tries reading a bunch of images and adds the path + file name and image to each page. Here the filename has the - in it and here some of the images do not dislay. Zip size for the project is 1458 KB with a bunch of images - can I send it somewhere?

Author:  Thomas Hoevel [ Wed Jul 29, 2009 3:41 pm ]
Post subject:  Re: Normal Style justification

I tested your code with the current (internal) version of PDFsharp and MigraDoc Foundation and everything works fine.

It seems there was a problem retrieving the font data - the font embedded in PDF was not the font used for measuring (this led to the spaces). This problem is specific to the WPF build!
All images can be read now.


PDF sharp 1.3 will be available next month (maybe even next week).

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/