Free Support Forum - aspose.com

Files load differently when licensed vs. eval is active

There are two files attached. The first was saved after loading the document while in eval mode (tmpA29Sco…). As you can see from the document : all titles and values are loaded.


The second file (tmpD7855…) was after activating the product. All titles and fields are missing.

This is a significant bug in my humble opinion.

I am setting the license in the constructor of my service:
Aspose.Pdf.License license = new Aspose.Pdf.License();
public MobileService()
{
license.Embedded = true;
license.SetLicense(“Aspose.Pdf.lic”);
}

Hi Michael,


Thanks for contacting support.

Can you please share some details on how you are creating these documents using Aspose.Pdf for .NET ? If possible, can you please share the document generation code.

We are sorry for this inconvenience.
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;
}

Hi Michael,


Thanks for sharing the details and sorry for delayed response.

As per my understanding, “Scoping” case concatenates PDF file and during my testing, when I have used the sample PDF files present over my end, I did not notice any issue when using the product in licensed mode. Can you please share some sample project along with resources files which you are using, so that we can again try replicating this issue at our end. We are sorry for this inconvenience.

Trust me, even we don’t want to touch the project files this code is in. :slight_smile: You’d never get it working. The code I sent you is basically what we are doing. I did notice after posting that we are currently running 7.6 instead of 7.9. I’m in the process of upgrading to see if that fixes the issue.

Hi,


Please try using the latest release version and in case the problem still persists, please share some further details which can help us in replicating this problem. Please note that until or unless we are able to replicate this problem, we might not be able to figure out the actual reasons of this issue.

We are upgraded to version 7.9 and still encounter the problem. So the steps we go through are as follows:


A web service is called to get the form as a byte array.
The webservice calls another component which creates one of our classes (basically a proxied stream object which takes the filestream of the file as input. This is the line in the code

using (Stream media = context.Functions.Media.GetMediaContent(element.MediaIdentity.Value))

The proxied stream is then used to load the pdf document into Aspose…
To workaround some other issues we save the file and create a file stream.
The stream is read by the PDF creator to populate the page with data.

We then merge the pages into a merge document so that all requested objects are returned. This is all of the logic in case “Scope”:

Now in this page that calls the code, the user gets a list of attachments from mobile to view. This includes images, small pdf documents, large pdf forms, and svg drawings. They can preview the attachments (this is the process that shows the error) or save them as a zip file of images of each object. For the pdf documents we create an image of each page in the document, images just go right into the zip file, and svg files go into Aspose, then saved as an image into the zip file.

Regardless of request type, the documents are loaded the same for each process and in the latter request type (Save As Image) we add each image into a zip file to be returned to the caller.

So I either enumerate over each page to make it into an image OR I do a mergeDocument.Pages.Add(pdfDocument.Pages); When I enumerate over the pages it is interesting that I see the entire document in the image! But when I just say “here, merge this stuff” the resulting merge is without the data. And we have done testing in both directions and with a ton of items merged as well as just the failing document merged. Regardless of either way we always miss data when we merge but get data when we convert to an image. If I make a single change (comment out license registration) we get the document and the image created properly but with the Eval stamp added to the page.

One thing I just thought of: we take the merged document, save it as a memory stream, and return a byte array to the client. The client then takes the byte array and feeds it to a pdf viewer to display the document. Just to make sure that “sending over wire” wasn’t an issue on our side I wrote temp code to save the file on the server. Thus the two files you have in this thread.

I hope this detail helps.

Here is a simple way to repro this (or try to)


Write a class that opens a filestream to the first document. Wrap that in a Stream and return the stream to the caller.

Write a class that uses the [ case “Scope”: ] code and call the first class to get the stream object instead of the italized call in my previous post.

Write a third class that has the adobe pdf view activeX control hosted in a wpf viewer.

Have that wpf class call the second class and have it return a byte array of the pdf document. Feed that into the adobe viewer.

Good luck.

Hi Michael,


Thanks for sharing the details. We are looking into it and will update you soon.

Best Regards,