Git Product home page Git Product logo

Comments (15)

mlocati avatar mlocati commented on June 7, 2024 2

Well, a library exists: this one 😉

from chm-lib.

mlocati avatar mlocati commented on June 7, 2024

@Deyrajesh could you provide the affected CHM? If it's a problem to share it publicly, you can send me an email (I obviously won't share it).

from chm-lib.

mlocati avatar mlocati commented on June 7, 2024

You can see my email address on GitHub: for instance here

from chm-lib.

Deyrajesh avatar Deyrajesh commented on June 7, 2024

Sir I have mailed you on that id. Please acknowledge me so I delete this links from here

from chm-lib.

mlocati avatar mlocati commented on June 7, 2024

File downloaded, thanks!

from chm-lib.

mlocati avatar mlocati commented on June 7, 2024

I wrote this code:

<?php

use CHMLib\CHM;
use CHMLib\Entry;

require_once 'CHMLib.php';

$outputFolder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'out';
if (!is_dir($outputFolder)) {
    mkdir($outputFolder);
}
$chm = CHM::fromFile('filename.chm');
foreach ($chm->getEntries(Entry::TYPE_FILE) as $entry) {
    echo "Processing {$entry->getPath()}... ";
    $entryPath = ltrim(str_replace('/', DIRECTORY_SEPARATOR, $entry->getPath()), DIRECTORY_SEPARATOR);
    $parts = explode(DIRECTORY_SEPARATOR, $entryPath);
    $subfolder = count($parts) > 1 ? implode(DIRECTORY_SEPARATOR, array_splice($parts, 0, -1)) : '';
    $filename = array_pop($parts);
    $path = $outputFolder;
    if ($subfolder !== '') {
        $path .= DIRECTORY_SEPARATOR . $subfolder;
        if (!is_dir($path)) {
            mkdir($path, 0777, true);
        }
    }
    $path .= DIRECTORY_SEPARATOR . $filename;
    file_put_contents($path, $entry->getContents());
    echo "done.\n";
}

and everything seems to work fine. What's your exact problem?

from chm-lib.

Deyrajesh avatar Deyrajesh commented on June 7, 2024

I am sending my problem / screen shot on your email id sir.

from chm-lib.

Deyrajesh avatar Deyrajesh commented on June 7, 2024

Sir your code worked . :) thank you so much. I forgot to use that "CHMLib\Entry" file. Now its working perfectly. Thank you so much sir. I have not find anything on web regarding this. But Your library that working parfectly. Thank you again sir.

from chm-lib.

mlocati avatar mlocati commented on June 7, 2024

No problems! I added the sample code to the README.md file: it may be handy for others too.

from chm-lib.

Deyrajesh avatar Deyrajesh commented on June 7, 2024

Thank you. It will be very helpful to others also. Because there is no such lib on internet for this conversion.

from chm-lib.

Deyrajesh avatar Deyrajesh commented on June 7, 2024

from chm-lib.

Deyrajesh avatar Deyrajesh commented on June 7, 2024

echo str_repeat("\t", $level).print_r($child->getName(), 1)."\n"; prints the Content names, but when I use print_r($level) or print_r($child->getName()), both of them prints some xml sting. I am confused how it is printing. Please help me to understand this one. Thank you sir.

from chm-lib.

mlocati avatar mlocati commented on June 7, 2024

It should be quite easy: when you extract the files, you store the $entry->getPath() in a dictionary.

Then, when you read the toc, you can determine the item you saved before by using $child->getLocal():

Using the examples in the README.md, you could have something like this:

$dictionary = array();

// Extract the contents of the CHM file
// [omissis]
foreach ($chm->getEntries(Entry::TYPE_FILE) as $entry) {
    // [omissis]
    $path .= DIRECTORY_SEPARATOR . $filename;
    file_put_contents($path, $entry->getContents());
    $dictionary[$entry->$entry->getPath()] = $path;
}

// Read the TOC
function printTree($tree, $level)
{
    global $dictionary;
    if ($tree !== null) {
        foreach ($tree->getItems() as $child) {
            // [omissis]
            $filePath = isset($dictionary[$child->getLocal()])
                ? $dictionary[$child->getLocal()]
                : null; 
            // [omissis]
            printTree($child->getChildren(), $level + 1);
        }
    }
}
// [omissis]

from chm-lib.

Deyrajesh avatar Deyrajesh commented on June 7, 2024

sir I am facing "Object of class CHMLib\Entry could not be converted to string" this fetal error while converting. I think $dictionary[$entry->$entry->getPath()] = $path; there will be 1 $entry instead of 2..

from chm-lib.

mlocati avatar mlocati commented on June 7, 2024

Solved via email.

from chm-lib.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.