weolar / miniblink49

a lighter, faster browser kernel of blink to integrate HTML UI in your app. 一个小巧、轻量的浏览器内核,用来取代wke和libcef
Apache License 2.0
7.22k stars 1.09k forks source link

wkeUtilPrintToPdf access violation #534

Closed hafedh-trimeche closed 2 years ago

hafedh-trimeche commented 2 years ago

Hello,

Please note taht wkeUtilPrintToPdf generated an exception when invoked with this code (Pascal/Delphi):

Project MiniBlink.exe raised exception class $C0000094 with message 'integer divide by zero at 0x5f7076e6'.

type
  _wkePdfDatas =
  packed record
    count : Integer;
    sizes : ^size_t ;
    datas : PPointer;
  end;
  wkePdfDatas = ^_wkePdfDatas;

  _wkePrintSettings =
  packed record
    structSize               : Integer;
    dpi                      : Integer;
    width                    : Integer; // in px
    height                   : Integer;
    marginTop                : Integer;
    marginBottom             : Integer;
    marginLeft               : Integer;
    marginRight              : Integer;
    isPrintPageHeadAndFooter : BOOL;
    isPrintBackgroud         : BOOL;
    isLandscape              : BOOL;
  end;
  wkePrintSettings = ^_wkePrintSettings;

------------------------------------
procedure ExprotToPdf;
var
  HTML           : string;
  Bytes          : TBytes;
  PrintSettings  : _wkePrintSettings;
  PdfDatas       : wkePdfDatas;
begin
  HTML := ReadFromTextFile(htmlFile);
  WkeBrowser.LoadHTML(HTML);
  while (not WkeBrowser.DocumentReady) do RelinquishTimeSlice;
  InitRecord(PrintSettings,SizeOf(PrintSettings)); // FillChar(PrintSettings,SizeOf(PrintSettings),0);
  PrintSettings.structSize       := SizeOf(PrintSettings);
  PrintSettings.isPrintBackgroud := True;
  PdfDatas := wkeUtilPrintToPdf(WkeBrowser,nil,@PrintSettings); // AV here

Best regards.

hafedh-trimeche commented 2 years ago

Hello,

Tha Access Violation is caused by non setting a positive value for the dpi parameter!

Problem solved but the result indicates that it contains 2 pages even if the document integrates only one.

Best regards.