Как включать страницу в PDF в документе в формате PDF в Python

Хотелось бы что-нибудь подобное?

export let findMode = (b: number[]): number => {
    // we'll store the values in b and the number of times they occur here
    const counts: Array<{ value: number, count: number }> = [];

    // it helps to check that b is defined before you check length, this avoids ReferenceErrors
    if (!b || !b.length) {
        return 0;
    }

    for (let i = 0; i < b.length; i++) {
        const val = b[i];
        const count = counts.find(count => count.value === val);

        if (count) {
            count.count++;
        } else {
            counts.push({ value: val, count: 1 });
        }
    }

    // get the mode by sorting counts descending and grabbing the most occuring
    const mode = counts.sort((c1, c2) => c2.count - c1.count)[0];

    // and now if you *need* an intermediate array with the index mapped to the value and value mapped to the count:
    const largestNumber = counts.sort((c1, c2) => c2.value - c1.value)[0];
    // initialize an empty as long as the largest number
    let newArr = new Array(largestNumber);
    newArr = newArr.map((val, i) => {
        const count = counts.find(count => count.value === i);
        if (count) {
            return count.count;
        } else {
            return 0; // 'i' occurs 0 times in 'b'
        }
    });
};
5
задан Jiri 23 March 2009 в 13:03
поделиться

2 ответа

Я в настоящее время использую PyPDF, чтобы считать, записать и объединить существующий PDF и ReportLab для генерации нового содержания. Используя два пакета, казалось, работал лучше, чем какой-либо единственный пакет, который я смог найти.

6
ответ дан 14 December 2019 в 01:17
поделиться

Существует дополнение для ReportLab — PageCatcher.

1
ответ дан 14 December 2019 в 01:17
поделиться
Другие вопросы по тегам:

Похожие вопросы: