Skip to content

Instantly share code, notes, and snippets.

@pigreco
Created September 13, 2023 16:57
Show Gist options
  • Save pigreco/272e58381ac896a86acbd4ccc1bc7fce to your computer and use it in GitHub Desktop.
Save pigreco/272e58381ac896a86acbd4ccc1bc7fce to your computer and use it in GitHub Desktop.
Funzione personalizzate per field clac by Giulio
# Korto19 2023
from qgis.core import *
from qgis.gui import *
from PyPDF2 import PdfReader
@qgsfunction(group='HfcQGIS',referenced_columns=[])
def Get_Pdf_N_Pages(pdfpath):
"""
Restituisce il numero di pagine di un pdf dando il percorso
<h2>Example usage:</h2>
<ul>
<li>Get_Pdf_N_Pages(pdfpath)-> 3</li>
</ul>
"""
reader = PdfReader(str(pdfpath))
number_of_pages = len(reader.pages)
return number_of_pages
@pigreco
Copy link
Author

pigreco commented Sep 13, 2023

Questa funziona

# Korto19 2023
from qgis.core import *
from qgis.gui import *
from PyPDF2 import PdfReader

@qgsfunction(group='HfcQGIS',referenced_columns=[])
def Get_Pdf_N_Pages(pdfpath, *args, **kwargs):
    """
    Restituisce il numero di pagine di un pdf dando il percorso
    <h2>Example usage:</h2>
    <ul>
      <li>Get_Pdf_N_Pages(pdfpath)-> 3</li>
    </ul>
    """

    reader = PdfReader(str(pdfpath))
    number_of_pages = len(reader.pages)

    return number_of_pages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment