Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I would like to replace a type1 font (Embedded subset) name and I tried to replace font name in fontfile3 stream but still its not achieved

C#
PdfName baseFont = dict.GetAsName(PdfName.BASEFONT);            
        if (baseFont.GetBytes()[7] == '+')
        {
            string rename = baseFont.ToString().Substring(8);

            string temp = baseFont.ToString().Replace(rename, "Changed" + cnt).Replace("/", "");
            baseFont = new PdfName(temp);                
            dict.Put(PdfName.BASEFONT, baseFont);
            cnt++;
        }

        PdfDictionary fontDescriptor = dict.GetAsDict(PdfName.FONTDESCRIPTOR);
        PdfDictionary Encoding = dict.GetAsDict(PdfName.ENCODING);


        if (fontDescriptor == null)
            return;
        fontDescriptor.Put(PdfName.FONTNAME, baseFont);
 PRStream stream = (PRStream)fontDescriptor.GetAsStream(PdfName.FONTFILE3);
byte[] data = PdfReader.GetStreamBytes(stream);
var str = System.Text.Encoding.Default.GetString(data);
                byte[] myByte = System.Text.Encoding.Default.GetBytes(str.Replace("OldName", "NewName"));
 PdfStream NewStream = new PdfStream(myByte);
                PdfIndirectObject objref = stamper.Writer.AddToBody(NewStream);
fontDescriptor.Put(PdfName.FONTFILE3, objref.IndirectReference);


by using the above code i am able to change the font name in acrobat document property.
but old name remain same when i select the text using edit text in acrobat 10
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900