j-petty / HtmlRendererCore

HtmlRendererCore is a partial port of HtmlRenderer for .NET Core.
MIT License
24 stars 8 forks source link

Cannot save a PDF document with no pages. HtmlRenderCore.PdfSharpCore #6

Open PrakashPaul opened 1 year ago

PrakashPaul commented 1 year ago

var result = string.Empty;

using (var stream = new MemoryStream()) { var pdf = PdfGenerator.GeneratePdf(html, PdfSharpCore.PageSize.A4);

pdf.Save(stream);

result = Convert.ToBase64String(stream.ToArray());

}

GitHubRulesOK commented 1 year ago

The title says "no pages" but then there is no PDF to save, since the very first step in ALL valid PDF is state the initial Page Media then the contents inside and outside that Page !

BS.WriteText("1 0 obj <</Type/Catalog/Pages 2 0 R>> endobj\n"); BS.WriteText("2 0 obj <</Type/Pages/Count 1/Kids[3 0 R]>> endobj\n"); BS.WriteText("3 0 obj <</Type/Page/MediaBox[0 0 144 144]/Rotate 0/Resources<</XObject<</Img0 4 0 R>>>>/Contents 5 0 R/Parent 2 0 R>> endobj\n"); ... BS.WriteText("0000000000 00001 f \n0000000015 00000 n \n0000000060 00000 n \n0000000111 00000 n \n0000000237 00000 n \n"+Pos1.slice(-10)+" 00000 n \n"); .. startxref\n"+Pos2+"\n%%EOF\n"); .. BS.SaveToFile("HelloWorldB&W.pdf", 2);

to be a valid PDF that BS needs save as file which will be a minimum of 4/5 file objects since the file index needs to store the file contents index so the file before stream will be about 10 lines of text of different binary byte length that need to be file write as indexed decimal file lengths any write to stream must include the filename for parsing as PDF before the stream can be file converted to base.64 file for recipient via any array ngment

Chebura commented 4 months ago

Same error FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine AS base ... RUN apk add libgdiplus --repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/community/

win/ubuntu working fine

PdfGenerator creates empty pdf without pages. AddPdfPages() method has internal loop for with AddPage() within that never invoked