ExtractEmbeddedFile

Discussions about PDF management.
Post Reply
DiHa
Posts: 1
Joined: Wed Sep 17, 2014 9:07 am

ExtractEmbeddedFile

Post by DiHa » Wed Sep 17, 2014 9:26 am

In need Access to XML files which are incuded in a pdf. There for I want to use the method ExtractEmbeddedFile from your package. In your Documentation you have written the follow function structure in Delphi:

Code: Select all

public function ExtractEmbeddedFile(FileIdx: Integer; var  Data: array of Byte): GdPictureStatus; 
When I try this like your description Delphi called an error like "wrong Parameter type". So I search in the TLB-File and I have saw that the Method must be called like that:

Code: Select all

      function ExtractEmbeddedFile(FileIdx: Integer; var Data: PSafeArray): GdPictureStatus; safecall;
When I use this function as descriped Delphi didnt compiled the program. Only when I Switch Data to variant the Compiler generate the dll. On runtime i get the error "wrong Parameter";

Please tell me: How I can use the function ExtractEmbeddedFile that it fill the Content of an enbedded file in a stream? How i must handled the PSafeArray.

Best regards

Dirk

PS: Source code:

Code: Select all

  function TccXMPPartWriterPDF_GDP.xTractEmbededFilesByType(path, fileName: String): TFileStream;
  var
    count          : integer;
    i                  : Integer;
    fileStream   : TFileStream;
    byteArray    :TBytes;
    saveArrayV   : variant;
    saveArrayS   : PSafeArray;

    function SafeArrayToBytes(const si: PSafeArray): TBytes;
    var
      nLow, nHigh, nSize: integer;
      pData: Pointer;
    begin
      //Copy from Variant Array to Delphi array
      SafeArrayGetLBound(si, 1, nLow);
      SafeArrayGetUBound(si, 1, nHigh);
      nSize := SafeArrayGetElemsize(si);
      SetLength(Result, nSize * (nHigh - nLow + 1));

      SafeArrayAccessData(si, pData);
      CopyMemory(@Result[1], pData, Length(Result));
      SafeArrayUnaccessData(si);
    end;
  begin
    fileStream := nil;

    if gdPicturePDFSourceOrg.LoadFromFile(path, False) = GdPictureStatus_OK then
    begin
      count := self.gdPicturePDFSourceOrg.GetEmbeddedFileCount;

      for i := 0 to count-1 do
      begin
        if TccStrings.equalsExW(gdPicturePDFSourceOrg.GetEmbeddedFileName(i),fileName,true,true,true,true) then
        begin
          //----------------- ERROR ON NEXT LINE --------------------------------------------------------------------------------------
          if self.gdPicturePDFSourceOrg.ExtractEmbeddedFile(i,saveArrayV) = 0 then
          begin
            saveArrayS := PSafeArray(TVarData(saveArrayV).VArray);
            byteArray := SafeArrayToBytes(PSafeArray(saveArrayS));
            fileStream.Write(byteArray,length(byteArray));
            result := fileStream;
          end;
        end;
      end;
    end;


  end;

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: ExtractEmbeddedFile

Post by Gabriela » Wed Jan 30, 2019 8:56 pm

Hello,

Here you can find examples in C#/VB.NET:
https://www.gdpicture.com/guides/gdpicture/web ... ument.html
We are sorry we do not offer support in Delphi.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest