Convert in word format

Reading File
Reading File
Reading File
Browsing Directory

~/

Searching the Web

PowerPoint to Word conversion preserve slide content Word document best practices

Browsing Directory

~/attachments/b514f745-44a7-48e8-afed-e770a2348404

Running Command

mkdir -p "/tmp/workspace/pptx-to-word/src" "/tmp/workspace/pptx-to-word/output" "/tmp/workspace/pptx-to-word/assets" && python - <<'PY' from pptx import Presentation from pathlib import Path src=Path('/tmp/workspace/attachments/b514f745-44a7-48e8-afed-e770a2348404/TITLE_ A STUDY OF RED CELL DISTRIBUTION WIDTH AS A PROGNOSTIC MARKER IN PATIENTS WITH HEART FAILURE.pptx') prs=Presentation(src) out=Path('/tmp/workspace/pptx-to-word/src/slide_inventory.txt') with out.open('w',encoding='utf-8') as f: f.write(f'Slides: {len(prs.slides)}\n') for i,slide in enumerate(prs.slides,1): f.write(f'\n=== SLIDE {i} ===\n') for shape in slide.shapes: if getattr(shape,'has_text_frame',False) and shape.text_frame.text.strip(): f.write('TEXT: '+shape.text_frame.text.replace('\n',' | ')+'\n') if getattr(shape,'has_table',False): f.write('TABLE:\n') for row in shape.table.rows: f.write(' | '.join(cell.text.replace('\n',' ') for cell in row.cells)+'\n') if shape.shape_type == 13: f.write('IMAGE\n') print(f'Inventory written: {out}; slides={len(prs.slides)}') PY

Reading File
Reading File
Reading File
Reading File
Running Command

python - <<'PY' from pathlib import Path from pptx import Presentation from docx import Document from docx.shared import Pt, Inches, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.enum.section import WD_SECTION from docx.oxml import OxmlElement from docx.oxml.ns import qn from docx.enum.style import WD_STYLE_TYPE src=Path('/tmp/workspace/attachments/b514f745-44a7-48e8-afed-e770a2348404/TITLE_ A STUDY OF RED CELL DISTRIBUTION WIDTH AS A PROGNOSTIC MARKER IN PATIENTS WITH HEART FAILURE.pptx') out=Path('/tmp/workspace/pptx-to-word/output/Red_Cell_Distribution_Width_Heart_Failure_Study.docx') prs=Presentation(src) doc=Document() sec=doc.sections[0] sec.top_margin=Inches(.7); sec.bottom_margin=Inches(.7); sec.left_margin=Inches(.8); sec.right_margin=Inches(.8) styles=doc.styles styles['Normal'].font.name='Arial'; styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'),'Arial'); styles['Normal'].font.size=Pt(10.5) styles['Title'].font.name='Arial'; styles['Title'].font.size=Pt(20); styles['Title'].font.bold=True; styles['Title'].font.color.rgb=RGBColor(31,78,121) for nam, size, col in [('Heading 1',15,RGBColor(31,78,121)),('Heading 2',12,RGBColor(47,84,150))]: styles[nam].font.name='Arial'; styles[nam].font.size=Pt(size); styles[nam].font.bold=True; styles[nam].font.color.rgb=col # footer pages footer=sec.footer.paragraphs[0]; footer.alignment=WD_ALIGN_PARAGRAPH.CENTER r=footer.add_run('Study Protocol | '); r.font.name='Arial'; r.font.size=Pt(8) fld=OxmlElement('w:fldSimple'); fld.set(qn('w:instr'),'PAGE'); footer._p.append(fld) def shade(cell, fill): tcPr=cell._tc.get_or_add_tcPr(); shd=OxmlElement('w:shd'); shd.set(qn('w:fill'),fill); tcPr.append(shd) def add_runs(par, text): # Split slide soft returns; clean but retain content text=text.replace('\x0b','\n').replace('\r','\n') for j,line in enumerate(text.split('\n')): line=line.strip() if not line: continue if j and par.text: par.add_run('\n') par.add_run(line) def is_heading(txt): s=txt.strip().replace('\n',' ').strip() if not s or len(s)>65: return False alpha=''.join(ch for ch in s if ch.isalpha()) return len(alpha)>2 and (s.upper()==s or s.endswith(':')) def append_text(txt): txt=txt.replace('\x0b','\n').replace('\r','\n').strip() if not txt:return lines=[x.strip() for x in txt.split('\n') if x.strip()] # Convert bullets / pipe-separated presentation items to Word bullets when likely lists if len(lines)>1 and all(x.startswith(('●','•','-','–')) for x in lines): for l in lines: p=doc.add_paragraph(style='List Bullet'); p.add_run(l.lstrip('●•-– ').strip()) else: # preserve short repeated line content; use normal paragraph p=doc.add_paragraph() add_runs(p,txt) # Title page based on slide 1 slide1=prs.slides[0] alltxt=[] for sh in slide1.shapes: if getattr(sh,'has_text_frame',False): t=sh.text_frame.text.strip() if t: alltxt.append(t) title=alltxt[0].replace('TITLE:','').strip() if alltxt else 'Study Protocol' p=doc.add_paragraph(style='Title'); p.alignment=WD_ALIGN_PARAGRAPH.CENTER; p.add_run(title) doc.add_paragraph('') for t in alltxt[1:]: p=doc.add_paragraph(); p.alignment=WD_ALIGN_PARAGRAPH.CENTER; add_runs(p,t) doc.add_page_break() for si,slide in enumerate(prs.slides[1:],start=2): texts=[] tables=[] for sh in slide.shapes: if getattr(sh,'has_text_frame',False): t=sh.text_frame.text.strip() if t: texts.append(t) if getattr(sh,'has_table',False): tables.append(sh.table) # First concise title-like text as heading; otherwise generic source marker head=None for i,t in enumerate(texts): if is_heading(t): head=t.strip().replace('\n',' ').rstrip(':').title() if t.isupper() else t.strip().rstrip(':') texts.pop(i); break if not head: head=f'Slide {si}' doc.add_heading(head,level=1) for t in texts: append_text(t) for tbl in tables: wt=doc.add_table(rows=len(tbl.rows), cols=len(tbl.columns)); wt.style='Table Grid' for ri,row in enumerate(tbl.rows): for ci,cell in enumerate(row.cells): wt.cell(ri,ci).text=cell.text if ri==0: shade(wt.cell(ri,ci),'D9EAF7') doc.add_paragraph() # Keep slide provenance without clutter p=doc.add_paragraph(); p.paragraph_format.space_after=Pt(4) r=p.add_run(f'Source: presentation slide {si}'); r.italic=True; r.font.size=Pt(8); r.font.color.rgb=RGBColor(100,100,100) if si < len(prs.slides): doc.add_page_break() # metadata doc.core_properties.title=title doc.core_properties.author='Dr. Ayushi Agrawal' doc.core_properties.subject='Study protocol converted from presentation' doc.save(out) print(out, out.stat().st_size) PY python - <<'PY' from docx import Document p='/tmp/workspace/pptx-to-word/output/Red_Cell_Distribution_Width_Heart_Failure_Study.docx' d=Document(p) print('paragraphs',len(d.paragraphs),'tables',len(d.tables),'sections',len(d.sections)) print('title:', d.paragraphs[0].text) print('last meaningful:', [x.text for x in d.paragraphs if x.text.strip()][-4:]) PY

Running Command

python - <<'PY' from pathlib import Path from pptx import Presentation from docx import Document from docx.shared import Pt, Inches, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml import OxmlElement from docx.oxml.ns import qn src=Path('/tmp/workspace/attachments/b514f745-44a7-48e8-afed-e770a2348404/TITLE_ A STUDY OF RED CELL DISTRIBUTION WIDTH AS A PROGNOSTIC MARKER IN PATIENTS WITH HEART FAILURE.pptx') out=Path('/tmp/workspace/pptx-to-word/output/Red_Cell_Distribution_Width_Heart_Failure_Study.docx') prs=Presentation(src) slides=list(prs.slides) doc=Document() sec=doc.sections[0] sec.top_margin=Inches(.7); sec.bottom_margin=Inches(.7); sec.left_margin=Inches(.8); sec.right_margin=Inches(.8) styles=doc.styles styles['Normal'].font.name='Arial'; styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'),'Arial'); styles['Normal'].font.size=Pt(10.5) styles['Title'].font.name='Arial'; styles['Title'].font.size=Pt(20); styles['Title'].font.bold=True; styles['Title'].font.color.rgb=RGBColor(31,78,121) for n,s,c in [('Heading 1',15,RGBColor(31,78,121)),('Heading 2',12,RGBColor(47,84,150))]: styles[n].font.name='Arial';styles[n].font.size=Pt(s);styles[n].font.bold=True;styles[n].font.color.rgb=c footer=sec.footer.paragraphs[0]; footer.alignment=WD_ALIGN_PARAGRAPH.CENTER r=footer.add_run('Study Protocol | ');r.font.name='Arial';r.font.size=Pt(8) fld=OxmlElement('w:fldSimple');fld.set(qn('w:instr'),'PAGE');footer._p.append(fld) def shade(cell,fill): tcp=cell._tc.get_or_add_tcPr();e=OxmlElement('w:shd');e.set(qn('w:fill'),fill);tcp.append(e) def add_text(p,txt): parts=[x.strip() for x in txt.replace('\x0b','\n').replace('\r','\n').split('\n') if x.strip()] for j,x in enumerate(parts): if j:p.add_run('\n') p.add_run(x) def headinglike(t): x=t.strip().replace('\n',' ') letters=''.join(a for a in x if a.isalpha()) return bool(letters) and len(x)<65 and (x.upper()==x or x.endswith(':')) def add_body(t): t=t.replace('\x0b','\n').replace('\r','\n').strip() if not t:return lines=[x.strip() for x in t.split('\n') if x.strip()] if len(lines)>1 and all(x.startswith(('●','•','-','–')) for x in lines): for x in lines:doc.add_paragraph(x.lstrip('●•-– ').strip(),style='List Bullet') else: p=doc.add_paragraph();add_text(p,t) # cover texts=[sh.text_frame.text.strip() for sh in slides[0].shapes if getattr(sh,'has_text_frame',False) and sh.text_frame.text.strip()] title=texts[0].replace('TITLE:','').strip() p=doc.add_paragraph(style='Title');p.alignment=WD_ALIGN_PARAGRAPH.CENTER;p.add_run(title) doc.add_paragraph() for x in texts[1:]: p=doc.add_paragraph();p.alignment=WD_ALIGN_PARAGRAPH.CENTER;add_text(p,x) doc.add_page_break() # subsequent slides for si,slide in enumerate(slides[1:],2): texts=[];tables=[] for sh in slide.shapes: if getattr(sh,'has_text_frame',False) and sh.text_frame.text.strip():texts.append(sh.text_frame.text.strip()) if getattr(sh,'has_table',False):tables.append(sh.table) head=None for i,t in enumerate(texts): if headinglike(t):head=t.replace('\n',' ').strip().rstrip(':');texts.pop(i);break doc.add_heading(head or f'Slide {si}',1) for t in texts:add_body(t) for table in tables: wt=doc.add_table(rows=len(table.rows),cols=len(table.columns));wt.style='Table Grid' for ri,row in enumerate(table.rows): for ci,cell in enumerate(row.cells): wt.cell(ri,ci).text=cell.text if ri==0:shade(wt.cell(ri,ci),'D9EAF7') p=doc.add_paragraph();r=p.add_run(f'Source: presentation slide {si}');r.italic=True;r.font.size=Pt(8);r.font.color.rgb=RGBColor(100,100,100) if si<len(slides):doc.add_page_break() doc.core_properties.title=title;doc.core_properties.author='Dr. Ayushi Agrawal';doc.core_properties.subject='Study protocol converted from presentation' doc.save(out) print(out, out.stat().st_size) PY python - <<'PY' from docx import Document from pathlib import Path p=Path('/tmp/workspace/pptx-to-word/output/Red_Cell_Distribution_Width_Heart_Failure_Study.docx') d=Document(p) print('exists=',p.exists(),'size=',p.stat().st_size,'paragraphs=',len(d.paragraphs),'tables=',len(d.tables)) print('title=',d.paragraphs[0].text) print('heading count=',sum(1 for x in d.paragraphs if x.style.name=='Heading 1')) PY

Converted the PowerPoint presentation into an editable Word document.

Red Cell Distribution Width Heart Failure Study

Word Document · DOCX

Dont use any colours use the same formatting and size and fonts as used and create a new word document

Reading File
Reading File
Reading File
Browsing Directory

~/

Running Command

python - <<'PY' from pptx import Presentation from pathlib import Path src=Path('/tmp/workspace/attachments/b514f745-44a7-48e8-afed-e770a2348404/TITLE_ A STUDY OF RED CELL DISTRIBUTION WIDTH AS A PROGNOSTIC MARKER IN PATIENTS WITH HEART FAILURE.pptx') prs=Presentation(src) for si,sl in enumerate(prs.slides,1): print('\nSLIDE',si) for sh in sl.shapes: if not getattr(sh,'has_text_frame',False) or not sh.text.strip(): continue print('shape',round(sh.left/914400,2),round(sh.top/914400,2),round(sh.width/914400,2), 'text=',repr(sh.text[:60])) for p in sh.text_frame.paragraphs: for r in p.runs: if r.text.strip(): print(' ',repr(r.text[:35]), 'font',r.font.name,'size',r.font.size.pt if r.font.size else None,'bold',r.font.bold,'italic',r.font.italic,'color',r.font.color.type if r.font.color else None) PY

Running Command

python - <<'PY' from pathlib import Path from pptx import Presentation from docx import Document from docx.shared import Pt, Inches from docx.enum.section import WD_ORIENT from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml import OxmlElement from docx.oxml.ns import qn src=Path('/tmp/workspace/attachments/b514f745-44a7-48e8-afed-e770a2348404/TITLE_ A STUDY OF RED CELL DISTRIBUTION WIDTH AS A PROGNOSTIC MARKER IN PATIENTS WITH HEART FAILURE.pptx') out=Path('/tmp/workspace/pptx-to-word/output/Red_Cell_Distribution_Width_Heart_Failure_Study_Plain_Original_Fonts.docx') prs=Presentation(src) slides=list(prs.slides) # Content slide dimensions are 10 x 7.5 in. Create one matched landscape Word page per slide. doc=Document() sec=doc.sections[0] sec.orientation=WD_ORIENT.LANDSCAPE sec.page_width=Inches(10) sec.page_height=Inches(7.5) sec.top_margin=Inches(0.12); sec.bottom_margin=Inches(0.12); sec.left_margin=Inches(0.12); sec.right_margin=Inches(0.12) sec.header_distance=Inches(0); sec.footer_distance=Inches(0) normal=doc.styles['Normal'] normal.font.name='Calibri'; normal._element.rPr.rFonts.set(qn('w:eastAsia'),'Calibri'); normal.font.size=Pt(22) normal.paragraph_format.space_after=Pt(0);normal.paragraph_format.space_before=Pt(0);normal.paragraph_format.line_spacing=1.0 # Use black-only formatting. Convert selected font traits and point sizes from each PowerPoint run. def set_run_font(wrun, prun, default_size=22): wrun.font.name = prun.font.name or 'Calibri' wrun._element.rPr.rFonts.set(qn('w:eastAsia'), prun.font.name or 'Calibri') wrun.font.size = Pt(prun.font.size.pt if prun.font.size else default_size) if prun.font.bold is not None: wrun.bold=prun.font.bold if prun.font.italic is not None: wrun.italic=prun.font.italic if prun.font.underline is not None: wrun.underline=prun.font.underline # Force black, per user request wrun.font.color.rgb=None def remove_paragraph_borders(paragraph): ppr=paragraph._p.get_or_add_pPr() pbdr=ppr.find(qn('w:pBdr')) if pbdr is not None:ppr.remove(pbdr) def add_shape_text(shape): # indentation approximates horizontal placement from source slide. Keep source font sizes. tf=shape.text_frame for pi,pp in enumerate(tf.paragraphs): # keep blank paragraphs only where source has a visible line gap if not pp.runs and not pp.text.strip(): p=doc.add_paragraph();p.paragraph_format.space_after=Pt(0);p.paragraph_format.line_spacing=1.0 continue p=doc.add_paragraph() p.paragraph_format.left_indent=Inches(max(0,shape.left/914400)) p.paragraph_format.first_line_indent=Inches(0) p.paragraph_format.space_after=Pt(0) p.paragraph_format.space_before=Pt(0) p.paragraph_format.line_spacing=1.0 p.alignment={0:WD_ALIGN_PARAGRAPH.LEFT,1:WD_ALIGN_PARAGRAPH.CENTER,2:WD_ALIGN_PARAGRAPH.RIGHT}.get(pp.alignment,WD_ALIGN_PARAGRAPH.LEFT) # A default 22 pt is used only where a PowerPoint run inherits its size from the master. default_size=22 for run in pp.runs: wr=p.add_run(run.text) set_run_font(wr,run,default_size) # paragraph ending retains potential text when run collection absent if not pp.runs and pp.text: wr=p.add_run(pp.text); wr.font.name='Calibri'; wr.font.size=Pt(default_size) remove_paragraph_borders(p) for idx, slide in enumerate(slides): # Shape ordering by position recreates source reading layout. Content in same y row is kept in a 2-column table when needed. text_shapes=[s for s in slide.shapes if getattr(s,'has_text_frame',False) and s.text_frame is not None] # group near-identical tops that are clearly distinct columns text_shapes.sort(key=lambda s:(round(s.top/914400,2),s.left)) processed=set() for a,shape in enumerate(text_shapes): if id(shape) in processed: continue peers=[s for s in text_shapes[a+1:] if id(s) not in processed and abs(s.top-shape.top)<91440 and s.left>shape.left+Inches(1)] if peers: # two-column source layout, such as clinical-history slides. other=peers[0] table=doc.add_table(rows=1,cols=2) table.autofit=False table.columns[0].width=Inches(4.75); table.columns[1].width=Inches(4.75) for col,s in enumerate((shape,other)): cell=table.cell(0,col); cell.text='' cell.width=Inches(4.75) # remove initial empty para then add all source paras in cell base=cell.paragraphs[0] for pi,pp in enumerate(s.text_frame.paragraphs): p=base if pi==0 else cell.add_paragraph() p.paragraph_format.space_after=Pt(0);p.paragraph_format.space_before=Pt(0);p.paragraph_format.line_spacing=1.0 for run in pp.runs: wr=p.add_run(run.text);set_run_font(wr,run,22) processed.add(id(other));processed.add(id(shape)) else: add_shape_text(shape);processed.add(id(shape)) if idx < len(slides)-1: doc.add_page_break() doc.core_properties.title='A STUDY OF RED CELL DISTRIBUTION WIDTH AS A PROGNOSTIC MARKER IN PATIENTS WITH HEART FAILURE' doc.core_properties.author='Dr. Ayushi Agrawal' doc.save(out) print(out, out.stat().st_size) PY python - <<'PY' from docx import Document from pathlib import Path p=Path('/tmp/workspace/pptx-to-word/output/Red_Cell_Distribution_Width_Heart_Failure_Study_Plain_Original_Fonts.docx') d=Document(p) # checks: no assigned non-black colors / all runs have source-like fonts runs=[r for p in d.paragraphs for r in p.runs] for t in d.tables: runs += [r for cell in t._cells for p in cell.paragraphs for r in p.runs] print('file exists:',p.exists(),'size:',p.stat().st_size,'paragraphs:',len(d.paragraphs),'tables:',len(d.tables),'runs:',len(runs)) print('fonts:',sorted(set(r.font.name for r in runs if r.font.name))) print('explicit color count:',sum(1 for r in runs if r.font.color.rgb is not None)) print('sizes:',sorted(set(round(r.font.size.pt,1) for r in runs if r.font.size))[:20]) PY

Created a new Word document with:
  • No colours
  • Original Calibri font retained
  • Original font sizes and bold/italic formatting retained
  • Landscape pages, arranged slide-by-slide for closer visual matching

Red Cell Distribution Width Heart Failure Study Plain Original Fonts

Word Document · DOCX

This is a shared conversation. Sign in to Orris to start your own chat.