Avatar billede kodak Mester
23. marts 2023 - 21:54 Der er 6 kommentarer

list fdf resultater

Jeg vil gerne lave en upload funkrion det læser filen igennem for alle verdier som:

%FDF-1.2
%
1 0 obj
<</FDF<</Annots[2 0 R 3 0 R 4 0 R 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 12 0 R 13 0 R 14 0 R 15 0 R 16 0 R 17 0 R 18 0 R 19 0 R 20 0 R 21 0 R 22 0 R 23 0 R 24 0 R 25 0 R 26 0 R 27 0 R 28 0 R 29 0 R 30 0 R 31 0 R 32 0 R 33 0 R 34 0 R 35 0 R 36 0 R 37 0 R 38 0 R 39 0 R 40 0 R 41 0 R 42 0 R 43 0 R 44 0 R 45 0 R 46 0 R 47 0 R 48 0 R 49 0 R 50 0 R 51 0 R 52 0 R 53 0 R 54 0 R 55 0 R 56 0 R 57 0 R 58 0 R 59 0 R 60 0 R 61 0 R 62 0 R 63 0 R 64 0 R 65 0 R 66 0 R 67 0 R 68 0 R 69 0 R 70 0 R 71 0 R 72 0 R 73 0 R 74 0 R 75 0 R 76 0 R 77 0 R 78 0 R 79 0 R 80 0 R 81 0 R 82 0 R 83 0 R 84 0 R 85 0 R 86 0 R 87 0 R 88 0 R 89 0 R 90 0 R 91 0 R 92 0 R 93 0 R 94 0 R 95 0 R]/F(/C/Users/henand05/Documents/SDU/Gravering/Tegninger/45.1/K07.1_L45.1F_H1.01_EN00_N112.pdf)/ID[<68B5F84E0D501A4EB84CF40727B1899A><47FC3F6F53047240A665C0638D1D3C19>]/UF(/C/Users/henand05/Documents/SDU/Gravering/Tegninger/45.1/K07.1_L45.1F_H1.01_EN00_N112.pdf)>>/Type/Catalog>>
endobj
2 0 obj
<</C[1.0 0.819611 0.0]/Contents(Print:Tavle:ET.45.1A.0W.02\r23-23-15 EDB-15 EDB-PDS\r<824>-[236])/CreationDate(D:20230323081009+01'00')/F 28/M(D:20230323115101+01'00')/NM(e5ab9eab-9c0a-4abe-9fa3-bfec97960cd3)/Name/Circle/Page 0/Popup 3 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:22.3.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.1pt;text-align:left;font-weight:normal;f\
ont-style:normal">ET.45.1A.0W.02&lt;824&gt;</span></p></body>)/Rect[549.719 1258.6 569.719 1278.6]/Subj(Gul seddel)/Subtype/Text/T(hjia)/Type/Annot>>
endobj
3 0 obj
<</F 28/Open false/Page 0/Parent 2 0 R/Rect[2976.0 1164.6 3180.0 1278.6]/Subtype/Popup/Type/Annot>>
endobj
4 0 obj
<</C[1.0 0.819611 0.0]/Contents(Print:ET.45.1A.0W.02<824>\rPrint:ET.45.1A.00.04[264])/CreationDate(D:20230323081014+01'00')/F 28/M(D:20230323115053+01'00')/NM(0cf1b242-7fb7-4299-be39-6cb10979ccf8)/Name/Circle/Page 0/Popup 5 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:22.3.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.1pt;text-align:left;font-weight:normal;f\
ont-style:normal">ET.45.1A.0W.02&lt;824&gt;&#13;ET.45.1A.00.04[264]</span></p></body>)/Rect[475.002 1277.79 495.002 1297.79]/Subj(Gul seddel)/Subtype/Text/T(hjia)/Type/Annot>>
endobj
5 0 obj
<</F 28/Open false/Page 0/Parent 4 0 R/Rect[2976.0 1192.19 3180.0 1306.19]/Subtype/Popup/Type/Annot>>
endobj
6 0 obj
<</C[1.0 0.819611 0.0]/Contents(Print:ET.45.1A.0W.02<822>\rPrint:ET.45.1A.00.04[264])/CreationDate(D:20230323081041+01'00')/F 28/M(D:20230323115032+01'00')/NM(16b4346c-09a5-4929-bd59-d06a9c4c5c1c)/Name/Circle/Page 0/Popup 7 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:22.3.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.3pt;text-align:left;font-weight:normal;f\
ont-style:normal">ET.45.1A.0W.02&lt;822&gt;&#13;ET.45.1A.00.04[264]</span></p></body>)/Rect[483.499 1382.37 503.499 1402.37]/Subj(Gul seddel)/Subtype/Text/T(hjia)/Type/Annot>>
endobj
7 0 obj
<</F 28/Open false/Page 0/Parent 6 0 R/Rect[2976.0 1288.37 3180.0 1402.37]/Subtype/Popup/Type/Annot>>
endobj
8 0 obj
<</C[1.0 0.819611 0.0]/Contents(263)/CreationDate(D:20230323125609+01'00')/F 28/M(D:20230323125617+01'00')/NM(048486ab-8cd2-48a3-a83c-64eb9ea7785c)/Name/Circle/Page 0/Popup 9 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:22.3.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.3pt;text-align:left;font-weight:normal;f\
ont-style:normal">263</span></p></body>)/Rect[682.324 1610.65 702.324 1630.65]/Subj(Gul seddel)/Subtype/Text/T(hjia)/Type/Annot>>
endobj
9 0 obj
<</F 28/Open true/Page 0/Parent 8 0 R/Rect[2976.0 1516.65 3180.0 1630.65]/Subtype/Popup/Type/Annot>>
endobj
10 0 obj
<</C[1.0 0.819611 0.0]/Contents(263)/CreationDate(D:20230323125617+01'00')/F 28/M(D:20230323125707+01'00')/NM(4665585c-d5e0-4285-bb47-5e33bb14426e)/Name/Circle/Page 0/Popup 11 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:22.3.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.3pt;text-align:left;font-weight:normal;f\
ont-style:normal">263</span></p></body>)/Rect[717.36 1609.25 737.36 1629.25]/Subj(Gul seddel)/Subtype/Text/T(hjia)/Type/Annot>>
endobj


hvor der gerne skal udlæses verdier fra:
/Contents()
/CreationDate()
hvad der står efter '/Name/'
/T()

og af det skal den kun gøre hvis '/Contents()' starter med 'Print:'
og så skal den dele verdien op i stumper:
Hvis vedien efter 'Print:' er 'Tavle:'
$output['tavle'] = (alt mellem 'Tavle:' og '\r')
$output['date'] = (verdi af /CreationDate())
$output['type'] = (verdi af /T())
$output['creator'] = (verdi af hvad der står efter '/Name/')
$output['field_1'] = (første del af den næste del før '-')
$output['field_2'] = (næste del af den næste del anden før '-')
$output['field_3'] = (næste del af den næste del tredie før '-')
$output['field_4'] = -||-
$output['field_5'] = -||-

dette skal den liste op i en tabel

men står der ikke 'Tavle:'
skal den lave en anden liste med verdierne


Troede jeg var på rette vej, men får tilbagefald.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_FILES["file"])) {
        $file_name = $_FILES["file"]["name"];
        $file_type = $_FILES["file"]["type"];
        $file_size = $_FILES["file"]["size"];
        $file_tmp = $_FILES["file"]["tmp_name"];

        // Check if the file is an FDF file
        if (strtolower(pathinfo($file_name, PATHINFO_EXTENSION)) == "fdf") {
            // Read the contents of the file and replace all \r with \n
            $file_contents = file_get_contents($file_tmp);
            $file_contents = str_replace("\r", "\n", $file_contents);

            // Extract the data
            preg_match_all('/Contents\((.*?)\)/', $file_contents, $matches);
            $output = array(
                "list" => array(),
                "tavle" => "",
                "field_1" => array(),
                "field_2" => array(),
                "field_3" => array(),
                "field_4" => array(),
                "field_5" => array()
            );
            foreach ($matches[1] as $match) {
                if (strpos($match, "Print:") === 0) {
                    // Add value to list
                    $output["list"][] = trim(substr($match, 6));
                } elseif (strpos($match, "Tavle:") === 0) {
                    // Set table value
                    $output["tavle"] = trim(substr($match, 6));
                } else {
                    // Set field values
                    $field_values = explode("-", $match);
                    $output["field_1"][] = trim($field_values[0]);
                    $output["field_2"][] = trim($field_values[1]);
                    $output["field_3"][] = trim($field_values[2]);
                    $output["field_4"][] = trim($field_values[3]);
                    $output["field_5"][] = trim($field_values[4]);
                }
            }

            // Display the data in a Bootstrap table
            echo "<div class='container'><h2>File Contents</h2>";
            echo "<table class='table'>";
            if (!empty($output["list"])) {
                echo "<tr>
                        <th>Print List:</th>
                        <td>";
                echo "<ul>";
                foreach ($output["list"] as $list_item) {
                    echo "<li>" . $list_item . "</li>";
                }
                echo "</ul>";
                echo "</td></tr>";
            }
            if (!empty($output["tavle"])) {
                echo "<tr>";
                echo "<th>Tavle:</th>";
                echo "<td>" . $output["tavle"] . "</td>";
                echo "</tr>";
            }
            if (!empty($output["field_1"])) {
                echo "<tr>";
                echo "<th>Field 1:</th>";
                echo "<td><ul>";
                foreach ($output["field_1"] as $field) {
                    echo "<li>" . $field . "</li>";
                }
                echo "</ul></td>";
                echo "</tr>";
            }
            if (!empty($output["field_2"])) {
                echo "<tr>";
                echo "<th>Field 2:</th>";
                echo "<td><ul>";
                foreach ($output["field_2"] as $field) {
                    echo "<li>" . $field . "</li>";
                }
                echo "</ul></td>";
                echo "</tr>";
            }
            if (!empty($output["field_3"])) {
                echo "<tr>";
                echo "<th>Field 3:</th>";
                echo "<td><ul>";
                foreach ($output["field_3"] as $field) {
                    echo "<li>" . $field . "</li>";
                }
                echo "</ul></td>";
                echo "</tr>";
            }
            if (!empty($output["field_4"])) {
                echo "<tr>";
                echo "<th>Field 4:</th>";
                echo "<td><ul>";
                foreach ($output["field_4"] as $field) {
                    echo "<li>" . $field . "</li>";
                }
                echo "</ul></td>";
                echo "</tr>";
            }
            if (!empty($output["field_5"])) {
                echo "<tr>";
                echo "<th>Field 5:</th>";
                echo "<td><ul>";
                foreach ($output["field_5"] as $field) {
                    echo "<li>" . $field . "</li>";
                }
                echo "</ul></td>";
                echo "</tr>";
            }
            echo "</table></div>";
        } else {
            echo "<div class='container'><div class='alert alert-danger'>Invalid file format. Please upload an FDF file.</div></div>";
        }
    } else {
        echo "<div class='container'><div class='alert alert-danger'>Please select a file to upload.</div></div>";
    }
}
?>
</body>
</html>
Avatar billede kodak Mester
23. marts 2023 - 22:49 #1
Har fået trukket dataen ud, nu skal jeg ha den til at dele den op i stumper:


    <?php
        if(isset($_FILES['fdfFile'])) {
            $fdfFile = $_FILES['fdfFile']['tmp_name'];

            $fdfContents = file_get_contents($fdfFile);

            preg_match_all("/Contents\((Print:.+?)\)/s", $fdfContents, $matches);
            preg_match_all("/\/CreationDate\s*\((.+?)\)/", $fdfContents, $creationDates);
            preg_match_all("/\/Name\s*\/(.+?)\//", $fdfContents, $names);
            preg_match_all("/\/T\s*\((.+?)\)/", $fdfContents, $titles);

            $data = array();
            for($i = 0; $i < count($matches[1]); $i++) {
                if(strpos($matches[1][$i], "Print:") === 0) {
                    $data[] = array(
                        "print" => $matches[1][$i],
                        "creation_date" => isset($creationDates[1][$i]) ? $creationDates[1][$i] : "",
                        "name" => isset($names[1][$i]) ? $names[1][$i] : "",
                        "title" => isset($titles[1][$i]) ? $titles[1][$i] : ""
                    );
                }
            }

            if(!empty($data)) {
                echo "<table class='table'>";
                echo "<thead><tr><th>Print</th><th>Dato</th><th>Type</th><th>Opretter</th></tr></thead>";
                echo "<tbody>";
                foreach($data as $row) {
                    echo "<tr>";
                    echo "<td>" . $row['print'] . "</td>";
                   
                    $datePart = substr($row['creation_date'], 2, 8);
                    $timePart = substr($row['creation_date'], 10, 6);
                   
                    $datetime = DateTime::createFromFormat('YmdHisO', $datePart . $timePart . '+0100');
                    $formatted = $datetime->format('Y-m-d H:i:s');
                                       
                    echo "<td>" . $formatted . "</td>";
                    echo "<td>" . $row['name'] . "</td>";
                    echo "<td>" . $row['title'] . "</td>";
                    echo "</tr>";
                }
                echo "</tbody></table>";
            } else {
                echo "<div class='alert alert-danger'>Ingen Data Fundet</div>";
            }
        }
?>
Avatar billede acore Ekspert
24. marts 2023 - 11:00 #2
Hej kodak,

Er du opmærksom på, at der er et bibliotek til at læse fdf filer i php - se https://www.php.net/manual/en/book.fdf.php. Ikke at jeg har prøvet det, men tænkte at det måske kan gøre arbejdet lettere og mere generisk?
Avatar billede kodak Mester
24. marts 2023 - 17:38 #3
Det er jeg klar over men det med at installere det er for bøvlet da jeg arbejder fra en NAS. og det kun er en så lille del af min side der skal bruge det.
Avatar billede ejvindh Ekspert
24. marts 2023 - 19:48 #4
Ja, fdf-biblioteket døde desværre omkring php5.3. I en tråd om et lignende problem, finder du et forslag til, hvordan man kan gøre, efter at fdf-biblioteket er taget ud af standard php:
https://stackoverflow.com/a/14442585

Jeg indrømmer lige, at jeg har ikke kigget i detaljen, så jeg kan love, hvor godt det virker. Men jeg gætter på, at du ret hurtigt selv vil kunne afgøre, om det hjælper dig på vej.
Avatar billede kodak Mester
24. marts 2023 - 20:13 #5
Udlæsnings delen har jeg fået styr på.

Jeg mangler kun ar få den til at forstå de forskellige metoder jeg har skrevet det pp.

at hvis der står: Tavle:
skal den gøre på én måde.
står der ikke tavle skal den gøre på nogle andre måder.
Avatar billede kodak Mester
26. marts 2023 - 22:34 #6
er ved at være der men den driller mig
$inputString = 'T:ET.45.1A.00.04\r401-401-401\rp\r511 EDB-511 EDB-511 EDB'

if (preg_match('/^T:(.*?)\\-(.*?)\\-(.*?)\\-(.*?)\\-(.*?)$/', $inputString, $matches)) {

prøver at dele den op i:
$matches[0]: 'ET.45.1A.00.04'
$matches[1]: '401'
$matches[2]: '401'
$matches[3]: '401'
$matches[4]: '' (pga. p)
$matches[5]: '' (pga. ikke angivet)
$matches[6]: '' (pga. ikke angivet)

ny linje:
$matches[0]: 'ET.45.1A.00.04'
$matches[1]: '511 EDB'
$matches[2]: '511 EDB'
$matches[3]: '511 EDB'
$matches[4]: '' (pga. ikke angivet)
$matches[5]: '' (pga. ikke angivet)
$matches[6]: '' (pga. ikke angivet)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester