Beside font resources and extractable text, PDF file can contain vector graphics, tables or Acroforms that can be visually rendered on the page.
To make sure that there are no visual elements on the page beside images we just need to remove all images from the page.
After this page should become visually empty (blank).
Here is PageContainsImages() function that basically answers are there any images on PDF page.
Your opinion and testing results are welcome.
procedure ClonePageDimensions(QPL: TQuickPDF; SourcePage, TargetPage: Integer); type TPageBox = record Left: Double; Top: Double; Width: Double; Height: Double; end; var i: Integer; width, height: Double; rotation: Integer; boxes: array [1..5] of TPageBox; begin with QPL do begin // Reading dimensions from Source Page SelectPage(SourcePage); width := PageWidth; height := PageHeight; rotation := PageRotation; for i := 1 to 5 do begin boxes.Left := GetPageBox(i, 0); boxes.Top := GetPageBox(i, 1); boxes.Width := GetPageBox(i, 2); boxes.Height := GetPageBox(i, 3); end; // Saving dimensions to Target Page SelectPage(TargetPage); SetPageDimensions(width, height); RotatePage(rotation); for i := 1 to 5 do SetPageBox(i, boxes.Left, boxes.Top, boxes.Width, boxes.Height); end; end;
function PageContainsImages(QPL: TQuickPDF; Page: Integer; DPI: Integer): Boolean; var i: Integer; doc, doc_tmp: Integer; s, s_tmp: AnsiString; begin Result := False; with QPL do begin try // custom Document is selected if FindImages = 0 then Exit; doc := SelectedDocument; doc_tmp := NewDocument; // temporary Document is selected CopyPageRanges(doc, IntToStr(Page)); // Page 2 contains customer's page copy atm SelectPage(2); // clear all image content on Page 2 for i := 1 to FindImages do ClearImage(GetImageID(i)); // Page 1 is empty and its dimensions should be equal to Page 2 ClonePageDimensions(QPL, 2, 1); s := RenderPageToString(DPI, 2, 0); s_tmp := RenderPageToString(DPI, 1, 0); // Compare Page 1 and Page 2 by size and content if Length(s) <> Length(s_tmp) then Exit; Result := True; for i := 1 to Length(s) do if s <> s_tmp then begin Result := False; Exit; end; finally RemoveDocument(doc_tmp); end; end; end;
------------- Regards,
Dmitry
|