Skip to content

Commit 53c7728

Browse files
committed
Fix #617, #635
1 parent b36ed33 commit 53c7728

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

pkg/pdfcpu/model/attach.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func decodeFileSpecStreamDict(sd *types.StreamDict, id string) error {
6666
return sd.Decode()
6767
}
6868

69-
func fileSpectStreamFileName(xRefTable *XRefTable, d types.Dict) (string, error) {
69+
func fileSpecStreamFileName(xRefTable *XRefTable, d types.Dict) (string, error) {
7070
o, found := d.Find("UF")
7171
if found {
7272
fileName, err := xRefTable.DereferenceStringOrHexLiteral(o, V10, nil)
@@ -105,7 +105,7 @@ func fileSpecStreamDict(xRefTable *XRefTable, d types.Dict) (*types.StreamDict,
105105
}
106106

107107
// NewFileSpectDictForAttachment returns a fileSpecDict for a.
108-
func (xRefTable *XRefTable) NewFileSpectDictForAttachment(a Attachment) (*types.IndirectRef, error) {
108+
func (xRefTable *XRefTable) NewFileSpecDictForAttachment(a Attachment) (*types.IndirectRef, error) {
109109
modTime := time.Now()
110110
if a.ModTime != nil {
111111
modTime = *a.ModTime
@@ -115,7 +115,15 @@ func (xRefTable *XRefTable) NewFileSpectDictForAttachment(a Attachment) (*types.
115115
return nil, err
116116
}
117117

118-
d, err := xRefTable.NewFileSpecDict(a.ID, types.EncodeUTF16String(a.ID), a.Desc, *sd)
118+
// TODO insert (escaped) reverse solidus before solidus between file name components.
119+
120+
// TODO Migrate to UTF-8 for both F and UF
121+
s, err := types.EscapeUTF16String(a.ID)
122+
if err != nil {
123+
return nil, err
124+
}
125+
126+
d, err := xRefTable.NewFileSpecDict(a.ID, *s, a.Desc, *sd)
119127
if err != nil {
120128
return nil, err
121129
}
@@ -138,7 +146,7 @@ func fileSpecStreamDictInfo(xRefTable *XRefTable, id string, o types.Object, dec
138146
}
139147
}
140148

141-
fileName, err := fileSpectStreamFileName(xRefTable, d)
149+
fileName, err := fileSpecStreamFileName(xRefTable, d)
142150
if err != nil {
143151
return nil, "", "", nil, err
144152
}
@@ -210,7 +218,7 @@ func (ctx *Context) AddAttachment(a Attachment, useCollection bool) error {
210218
}
211219
}
212220

213-
ir, err := xRefTable.NewFileSpectDictForAttachment(a)
221+
ir, err := xRefTable.NewFileSpecDictForAttachment(a)
214222
if err != nil {
215223
return err
216224
}

pkg/pdfcpu/property.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ func PropertiesAdd(ctx *model.Context, properties map[string]string) error {
5252

5353
for k, v := range properties {
5454
k1 := types.UTF8ToCP1252(k)
55-
v1 := types.UTF8ToCP1252(v)
56-
d[k1] = types.StringLiteral(v1)
57-
ctx.Properties[k1] = v1
55+
d[k1] = types.StringLiteral(v)
56+
ctx.Properties[k1] = v
5857
}
5958

6059
return nil

0 commit comments

Comments
 (0)