Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #2  
Antiguo 17-06-2021
bucanero bucanero is offline
Miembro
 
Registrado: nov 2013
Ubicación: Almería, España
Posts: 208
Poder: 11
bucanero Va camino a la fama
Si la aplicación es bajo windows puedes utilizar la dll PDFText, que puedes encontrar en este enlace: https://pdf-analyzer.com/mdownloads.html, yo la utilizo para extraer información de los PDF y funciona bien.

Aquí dejo el código de uso de esta DLL

Código Delphi [-]
type
  TPDFText = class
  public
    function GetPDFNumPages(const FileName:string):LongInt; overload;
    function GetPDFContent(fileName: string): string;
    function GetPDFErrorMsg(const CodeError: Integer): string;
  end;


implementation

uses System.SysUtils;

    function GetPDFPageCount(const FileName:PWideChar):LongInt; stdcall; external 'PDFtext.dll';
    function GetPDFText(const FileName: PWideChar;
      opt: LongInt=3;
      hw: LongInt=0;
      fast: LongInt=0;
      target: PWideChar=0;
      lspaces: LongInt=1;
      ptitel: PWideChar=0;
      pos:  LongInt=0;
      page: LongInt=0;
      clock: LongInt=0;
      blank: LongInt=0;
      ende: LongInt=0;
      wlist: LongInt=0): pWidechar; stdcall; external 'PDFtext.dll';



{ TPDFText }

function TPDFText.GetPDFErrorMsg(const CodeError: Integer): string;
begin
  case CodeError of
    0:
      result := 'General main error';
    9001:
      result := 'File not found';
    9002:
      result := 'No PDF file';
    9003:
      result := 'There´s a user password';
    9004:
      result := 'Invalid/damaged page structure';
    9005:
      result := 'Target drive/path is not valid';
    9006:
      result := 'Target drive/path is missing';
    9007:
      result := 'Source and target (for fileoutput) is the same';
    9015:
      result := 'The text is based on the rare codepage 1251.. extraction won''t work proper';
    9016:
      result := 'The text is based on the codepage CJK... extraction wont''t work proper';
  else
    result := 'Unknow error';
  end;
end;

function TPDFText.GetPDFNumPages(const FileName: string): LongInt;
begin
  result := GetPDFPageCount(PWideChar(FileName));
end;

function TPDFText.GetPDFContent(fileName: string): string;
var
  errorCode: integer;
begin
  result := GetPdfText(PWideChar(fileName));
  if (Length(result) <= 4) and TryStrToInt(result, errorCode) then
    result := GetPDFErrorMsg(errorCode);
end;

y para llamar a la clase:
Código Delphi [-]
uses PDFtext;

procedure TForm2.Button1Click(Sender: TObject);
var
  PDFText: TPDFText;
begin
  with OpenDialog1 do
    if execute then begin
      PDFText := TPDFText.Create;
      try
        memo1.lines.add(Format('%d pagina/s', [PDFText.GetPDFNumPages(filename)]));
        memo1.lines.add(Format('contenido:'#13'%s', [PDFText.GetPDFContent(filename)]));
      finally
        PDFText.Free;
      end;
    end;
end;

Los inconvenientes de este sistema son:
-La información obtenida del PDF no va en el mismo orden que se ve en el documento, aunque esto no es problema de la DLL si no mas bien de como está organizado el PDF internamente
-Y la DLL en su versión freeware, después de leer el PDF muestra una ventana con la información del autor

saludos
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
leer csv aprendiz_delphi OOP 9 27-03-2020 23:42:37
Leer CSV Willo Varios 4 04-04-2017 20:06:21
Leer EAN 128 newtron La Taberna 3 29-08-2016 04:09:53
Leer XML chinchan C++ Builder 3 08-11-2012 23:45:24
Leer XML cmm07 Varios 4 02-02-2010 14:36:05


La franja horaria es GMT +2. Ahora son las 18:50:45.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi