private static SKDocumentPdfMetadata MapMetadata(DocumentMetadata metadata) { return(new SKDocumentPdfMetadata { Title = metadata.Title, Author = metadata.Author, Subject = metadata.Subject, Keywords = metadata.Keywords, Creator = metadata.Creator, Producer = metadata.Producer, Creation = metadata.CreationDate, Modified = metadata.ModifiedDate, RasterDpi = metadata.RasterDpi, EncodingQuality = metadata.ImageQuality, PdfA = metadata.PdfA }); }
internal static void RenderPass <TCanvas>(PageContext pageContext, TCanvas canvas, Container content, DocumentMetadata documentMetadata, DebuggingState?debuggingState) where TCanvas : ICanvas, IRenderingCanvas { content.VisitChildren(x => x?.Initialize(pageContext, canvas)); content.VisitChildren(x => (x as IStateResettable)?.ResetState()); canvas.BeginDocument(); var currentPage = 1; while (true) { pageContext.SetPageNumber(currentPage); debuggingState?.Reset(); var spacePlan = content.Measure(Size.Max); if (spacePlan.Type == SpacePlanType.Wrap) { canvas.EndDocument(); ThrowLayoutException(); } try { canvas.BeginPage(spacePlan); content.Draw(spacePlan); } catch (Exception exception) { canvas.EndDocument(); throw new DocumentDrawingException("An exception occured during document drawing.", exception); } canvas.EndPage(); if (currentPage >= documentMetadata.DocumentLayoutExceptionThreshold) { canvas.EndDocument(); ThrowLayoutException(); } if (spacePlan.Type == SpacePlanType.FullRender) { break; } currentPage++; } canvas.EndDocument(); void ThrowLayoutException() { var message = $"Composed layout generates infinite document. This may happen in two cases. " + $"1) Your document and its layout configuration is correct but the content takes more than {documentMetadata.DocumentLayoutExceptionThreshold} pages. " + $"In this case, please increase the value {nameof(DocumentMetadata)}.{nameof(DocumentMetadata.DocumentLayoutExceptionThreshold)} property configured in the {nameof(IDocument.GetMetadata)} method. " + $"2) The layout configuration of your document is invalid. Some of the elements require more space than is provided." + $"Please analyze your documents structure to detect this element and fix its size constraints."; throw new DocumentLayoutException(message) { ElementTrace = debuggingState?.BuildTrace() ?? "Debug trace is available only in the DEBUG mode." }; } }
public ImageCanvas(DocumentMetadata metadata) { Metadata = metadata; }
public PdfCanvas(Stream stream, DocumentMetadata documentMetadata) : base(SKDocument.CreatePdf(stream, MapMetadata(documentMetadata))) { }
public XpsCanvas(Stream stream, DocumentMetadata documentMetadata) : base(SKDocument.CreateXps(stream, documentMetadata.RasterDpi)) { }