<< Click to Display Table of Contents >> Navigation: Direct Calls to DLL > pdfGetInfoW |
With Option=0, this method can be used to quickly fill a string list with the info items from a certain PDF file. This makes it possible to read "Author" or "Keywords".
The function will encode CRNL characters into "<br>" unless the Option 1024 was used.
You need to pass a buffer which is big enough to hold the data. The buffer (unicode char) will be filled with the items of the information record of the PDF file.
The function returns the count of bytes which were copied.
var s, b : WideString; os: Ansistring; n: Integer;
begin
os := WorkPath.Text + 'page_x%d.' + FileFormat.Text;
if not assigned(wpview_pdfGetInfoW) then
begin
ShowMessage('function pdfGetInfoW is not available');
exit;
end
else ShowMessage('Check Info Items');
if OpenDialog1.Execute then
begin
s := OpenDialog1.FileName;
SetLength(b, 10000);
n := wpview_pdfGetInfoW(PWideChar(s), PWideChar(b), Length(b),
'', // Password
PWideChar(WPViewPDF_LicName), PWideChar(WPViewPDF_LicKey), WPViewPDF_LicCode,
0);
if n <0 then ShowMessage('Cannot open file!')
else if n >= 0 then
begin
SetLength(b, n);
ShowMessage(b);
end;
end;
end;
Also possible Option=1024:
Read info strings with comma as separator between values
Using different values for option this method reads certain integer properties and returns the selected value. buflen is used as page number parameter.
Values for Option:
1: Read pagecount
2: Read page[pageno].width
3: Read page[pageno].height
4: Read page[pageno].rotate
Width and height are measured in pt, this is 1 inch / 72. Rotate can be 0, 90, 180 and 270 (degree)
The function returns the page count. Since the PDF file is only loaded a single time, this works much more efficiently than multiple calls.
values is used a integer array.
values[(pageno*3)+0] = width of page # pageno
values[(pageno*3)+1] = height of page # pageno
values[(pageno*3)+2] = rotate of page # pageno
maxvaluescount is the size of the array, it should be larger or equal to pagecount * 3;
maxvaluescount must be large enough to hold all values, otherwise not all page sizes can be returned.
In any case (and if values=nil) the return value will be the count of pages in the document.
Read info strings with comma as separator between values
fktpdfGetInfoW = function(filename: PWideChar; buffer: PWideChar;
buflen: Integer; password: PWideChar; licname, lickey: PWideChar;
liccode: Cardinal; Option: Integer): Integer; stdcall;
fktpdfGetInfoW2 = function(filename: PWideChar; IntRef: PInteger;
param: Integer; password: PWideChar; licname, lickey: PWideChar;
liccode: Cardinal; Option: Integer): Integer; stdcall;
The Return Value of pdfGetInfoW is <0 if the PDF file could not be loaded.
Delphi Example:
Create TShapes in a scrollbox for all pages in a document
var i, n, y : Integer;
s : string;
pag : array of Integer;
aPage : TShape;
lic_name, lic_key : WideString;
const MAXPAGES = 3000;
begin
if not assigned(wpview_pdfGetInfoW2) then
begin
ShowMessage('function pdfGetInfoW2 is not available');
exit;
end
else if OpenDialog1.Execute then
begin
s := OpenDialog1.FileName;
ListPagesFilename.ReadOnly := false;
ListPagesFilename.Text := s;
ListPagesFilename.ReadOnly := true;
for i := ListPagesScroll.ControlCount-1 downto 0 do
ListPagesScroll.Controls[i].Free;
SetLength(pag, MAXPAGES*3); // expect MAXPAGES pages ...
lic_name := WPViewPDF_LicName;
lic_key := WPViewPDF_LicKey;
n := wpview_pdfGetInfoW2(PWideChar(s), @pag[0], MAXPAGES*3,
'', // Password
PWideChar(lic_name), PWideChar(lic_key), WPViewPDF_LicCode,
5);
if n <0 then ShowMessage('Cannot open file!')
else
begin
y := 10;
for i := 0 to n-1 do
begin
aPage := TShape.Create(ListPagesScroll);
aPage.Tag := i;
aPage.Width := pag[(i*3)+0] div 10;
aPage.Height := pag[(i*3)+1] div 10;
aPage.Parent := ListPagesScroll;
aPage.Left := 10;
aPage.Top := y;
inc(y, 5 + aPage.Height);
end;
if n>MAXPAGES then ShowMessage('PDF cannot be fully scanned')
end;
end;
end;