2014-02-26 23 views
-1

我有一個使用MigraDoc生成PDF文件的小型HTML-to-PDF。似乎有一個向段落添加格式化文本的錯誤。問題在於,多頁PDF中的第一頁上的所有文本的下劃線格式會丟失。粗體和斜體格式保留在所有頁面上,但下劃線僅顯示從第二頁開始。這是一個已知的Migradoc錯誤嗎?Migradoc在分頁符之前丟失了下劃線格式

,只是爲了避免在這裏進一步的問題是我的代碼:

var textFormat = this.BuildTextFormat(isBold, isItalic, isUnderline); 
var formattedText = paragraph.AddFormattedText(textFormat); 
formattedText.Add(new Text(text)); 


private TextFormat BuildTextFormat(bool isBold, bool isItalic, bool isUnderline) 
{ 
    var textFormat = TextFormat.NoUnderline; 

    if (isUnderline) 
    { 
     textFormat = TextFormat.Underline; 
    } 

    if (isBold) 
    { 
     textFormat |= TextFormat.Bold; 
    } 

    if (isItalic) 
    { 
     textFormat |= TextFormat.Italic; 
    } 

    return textFormat; 
} 

UPDATE:

只是爲了讓PdfSharp開發者知道,雖然我解決了這個問題,但我仍然無法理解它是否是一個實現或庫錯誤,或兩者兼而有之。問題通過改變樣式的定義來解決,更確切地說,是字體顏色。

對於正常的風格,我們加入了類似下面的代碼:

var style = document.Styles["Normal"]; 
    style.Font.Color = Color.Parse("0x222222"); 

然後,從正常的風格繼承了其他風格也可以有不同的顏色,也從一個十六進制代碼解析的字體。

最終的修復是微小的,只是讓改變每個解析顏色是這樣的:

style.Font.Color = Color.Parse("0xFF222222"); 

另一種方式來解決這個bug是建立一個CMYK顏色。作爲一個單獨的問題,當我這樣做時,我也注意到用上面的行解析的顏色和CMYK生成的顏色略有不同,所以顏色解析器也似乎是bug。這裏我假定十六進制顏色0x222222應該與CMYK(0,0,0,86.7)相同。

問題是爲什麼描述的修復解決了下劃線問題錯誤,爲什麼錯誤只出現在頁面制動之前?另外,有趣的是,在調試這個問題時,我最初開始刪除一些PDF內容,並且當某些表從PDF文檔中刪除時,bug也會消失,這對我來說沒有任何意義。

無論如何,謝謝你讓我知道如何創建一個mdddl文件。這有助於我測試幾件事情。

+0

避免問題的最佳方法是提供SSCCE(另請參閱:http://sscce.org/)。可能是MigraDoc錯誤,可能是一個使用問題。您可以提供顯示錯誤的MigraDoc DDL文件,而不是SSCCE:http://pdfsharp.net/wiki/MigraDocDDL.ashx –

+0

「這是已知的Migradoc錯誤嗎?」這是一個MigraDoc錯誤還是它是一個使用問題?除了截至目前爲止發佈的代碼片段之外,獲得一些反饋意見還不錯。 –

+0

顏色「0x222222」是透明的,所以「0xff222222」是不透明顏色的正確值。 MigraDoc將「0xff222222」轉換爲CMYK(0,0,0,86.7),所以代碼似乎沒有問題。但Adobe Reader似乎計算有點不同,CMYK(0,0,0,86.7)與「0xff222222」略有不同。所以「0x222222」應該是一個完全透明的顏色 - 但對於文本和下劃線以及第1頁和第2頁應該看起來一樣。但是「0xff222222」是正確的值,並且該值一切正常。 MDDDL文件允許您刪除機密數據,並且可以複製該錯誤。 –

回答

0

我無法複製MigraDoc的問題。

這是我加入MigraDoc的Hello World示例代碼:

paragraph2 = section.AddParagraph(); 
var textFormat0 = BuildTextFormat(false, false, false); 
var textFormat1 = BuildTextFormat(false, false, true); 
var textFormat2 = BuildTextFormat(false, true, false); 
var textFormat3 = BuildTextFormat(false, true, true); 
var textFormat4 = BuildTextFormat(true, false, false); 
var textFormat5 = BuildTextFormat(true, false, true); 
var textFormat6 = BuildTextFormat(true, true, false); 
var textFormat7 = BuildTextFormat(true, true, true); 
var formattedText = paragraph2.AddFormattedText(textFormat0); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat1); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat2); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat3); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat4); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat5); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat6); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat7); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat0); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat1); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat2); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat3); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat4); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat5); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat6); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat7); 
formattedText.Add(new Text("Hello, World! ")); 
paragraph2 = section.AddParagraph(); 
formattedText = paragraph2.AddFormattedText(textFormat0); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat1); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat2); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat3); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat4); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat5); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat6); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat7); 
formattedText.Add(new Text("Hello, World! ")); 
section.AddPageBreak(); 
paragraph2 = section.AddParagraph(); 
formattedText = paragraph2.AddFormattedText(textFormat0); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat1); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat2); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat3); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat4); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat5); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat6); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat7); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat0); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat1); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat2); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat3); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat4); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat5); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat6); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat7); 
formattedText.Add(new Text("Hello, World! ")); 
paragraph2 = section.AddParagraph(); 
formattedText = paragraph2.AddFormattedText(textFormat0); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat1); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat2); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat3); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat4); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat5); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat6); 
formattedText.Add(new Text("Hello, World! ")); 
formattedText = paragraph2.AddFormattedText(textFormat7); 
formattedText.Add(new Text("Hello, World! ")); 

這導致兩個頁面的PDF文件,然後帶下劃線的文本正確顯示兩個頁面上。

不是一個普遍的問題 - 我應該等待SSCCE。

+0

感謝並且很抱歉讓您等待。我更新了我的初始帖子。這個問題有點複雜,難以複製。抱歉,我無法在此處提交我的完整代碼 – lekso