Skip to content

Commit 7ce03fc

Browse files
committed
-修复书签颜色未写入PDF文档的问题
1 parent 89c3cc0 commit 7ce03fc

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

App/Processor/DocInfoImporter.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,36 +360,39 @@ internal void ImportPageLinks(PdfReader r, PdfStamper w) {
360360
}
361361

362362
internal static void ImportColor(XmlElement item, PdfDictionary dict) {
363+
PdfArray components;
363364
if (item.HasAttribute(Constants.Color)) {
364365
var s = item.GetAttribute(Constants.Color);
365366
if (s == Constants.Colors.Transparent) {
366-
dict.Put(PdfName.C, new PdfArray());
367+
components = new PdfArray();
368+
}
369+
else {
370+
var c = Int32.TryParse(s, out var v) ? System.Drawing.Color.FromArgb(v) : System.Drawing.Color.FromName(s);
371+
components = new PdfArray(new float[] { c.R / 255f, c.G / 255f, c.B / 255f });
367372
}
368-
var c = System.Drawing.Color.FromName(s);
369-
dict.Put(PdfName.C, new PdfArray(new float[] {
370-
c.R / 255f,
371-
c.G / 255f,
372-
c.B / 255f
373-
}));
374373
}
375374
else if (item.HasAttribute(Constants.Colors.Red) || item.HasAttribute(Constants.Colors.Green) || item.HasAttribute(Constants.Colors.Blue)) {
376-
dict.Put(PdfName.C, new PdfArray(new float[] {
375+
components = new PdfArray(new float[] {
377376
item.GetValue(Constants.Colors.Red, 0f),
378377
item.GetValue(Constants.Colors.Green, 0f),
379378
item.GetValue(Constants.Colors.Blue, 0f)
380-
}));
379+
});
381380
}
382381
else if (item.HasAttribute(Constants.Colors.Gray)) {
383-
dict.Put(PdfName.C, new PdfArray(new float[] { item.GetValue(Constants.Colors.Gray, 0f) }));
382+
components = new PdfArray(new float[] { item.GetValue(Constants.Colors.Gray, 0f) });
384383
}
385384
else if (item.HasAttribute(Constants.Colors.Black) || item.HasAttribute(Constants.Colors.Cyan) || item.HasAttribute(Constants.Colors.Magenta) || item.HasAttribute(Constants.Colors.Yellow)) {
386-
dict.Put(PdfName.C, new PdfArray(new float[] {
385+
components = new PdfArray(new float[] {
387386
item.GetValue(Constants.Colors.Cyan, 0f),
388387
item.GetValue(Constants.Colors.Magenta, 0f),
389388
item.GetValue(Constants.Colors.Yellow, 0f),
390389
item.GetValue(Constants.Colors.Black, 0f)
391-
}));
390+
});
391+
}
392+
else {
393+
return;
392394
}
395+
dict.Put(PdfName.C, components);
393396
}
394397

395398
private static void ImportBorder(string border, PdfAnnotation ann) {

0 commit comments

Comments
 (0)