Greetings,
I am writing this post to address three problems.
Issue #1
The first issue is that our license that was purchased today is acting as if it were a trial and is still watermarking our images. After following documentation as well as forum posts about including the license via embedding as well as streaming, we have found no resolution to this problem. After perusing the forums it appears that many people have issues where the license end date is incorrect. The date is as follows:
<SubscriptionExpiry>20150115</SubscriptionExpiry>
We have included the license in the following manners before using any of the Aspose API calls. We have moved the license to various directories (including the directory with the DLLs, the root of the project directory, the bin directory, etc) that have been suggested by staff on these forums and the documentation:
Aspose.Pdf.License license = new Aspose.Pdf.License();
var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Pdf.lic");
FileStream myStream = new FileStream(file, FileMode.Open);
license.SetLicense(myStream);
license.Embedded = true;
As well as:
var lic = new Aspose.Pdf.License { Embedded = true };
lic.SetLicense("Aspose.Pdf.lic");
We would be grateful for any assistance with this issue that is possible. Preferably if there is a sample project or class that can be shown to demonstrate how the license should be called and when/how often it should be.
Issue #2
We assume that this issue is caused (after speaking with technical support and prior forum posts) due to the license issue mentioned above. However, we would like to have it addressed regardless in case they are unrelated. When we are creating a PDF file out of images it appears that the the PDF itself is blank. Note that we have tried this with 1 image, 2 images, 3, and 4 (from what I've read the trial limits you to 4). This problem occurs with any number of images. However, when we write annotations to it they are saved and the appropriate pages are created. The image files that are sent to it are not rendered, though. We are not sure if this stems from the license problem (listed above) or not. Any assistance would be appreciated. Our code is as follows (the problematic function is CreateAndSavePDFFromImages) .
namespace Application.Service.Implementations
{
public class AsposeService : IPDFService
{
const int ASPOSE_RESOLUTION = 200;
const int ASPOSE_QUALITY = 30; // [0-100], 100 is Maximum
//Aspose.Pdf.License license;
public AsposeService()
{
//lic = new Aspose.Pdf.License { Embedded = true };
//lic.SetLicense("Aspose.Pdf.lic");
}
public void CreateAndSavePDFFromImages(string fileName, List<Image> images)
{
//var lic = new Aspose.Pdf.License { Embedded = true };
//lic.SetLicense("Aspose.Pdf.lic");
var doc = new Aspose.Pdf.Document();
foreach (var image in images) {
var page = doc.Pages.Add();
page.Resources.Images.Add(new MemoryStream(image.Data));
double lowerLeftX = 0;
double lowerLeftY = 0;
double upperRightX = doc.PageInfo.Width;
double upperRightY = doc.PageInfo.Height;
if (!image.Width.HasValue) image.Width = (float)upperRightX;
if (!image.Height.HasValue) image.Height = (float)upperRightY;
double xFactor = (double)(upperRightX / image.Width);
double yFactor = (double)(upperRightY / image.Height);
page.Contents.Add(new Aspose.Pdf.Operator.GRestore());
var rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
var 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 Aspose.Pdf.Operator.ConcatenateMatrix(matrix));
Aspose.Pdf.XImage ximage = page.Resources.Images[page.Resources.Images.Count];
page.Contents.Add(new Aspose.Pdf.Operator.Do(ximage.Name));
page.Contents.Add(new Aspose.Pdf.Operator.GRestore());
foreach (var dataPoint in image.DataPoints) {
if (dataPoint.XCoor.HasValue && dataPoint.YCoor.HasValue) {
var x = (double)dataPoint.XCoor * xFactor;
var y = doc.PageInfo.Height - (double)dataPoint.YCoor * yFactor;
var rect = new Aspose.Pdf.Rectangle(x, y, x, y);
var ann = new Aspose.Pdf.InteractiveFeatures.Annotations.TextAnnotation(page, rect);
ann.Title = dataPoint.UserName;
ann.Subject = dataPoint.DataPointType.Name;
ann.Contents = dataPoint.DataPointType.Name;
//ann.Contents = dataPoint.Value;
ann.Open = true;
ann.State = Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationState.Accepted;
ann.Icon = Aspose.Pdf.InteractiveFeatures.Annotations.TextIcon.Comment;
page.Annotations.Add(ann);
}
}
doc.Save(fileName);
}
}
public List<Image> ConvertPDFToImages(byte[] pdf)
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Pdf.lic");
FileStream myStream = new FileStream(file, FileMode.Open);
license.SetLicense(myStream);
license.Embedded = true;
//var lic = new Aspose.Pdf.License { Embedded = true };
//lic.SetLicense("Aspose.Pdf.lic");
var doc = new Aspose.Pdf.Document(new MemoryStream(pdf));
var images = new List<Image>();
for (int pageCount = 1; pageCount <= doc.Pages.Count; pageCount++) {
var image = new Image();
image.FileName = "image" + pageCount + ".jpg";
image.FileType = "image/jpeg";
var resolution = new Aspose.Pdf.Devices.Resolution(ASPOSE_RESOLUTION);
//Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(500, 700, resolution, 100);
Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(resolution, ASPOSE_QUALITY);
using (var stream = new FileStream("C:\\temp\\image" + pageCount + ".jpg", FileMode.Create)) {
jpegDevice.Process(doc.Pages[pageCount], stream);
}
using (var stream = new MemoryStream()) {
jpegDevice.Process(doc.Pages[pageCount], stream);
image.Data = stream.ToArray();
}
images.Add(image);
}
return images;
}
}
}
Issue #3
In the above code, ConvertPDFToImages places watermarks on the images (sometimes just the first). We believe this stems from the license issue.
I am writing this post to address three problems.
Issue #1
The first issue is that our license that was purchased today is acting as if it were a trial and is still watermarking our images. After following documentation as well as forum posts about including the license via embedding as well as streaming, we have found no resolution to this problem. After perusing the forums it appears that many people have issues where the license end date is incorrect. The date is as follows:
<SubscriptionExpiry>20150115</SubscriptionExpiry>
We have included the license in the following manners before using any of the Aspose API calls. We have moved the license to various directories (including the directory with the DLLs, the root of the project directory, the bin directory, etc) that have been suggested by staff on these forums and the documentation:
Aspose.Pdf.License license = new Aspose.Pdf.License();
var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Pdf.lic");
FileStream myStream = new FileStream(file, FileMode.Open);
license.SetLicense(myStream);
license.Embedded = true;
As well as:
var lic = new Aspose.Pdf.License { Embedded = true };
lic.SetLicense("Aspose.Pdf.lic");
We would be grateful for any assistance with this issue that is possible. Preferably if there is a sample project or class that can be shown to demonstrate how the license should be called and when/how often it should be.
Issue #2
We assume that this issue is caused (after speaking with technical support and prior forum posts) due to the license issue mentioned above. However, we would like to have it addressed regardless in case they are unrelated. When we are creating a PDF file out of images it appears that the the PDF itself is blank. Note that we have tried this with 1 image, 2 images, 3, and 4 (from what I've read the trial limits you to 4). This problem occurs with any number of images. However, when we write annotations to it they are saved and the appropriate pages are created. The image files that are sent to it are not rendered, though. We are not sure if this stems from the license problem (listed above) or not. Any assistance would be appreciated. Our code is as follows (the problematic function is CreateAndSavePDFFromImages) .
namespace Application.Service.Implementations
{
public class AsposeService : IPDFService
{
const int ASPOSE_RESOLUTION = 200;
const int ASPOSE_QUALITY = 30; // [0-100], 100 is Maximum
//Aspose.Pdf.License license;
public AsposeService()
{
//lic = new Aspose.Pdf.License { Embedded = true };
//lic.SetLicense("Aspose.Pdf.lic");
}
public void CreateAndSavePDFFromImages(string fileName, List<Image> images)
{
//var lic = new Aspose.Pdf.License { Embedded = true };
//lic.SetLicense("Aspose.Pdf.lic");
var doc = new Aspose.Pdf.Document();
foreach (var image in images) {
var page = doc.Pages.Add();
page.Resources.Images.Add(new MemoryStream(image.Data));
double lowerLeftX = 0;
double lowerLeftY = 0;
double upperRightX = doc.PageInfo.Width;
double upperRightY = doc.PageInfo.Height;
if (!image.Width.HasValue) image.Width = (float)upperRightX;
if (!image.Height.HasValue) image.Height = (float)upperRightY;
double xFactor = (double)(upperRightX / image.Width);
double yFactor = (double)(upperRightY / image.Height);
page.Contents.Add(new Aspose.Pdf.Operator.GRestore());
var rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
var 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 Aspose.Pdf.Operator.ConcatenateMatrix(matrix));
Aspose.Pdf.XImage ximage = page.Resources.Images[page.Resources.Images.Count];
page.Contents.Add(new Aspose.Pdf.Operator.Do(ximage.Name));
page.Contents.Add(new Aspose.Pdf.Operator.GRestore());
foreach (var dataPoint in image.DataPoints) {
if (dataPoint.XCoor.HasValue && dataPoint.YCoor.HasValue) {
var x = (double)dataPoint.XCoor * xFactor;
var y = doc.PageInfo.Height - (double)dataPoint.YCoor * yFactor;
var rect = new Aspose.Pdf.Rectangle(x, y, x, y);
var ann = new Aspose.Pdf.InteractiveFeatures.Annotations.TextAnnotation(page, rect);
ann.Title = dataPoint.UserName;
ann.Subject = dataPoint.DataPointType.Name;
ann.Contents = dataPoint.DataPointType.Name;
//ann.Contents = dataPoint.Value;
ann.Open = true;
ann.State = Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationState.Accepted;
ann.Icon = Aspose.Pdf.InteractiveFeatures.Annotations.TextIcon.Comment;
page.Annotations.Add(ann);
}
}
doc.Save(fileName);
}
}
public List<Image> ConvertPDFToImages(byte[] pdf)
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Pdf.lic");
FileStream myStream = new FileStream(file, FileMode.Open);
license.SetLicense(myStream);
license.Embedded = true;
//var lic = new Aspose.Pdf.License { Embedded = true };
//lic.SetLicense("Aspose.Pdf.lic");
var doc = new Aspose.Pdf.Document(new MemoryStream(pdf));
var images = new List<Image>();
for (int pageCount = 1; pageCount <= doc.Pages.Count; pageCount++) {
var image = new Image();
image.FileName = "image" + pageCount + ".jpg";
image.FileType = "image/jpeg";
var resolution = new Aspose.Pdf.Devices.Resolution(ASPOSE_RESOLUTION);
//Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(500, 700, resolution, 100);
Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(resolution, ASPOSE_QUALITY);
using (var stream = new FileStream("C:\\temp\\image" + pageCount + ".jpg", FileMode.Create)) {
jpegDevice.Process(doc.Pages[pageCount], stream);
}
using (var stream = new MemoryStream()) {
jpegDevice.Process(doc.Pages[pageCount], stream);
image.Data = stream.ToArray();
}
images.Add(image);
}
return images;
}
}
}
Issue #3
In the above code, ConvertPDFToImages places watermarks on the images (sometimes just the first). We believe this stems from the license issue.