Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Width property is not parsed inside CSS body #317

Open
hafedh-trimeche opened this issue Apr 3, 2022 · 2 comments
Open

Width property is not parsed inside CSS body #317

hafedh-trimeche opened this issue Apr 3, 2022 · 2 comments

Comments

@hafedh-trimeche
Copy link

Hello,

Using this code to convert HTML to PDF via SynPdf component, the PNG image is not rendered ; JPG does.

function THtmlPager.SynPdf:TBytes;
label
  Clear;
var
  OK     : Boolean;
  Size   : TSize;
  PDF    : TPdfDocumentGDI;
  Stream : TMemoryStream;
begin
  PDF  := nil;
  PDF  := TPdfDocumentGDI.Create;
  OK   := True;
  Size := FullDisplaySize(Width);
  try
    {PDF.UseUniscribe     := True;}
    PDF.DefaultPaperSize  := psUserDefined;
    PDF.ScreenLogPixels   := Screen.PixelsPerInch;
    PDF.Info.Author       := EditorOrgName;
    PDF.Info.CreationDate := Now;
    PDF.Info.Creator      := ApplicationName;
    PDF.Info.Keywords     := '';
    PDF.GeneratePDF15File := True;
    PDF.DefaultPageWidth  := Round(Size.cx*72/PDF.ScreenLogPixels);
    PDF.DefaultPageHeight := Round(Size.cy*72/PDF.ScreenLogPixels);
    PDF.AddPage;
    HTMLPaint(PDF.VCLCanvas,Rect(0,0,Size.cx,Size.cy));
  except
    OK := False;
  end;
  if (not OK) then goto Clear;
  Stream := TMemoryStream.Create;
  try
    PDF.SaveToStream(Stream);
  except
    Stream.Clear;
  end;
  SetLength(Result,Stream.Size);
  Stream.Position := 0;
  Stream.Read64(Result,0,Length(Result));
  FreeAndNil(Stream);
Clear:
  if Assigned(PDF) then FreeAndNil(PDF);
end;

Would real rendered Width and Height determined without the default width parameter provided to FullDisplaySize function?

Would margins set to 0 so document and control widths will be identical by introducing paraemetrs to the function:

procedure THtmlViewer.UpdateSize;
begin
  if AutoSize then
  begin
    HScrollBar.Visible := False;
    VScrollBar.Visible := False;
    SetBounds(Left, Top, ScrollWidth + 2, MaxVertical + 2);
  end;
end;

which would be:

procedure THtmlViewer.UpdateSize;
begin
  if AutoSize then
  begin
    HScrollBar.Visible := False;
    VScrollBar.Visible := False;
    SetBounds(Left, Top, ScrollWidth + WidthMargin, MaxVertical + HeightMargin);
  end;
end;

Best regards.

@hafedh-trimeche
Copy link
Author

Hello,
The Width attribute is not parsed inside CSS body (210mm). The real Width of the html is set ignoring this attribute.

<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
   <title>Residence information</title>
   <style>
       body {
           font-family: "Courier New", Courier, monospace;
           font-size: small;
           position: absolute;
           width:210mm;
           margin:0mm;
       }

Please note that the Height is set to its correct value.

Best regards.

@hafedh-trimeche
Copy link
Author

Sorry,

The PNG rendering problem is caused by the SynPdf component!
https://github.com/synopse/SynPDF

Best regards.

@BerndGabriel BerndGabriel changed the title PNG image not rendered on SynPdf Canvas. Width property is not parsed inside CSS body May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant