Skip to content

Reading an RTF doc in PhpOffice/PhpWord displaying the style as part of the text content #1009

@ademola-raimi

Description

@ademola-raimi

I have been trying to read and convert Word and RTF resume into formatted text. I was able to convert Word successfully, however, RTF doc is displaying the styles as part of the text. How do I resolve this?
Here is my code:

 $source = __DIR__ . "/Resumes/Curriculum-Vitae-Template.rtf";
            $phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'RTF');
            $sections = $phpWord->getSections();
            foreach ($sections as $key => $value) {
                $sectionElement = $value->getElements();
                foreach ($sectionElement as $elementKey => $elementValue) {
                    if ($elementValue instanceof \PhpOffice\PhpWord\Element\TextRun) {
                        $secondSectionElement = $elementValue->getElements();
                        foreach ($secondSectionElement as $secondSectionElementKey => $secondSectionElementValue) {
                                if ($secondSectionElementValue instanceof \PhpOffice\PhpWord\Element\Text) {
                                    echo $secondSectionElementValue->getText() . '<br/>';
                                }
                        }
                    }
                }
            }
            die;

The output is shown below:

Normal;heading 1;heading 2;heading 3;Default Paragraph Font;Normal
Table;Heading 1 Char;Heading 2 Char;Heading 3 Char;Job Title;Job Title
Char;Contact Information;Normal Body Text;All Caps;Location;Space
After;Placeholder Text;Balloon Text;Balloon Text Char;Your Name;Space
After 1 (No Right Indent);Section Heading;Italic Heading;header;Header
Char;footer;Footer
Char;;;;;;;_TemplateIDTC101695599990http://schemas.microsoft.com/office/word/2003/wordml0110Macintosh
HD:Users:charlesgendron:Downloads:TS010169559.dotx[Name]Page
2...)()()()()()

[Name][Street Address], [City, ST ZIP Code] | [Phone] |
[E-Mail]EDUCATION[Elm University, Chapel Hill, NC][Ph.D. in
English][Pick the Year][Dissertation: The Cross-Cultural Communication
Epidemic of the 21st Century][Honors: Dissertation passed with
Distinction][Elm University, Chapel Hill, NC][M.A. in English][Pick
the Year][Thesis: The Accessibility Debate of Content in the Online
Context][Oak Tree University, Raleigh, NC][B.A. Honors in
English][Pick the Year][Areas of Concentration: Journalism, Proposal
Writing][Minor: French][Honors Thesis: The Female Betrayed and Modern
Media]AWARDS[Postdoctoral Fellowship, Elm University][Start Date] [End
Date][Presidents Fellowship, Oak Tree University][Start Date] [End
Date][Excellence Grant, Oak Tree University][Start Date] [End
Date]TEACHING EXPERIENCE[Walnut Grove University, Chapel Hill,
NC][Lecturer Global Communication in the 21st Century][Pick the
Year][Developed syllabus and overall course structure, and
administered all grades.][Adjunct Instructor Editing Technical
Documents][Pick the Year][Developed syllabus and overall course
structure, and administered all grades.][Instructor French 101, 102,
201, 202][Pick the Year[Developed syllabus and overall course
structure, including weekly lab practicum, and administered all
grades.][Teaching Assistant to Professor Garth Fort in Advanced
Rhetoric][Pick the Year][Collaborated on curriculum and exam
development, met with students upon request, and graded all written
work, including final exam papers.]RELATED EXPERIENCE[Lucerne
Publishing, Raleigh, NC][Editor][Start Date] [End Date][Provide as
needed editorial support remotely, including developmental and copy
editing of their internal online and printed documentation.][Wide
World Importers, Durham, NC][Researcher][Start Date] [End
Date][Compile reports, including statistical and market trends, to
track the growth of online shipping sales versus the primary offline
practices.][Fabrikam, Inc., Raleigh, NC][Language Consultant][Pick the
Year[Translated American-English external Web site content to
French.][Trey Research, Raleigh, NC][User Interface Design
Consultant][Pick the Year][Provided content design feedback to program
managers to create accessible segue between English and French
versions of related content.]PUBLICATIONS AND PAPERS[The
Cross-Cultural Communication Epidemic of the 21st Century][Guest
speaker at the Global Communication Convention, Los Angeles, CA][Pick
the Year][Why So Many Documents Remain Inaccessible in the Information
Age][Paper presented at the Annual Meeting of English Professors, New
York, NY][Pick the Year][The Female Betrayed and Modern Media][Paper
presented to the Historical Society for American Women, Athens,
Ohio][Pick the Year]LANGUAGES[English native language][French speak
fluently and read/write with high proficiency][Spanish and Italian
speak, read, and write with basic competence]MEMBERSHIPS[American
Society of English Honorees][Western Society of Women
Writers][Organization of Global Communicators]

;heading 1;heading 2;heading 3;heading 4;heading 5;heading 6;heading
7;heading 8;heading 9;Normal Indent;List Bullet;List Number;List
Bullet 2;List Number 2;Title;List Continue;List Continue
2;Subtitle;Block Text;Strong;Emphasis;Table Grid;Placeholder
Text;Revision;List Paragraph;Quote;Intense Quote;Medium List 2 Accent
1;Medium Grid 1 Accent 1;Medium Grid 2 Accent 1;Medium Grid 3 Accent
1;Dark List Accent 1;Colorful Shading Accent 1;Colorful List Accent
1;Colorful Grid Accent 1;Light Shading Accent 2;Light List Accent
2;Light Grid Accent 2;Medium Shading 1 Accent 2;Medium Shading 2
Accent 2;Medium List 1 Accent 2;Medium List 2 Accent 2;Medium Grid 1
Accent 2;Medium Grid 2 Accent 2;Medium Grid 3 Accent 2;Dark List
Accent 2;Colorful Shading Accent 2;Colorful List Accent 2;Colorful
Grid Accent 2;Light Shading Accent 3;Light List Accent 3;Light Grid
Accent 3;Medium Shading 1 Accent 3;Medium Shading 2 Accent 3;Medium
List 1 Accent 3;Medium List 2 Accent 3;Medium Grid 1 Accent 3;Medium
Grid 2 Accent 3;Medium Grid 3 Accent 3;Dark List Accent 3;Colorful
Shading Accent 3;Colorful List Accent 3;Colorful Grid Accent 3;Light
Shading Accent 4;Light List Accent 4;Light Grid Accent 4;Medium
Shading 1 Accent 4;Medium Shading 2 Accent 4;Medium List 1 Accent
4;Medium List 2 Accent 4;Medium Grid 1 Accent 4;Medium Grid 2 Accent
4;Medium Grid 3 Accent 4;Dark List Accent 4;Colorful Shading Accent
4;Colorful List Accent 4;Colorful Grid Accent 4;Light Shading Accent
5;Light List Accent 5;Light Grid Accent 5;Medium Shading 1 Accent
5;Medium Shading 2 Accent 5;

Notice how the style is part of the text, I need to eliminate the
style, How do I do these?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions