/// <summary> /// Sends resulting document to the client. /// </summary> /// <param name="document">The resulting document.</param> public void SendDocument(IMergeDocument document) { var documentRenderer = new PdfDocumentRenderer { Document = document.ResultingDocument }; documentRenderer.RenderDocument(); var pageCount = documentRenderer.PdfDocument.PageCount - 1; documentRenderer.PdfDocument.Pages.RemoveAt(pageCount); var documentToSend = documentRenderer.PdfDocument; var buffer = new byte[1024]; using (var stream = new MemoryStream()) { documentToSend.Save(stream, false); stream.Position = 0; var position = 0; var size = (int)Math.Ceiling((double)(stream.Length) / 1024) - 1; int bytesRead; while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0) { var chunk = new DocumentChuckMessage { Position = position, Size = size, Buffer = buffer.ToList(), BufferSize = bytesRead }; position++; using (var serverQueue = new MessageQueue(MergePagesQueuesNames.Server, QueueAccessMode.Send)) { var message = new Message(chunk); serverQueue.Send(message); } } } }
public void SaveResultDocument(ref IMergeDocument document, IDocumentFactory factory) { document.SaveResult($"{OutputDirectory.FullName}\\{Guid.NewGuid()}.pdf"); document = factory.CreateDocument(); }