Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 43

Thread: How to read xml file using PHP

  1. #11
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You can convert directly from pptx to pdf for free on the web, or just use Open Office or Office to do it yourself:

    https://www.google.com/search?q=convert+pptx+to+pdf

    That said, we can probably save the information we have just extracted to a pdf, that still leaves the issue of how that should be formatted. You don't have to release any private info. Just take an example file, use it's output from the code we have so far, and change that into something pretend. Then show how you would like that displayed.

    Or, if you're happy with how it looks and just want it as a pdf, we can just dump it into a pdf.
    Last edited by jscheuer1; 06-05-2016 at 01:57 PM. Reason: add last line
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  2. #12
    Join Date
    Jun 2016
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    sure i tried with some example file and the information have been displayed like a mess
    unfortunately i cant use a web service for that i have to do it progamaticaly with xml and php
    i also think that may be its not possible at all because they are info that would be missed as images
    because when unzipped there are in many others files

  3. #13
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well OK, there usually are images in pptx files, but unless they are required, you don't need them. If they are required, they can be found in the archive and put into a .pdf file. The tricky part would be in determining where in the pdf file they should go. That information is probably available (hopefully in the slides, but might be elsewhere in the pptx archive), how else would the pptx file know where to put the images?

    Anyways, I have worked something out for a text only pdf from the slides of a pptx file using the fpdf library:

    PHP Code:
    <?php 
    error_reporting
    (E_ALL); 
    ini_set('display_errors'1); 

    // open file 
    $file_path 'Reports/report.pptx'
    //$target_folder_path = 'Reports'; 

    $zip = new ZipArchive
    $res $zip->open($file_path); 

    if (
    $res === TRUE) { 
        
    //    $zip->extractTo($target_folder_path); 
        
    require('../../../fpdf181/fpdf.php'); //path to fpdf.php on your server
        
        
    $pdf = new FPDF();
        
    $pdf->AddPage();
        
    $pdf->SetFont('Arial','B',10);
        
    $headings = Array();
        
    // loop through all slide#.xml files 
        
    $slide 1

        while ( (
    $index $zip -> locateName("ppt/slides/slide" $slide ".xml")) !== false ){ 
        
    $pdf->Cell(40,7,"Report #$slide:",0,1);
        
    $data $zip -> getFromIndex($index); 

        
    $p xml_parser_create();
        
    xml_parse_into_struct($p$data$vals);
        
    xml_parser_free($p);
        
    $str '';
        foreach(
    $vals as $val){
            if(isset(
    $val['value'])){
                
    $str .= chop($val['value']) . " ";
            }
        }
        if(
    strlen($str)){
            
    $parts explode(" "$str);
            
    $tmpstr "";
            foreach(
    $parts as $part){
                
    $apart chop($part)? chop($part) . " " "";
                
    $tmpstr .= $apart;
                if(
    strlen($tmpstr) < 113){
                    
    $pstr $tmpstr;
                } else {
                    
    $pdf->Cell(0,4,$pstr,0,1);
                    
    $tmpstr $apart;
                }
            }
            if(
    strlen($tmpstr)){
                
    $pdf->Cell(0,4,$tmpstr,0,1);
            }
            
    $pdf->Cell(0,3,'',0,1);
        }
            
    $slide++; 
        } 
        
    $zip->close(); 
    $pdf->Output();
         
    }   else { 
            echo 
    'failed'
        } 

    ?>
    Use fpdf from: http://www.fpdf.org/en/download.php (version 1.81)
    Last edited by jscheuer1; 06-05-2016 at 09:37 PM. Reason: add link
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #14
    Join Date
    Jun 2016
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Beverleyh,
    thank you for the links i think they will help me though.

  5. #15
    Join Date
    Jun 2016
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    Thanks for your reply ... it works fine except the fact that each slide has been output
    the images are located in Reports/ppt/media but as you said
    "how else would the pptx file know where to put the images?" that is the question ...
    and its a little complicated as far slides have different structure
    i remembered that this document is for public displays so i can share it with you so you
    see how it looks like
    for the first 3 slides we have this kind of "header" but the "footer" seems to be the same

  6. #16
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This (pptx) is all fairly new to me. I've heard of it before, had a general idea what it was, but never actually worked with it or anything related to it before. In fact, I'd never even looked at power point presentation before. XML, PHP, and PDF, on the other hand, those I know a fair amount about, and am therefore able to learn new details on those fairly easily.

    I've been looking at some more xml slide files. I don't see where the images are specified. I may have missed something though, or maybe that information is stored somewhere else in the pptx file. It has to be there. It's like a black hole (or at least no more complicated than one). Information must be conserved (Hawking).

    So you say these files can be shared after all? I would probably only need one fairly typical one to enhance my chances of finding an optimal solution for your particular situation. That's because, so far - I've discovered that each pptx can make specific uses of images, not each pptx file uses images in the same ways. If we can discover a pattern for how your particular pptx files use images, that might be useful.

    That said, as I look more at the structure of pptx in general, I'm likely to discover a generic solution. I'm also thinking - someone must have already done this. Or at least mapped where each significant bit of information is stored in these files. By the end of the week I'll probably have more on that front.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #17
    Join Date
    Jun 2016
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,
    It's much appreciated the way you take your time and energy to answer.
    When unzipping the files don't you have any "media" folder!?
    OK I'll also continue working on it. Thank you
    Best Regards
    Charles
    Last edited by mignoncharly; 06-07-2016 at 06:15 AM.

  8. #18
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes, I know - have seen the media folder (as far as I can tell at the moment - only contains images - no info on how said images are to be deployed, especially visa vis the positioning of text upon them, which I also have found can be erratic at times even internally to a pptx file - but, if one and only one image per slide, that's helpful/easy to deal with to an extent). I will be looking into that and any other clues as to how best to go about this. But, since you seem to be willing to link to or attach one of your files, that would probably also be helpful. These files can have subtle differences like encoding, and general organizational approaches. Being able to see a typical one of the sort you are dealing with would probably be a good thing - that is, if I understood correctly and it is OK for you to share one publicly.

    If not, I can probably arrange for a way for you to get one of your pptx files to me privately.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #19
    Join Date
    Jun 2016
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    OK
    how can I attach the file here ... I can't share it via dropbox on this machine(technically problem may be) ... may be the private way will be the best one

    Charles

  10. #20
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'll PM you my email address. You can attach the file there. Or to a PM response, your choice.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. read xml file
    By lay in forum PHP
    Replies: 4
    Last Post: 03-12-2009, 12:13 PM
  2. how to read pdf file using php?
    By khoulong in forum PHP
    Replies: 1
    Last Post: 03-12-2009, 03:33 AM
  3. read pdf file
    By lay in forum PHP
    Replies: 3
    Last Post: 03-12-2009, 02:39 AM
  4. how to read xml file from safari?
    By onoprise in forum JavaScript
    Replies: 1
    Last Post: 12-16-2008, 10:55 PM
  5. asp read file
    By midhul in forum ASP
    Replies: 1
    Last Post: 02-23-2008, 06:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •