UPDATE: We had a multipage document which went through the same process as posted below. It appears that this document was processed successfully. I don't know why having a registered copy changes things but it is almost as if the buffer isn't flushed if the document is <= a single buffer.
The section for case "Scoping" is the PDF document process. This is the 3rd bug we've encountered with using Aspose. As a note: while the code below generates a blank document, when we load the pages in the same manner and save the pages as an image, all of the data displays correctly in the image. Go figure.
{
private const int lowerLeftX = 50;
private const int lowerLeftY = 200;
private const int upperRightX = 550;
private const int upperRightY = 750;
private const int multiplier = 6;
private Page page = null;
private License license = new License();
public MobileService()
{
license.Embedded = true;
license.SetLicense("Aspose.Pdf.lic");
}
public byte[] GetMobileItems(List keyList)
{
if (keyList == null || keyList.Count.Equals(0))
{
throw new InvalidOperationException("No data passed in keyList parameter");
}
Document mergedDocument = new Document();
using (Data.EvergreenDatabase context = CreateDataContext())
{
foreach (MobileListDto element in keyList)
{
if (!element.MediaIdentity.HasValue)
{
continue;
}
switch (element.Category)
{
case "Image":
Document imageDocument = new Document();
page = imageDocument.Pages.Add();
using (Stream media = context.Functions.Media.GetMediaContent(element.MediaIdentity.Value))
{
page.Resources.Images.Add(media);
page.Contents.Add(new Operator.GSave());
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
page.Contents.Add(new Operator.ConcatenateMatrix(matrix));
XImage image = page.Resources.Images[page.Resources.Images.Count];
page.Contents.Add(new Operator.Do(image.Name));
page.Contents.Add(new Operator.GRestore());
mergedDocument.Pages.Add(imageDocument.Pages);
}
break;
case "Scoping":
using (Stream strm = context.Functions.Media.GetMediaContent(element.MediaIdentity.Value))
{
Document pdfDocument = new Document(strm);
// temporary workaround until Aspose fixes their stream bugs
//
string filename = Path.GetTempFileName().Replace(".tmp", "Scoping.pdf");
pdfDocument.Save(filename);
using (FileStream temp = File.OpenRead(filename))
{
pdfDocument = new Document(temp);
mergedDocument.Pages.Add(pdfDocument.Pages);
}
File.Delete(filename);
}
break;
case "Drawing":
using (Stream media = context.Functions.Media.GetMediaContentContent(element.MediaIdentity.Value))
{
Document drawingDocument = new Document();
//mergedDocument.Pages.Add(drawingDocument.Pages);
SvgDocument drawing = Svg.SvgDocument.Open(media);
drawing.Transforms = new Svg.Transforms.SvgTransformCollection();
drawing.Transforms.Add(new Svg.Transforms.SvgScale(multiplier, multiplier));
drawing.Width = new SvgUnit(drawing.Width.Type, drawing.Width * multiplier);
drawing.Height = new SvgUnit(drawing.Height.Type, drawing.Height * multiplier);
using (MemoryStream stream = new MemoryStream())
{
drawing.Draw().Save(stream, ImageFormat.Jpeg);
page = drawingDocument.Pages.Add();
page.Resources.Images.Add(stream);
page.Contents.Add(new Operator.GSave());
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
page.Contents.Add(new Operator.ConcatenateMatrix(matrix));
XImage image = page.Resources.Images[page.Resources.Images.Count];
page.Contents.Add(new Operator.Do(image.Name));
page.Contents.Add(new Operator.GRestore());
mergedDocument.Pages.Add(drawingDocument.Pages);
}
}
break;
};
}
}
byte[] buffer = null;
try
{
using (MemoryStream strm = new MemoryStream())
{
mergedDocument.Save(strm);
buffer = strm.ToArray();
}
}
catch (Exception exp)
{
DebugLogger.WriteLine(exp);
}
return buffer;
}