Jump to content
Fórum Script Brasil
  • 0

Lendo arquivos .pdf e .doc no Linux‏


Renato Penna
 Share

Question

Bom dia povo! Estou tentando ler arquivos .doc e .pdf no Linux, mas não consigo. Estou tentando usar o comando $conteudo = shell_exec("catdoc $arq"); mas retorna vazio (como se o arquivo não tivesse nada escrito). Quando eu uso a forma padrão ($fp = fopen($arq,"r"); $conteudo = fread($fp,filesize($arq));) ele retorna um monte de lixo:

&(%[+bjbj.+Y[[[[[[$Z%%%Y%Y%%%J%E%%% %%:Teste para leitura de arquivo word com php*+hAhx+,1h. A!#$%f666666666vvvvvvvvv6666666666666666666666666666666666666666666666666666666hH6666666666666666666666666666666666666666666666666666666666666666662 @Pp2( @Pp @Pp @Pp @Pp @Pp @Pp8XVOJQJ_HmHnHsHtHJJNormaldCJ_HaJmHsHtHA Fonte parg. padroTiTTabela normal4l4a,k ,Sem listaPK![Content_Types].xmljEr(Iw},-j4wP-t#b{UTUhd})*1PW)T9l#$yi};@(Hu*Dz/$X3aZ,Dj3bi3?/[G!-Rk.s..a?PK!6_rels/.relsj}Q%v/C/}(hO= C?hv=%[xp{_P1HORBdJE4b$q_6LR7O,En7Lib/SePK!kytheme/theme/themeManager.xmlM @}w7c(EbCA7KY,e.,H,lxIsQ}# +!,$j=GW)E+&8PK!.atheme/theme/theme1.xmlYMoE#F{omvGuhF[xw;jf7q7J(/z4IA!35.=D4;IOH]YxME$&TVIS1V(Z Ym_&[email protected]&[email protected]$K_PA!&g=!nmreDLC[OF{KFY7qoku)lVgd.[/_v[LXrd8xR{(b4[@2lz &QLb(fXYJ&x,(R7vKZ Ia:?xpxGIXzg=2PCsu=o.G4& h9QLI(q}938ztzHSE+$_b9rQkZViV2n*=8OSyZ:ppH_/P%#:viNEcfYdEBUVWTXEUJg/RAC8D*-Um6]Ptuyz*&Qh*6w+D?CprloSnpJoBc3chTYok#=pGn=wOikZoiBszLPjui&eEEMl8;64HpU)LO3e:(xf)HyrB(-4gfpZa2khN-aT3V4ov/][email protected]@THNZIZ[}iRYqy$JyH9,AZjyi)D]n%lXlE6ljWYDK/eby_L&WVcJT14fS!:UJA?y6Xg1K#[]y%[bTRlwvSL)4.XtzxCJ#[email protected],e_}aN}jHPT$dfl,YdTI]Zd+zoPnIhYC=!kkl1Qn6MB]-_f MR+Wh1,QH*:[[email protected]_.ap64+lt7stG5;Mb8s9xjI11qM2%M2K94uo%PK!theme/theme/_rels/themeManager.xml.relsMwoo&56?$Q,.aic21h:[email protected];do7gK(M&$R(.1rJT8VAHu}$b{P8g/]QAs(#L[PK-![Content_Types].xmlPK-!6+_rels/.relsPK-!kytheme/theme/themeManager.xmlPK-!.atheme/theme/theme1.xmlPK-!theme/theme/_rels/themeManager.xml.relsPK]?xml version=1. encoding=UTF-8 standalone=yes?a:clrMap xmlns:a=http://schemas.openxmlformats.org/drawingml/26/main bg1=lt1 tx1=dk1 bg2=lt2 tx2=dk2 accent1=accent1 accent2=accent2 accent3=accent3 accent4=accent4 accent5=accent5 accent6=accent6 hlink=hlink folHlink=folHlink/[email protected](BS?*-*-*[email protected]** **[email protected]* Times New Roman5Symbol3.* Arial7.{ @CalibriACambria Mathqzz%%!r**2HP$Px2!xxrenato.pennarenato.pennaOh+8DPdltrenato.pennaNormal.dotmrenato.penna2Microsoft Office [email protected]#@[email protected]%.+,hpediouro*Ttulo !#$Root EntryFpJ)1TableWordDocumentSummaryInformation(DocumentSummaryInformation8CompObj}F+Documento do Microsoft Office Word 97-23MSWordDocWord.Document.89q

Alguém sabe como ler arquivos .doc e .pdf no Linux com PHP corretamente ?

Desde já agradeço,

Renato.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Achei a solução, obrigado!

$pos = strpos($documento,'.');
$tam = strlen($documento);
$qtd_caracteres_extensao = $tam-$pos;
$extensao_arquivo = substr($documento,($pos+1),$qtd_caracteres_extensao);
        
if($extensao_arquivo=="doc")
{
    $conteudo = shell_exec("catdoc $arq");
}
elseif($extensao_arquivo=="pdf")
{
    $conteudo = shell_exec('pdftotext $arq -');
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.9k
    • Total Posts
      648.8k
×
×
  • Create New...