I have a webview correctly displaying the HTML content. When loading a lot of information the webview still displays correctly, but the generated PDF stops adding the content and only adds white space.
If i scroll through the webview before generating the PDF, the second half of the PDF will be included in the document while the first part is ignored and resulting in white space.
view.Measure(
View.MeasureSpec.MakeMeasureSpec( ViewGroup.LayoutParams.WrapContent,MeasureSpecMode.Unspecified),
View.MeasureSpec.MakeMeasureSpec(ViewGroup.LayoutParams.WrapContent, MeasureSpecMode.Unspecified));
view.Layout(0, 0, view.MeasuredWidth, view.MeasuredHeight);
var printAttributesBuilder = new PrintAttributes.Builder();
printAttributesBuilder.SetColorMode(PrintColorMode.Color);
printAttributesBuilder.SetMediaSize(PrintAttributes.MediaSize.IsoA4);
printAttributesBuilder.SetDuplexMode(DuplexMode.None);
printAttributesBuilder.SetMinMargins(PrintAttributes.Margins.NoMargins);
PdfDocument document = new PrintedPdfDocument(view.Context, printAttributesBuilder.Build());
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(view.MeasuredWidth, view.MeasuredHeight, 1).Create();
PdfDocument.Page page = document.StartPage(pageInfo);
view.Draw(page.Canvas);
document.FinishPage(page);
byte[] docBytes = null;
using (MemoryStream memoryStream = new MemoryStream())
{
try
{
document.WriteTo(memoryStream);
docBytes = memoryStream.ToArray();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return docBytes;
and also
WebView.EnableSlowWholeDocumentDraw();
I believe that the size of the PDF is correct, somehow only the content stops from adding. The remaining white space takes aproximately the same space like the missing content would. I tried using the PrintManager and that generates a 30 page PDF based on the same HTML. But I do not want to use PrintManager or any other libraries, i have to make the posted solution work.
Any input is highly appreciated!