I’m using Aspose.Pdf 6.8.0.0 (2012.03.01), .NET 2.0 version.
Opening of the following PDF fails with error: “Cross reference table or cross refference stream not found”.
Adobe Reader 10.1.2 is able to open the PDF in question.
Hi Juha,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank
you for sharing the sample file.
I am
able to reproduce your mentioned issue after an initial test. Your issue has been
registered in our issue tracking system with issue id:PDFNEWNET-33510. You will be notified via this forum thread
regarding any updates against your issue.
Hi
Juha,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank
you for the details.
However,
your issue was not fixed in our latest release i.e. Aspose.Pdf for .NET v6.9.
We have fixed the issue and the fix will be a part of our upcoming release of
Aspose.Pdf for .NET v7.0 (to be release in a few days time.). Please be patient
and spare us some time to complete our testing and publishing process. We will
notify you via this forum thread once the latest fix is available for download.
I'm using Aspose.Pdf 7.0.0.0 and .NET 3.5 version.
In a folder, I have around 1200 pfd files, here we try to take one by one pdf file and add a text(i.e. "Duplicate Copy") on the top of the pdf file.
I am trying this using a scheduler. Every time I run this scheduler, it work for only 258 file and show a error "Cross reference table or cross refference stream not found".
But in you forum it is written that "The issues you have found earlier (filed as PDFNEWNET-33510) have been fixed in Aspose.Pdf for .NET 7.0.0.".
This is very urgent, please confirm as soon as posiable.
Hi Kali
Charan,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Well, the
issue reported by the user as PDFNEWNET-33510 was fixed as per the
information shared by the user. However, the issue you are facing may be
different from that particular issue. Please share your PDF files and sample
code to help us reproduce the issue at our end. We will check it and get back
to you soon.
We are having the same issue.
The document byte array is getting passed to return the PDF document, but trying to pass the page to get the stamp on it I get the same error (when evaluating doc.Pages[i] using the Shift+F9 feature). Since I have multiple methods that use the aspose document object, I actually don’t know what I am missing here.
var doc = AsposeImplementation.DocumentFromBytes(document);
for (int i = 1; i <= doc.Pages.Count; i++)
{
if (templateDataTable.Count >= i)
{
//Bind stamp
fileStamp.BindPdf(doc);
// Create stamp.
var templateStamp = AsposeImplementation.GetImageStamp(templateDataTable[0], doc.Pages[i], templateDataTable[i - 1].TemplateBlob);
fileStamp.AddStamp(templateStamp);
}
}
The function I am calling is defined as
public static Aspose.Pdf.Document DocumentFromBytes(byte[] documentFromBytes)
{
LoadAsposeLicense();
if (documentFromBytes == null || documentFromBytes.Length == 0)
{
var doc = new Aspose.Pdf.Document();
doc.Pages.Insert(1);
return doc;
}
using (var asposeDocumentStream = new MemoryStream(documentFromBytes))
{
var doc = new Aspose.Pdf.Document(asposeDocumentStream);
return doc;
}
}
and to return the image stamp I pass the Page object as
public static Aspose.Pdf.Facades.Stamp GetImageStamp(DsDocumentTemplate.TTemplateDataRow dataTemplateRow, Page page, byte[] imageBytes, bool isBackGround = true)
{
LoadAsposeLicense();
// Scale image with the page size
var image = new MagickImage(imageBytes);
image.Scale((int)page.PageInfo.Width, (int)page.PageInfo.Height);
using(var imageStream = new MemoryStream(image.ToByteArray()))
{
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindImage(imageStream);
stamp.SetOrigin(dataTemplateRow.OffsetXNullable(), dataTemplateRow.OffsetYNullable());
stamp.IsBackground = isBackGround;
return stamp;
}
}
I checked the PDF with a validator and all PDFs I’ll try to use seem to be correct. I’ll try to find a pdf document which I can share.
The specific exception is: #=ziEiFFdsFThPHIJ19hqc43cRK3wor: ‘Cross reference table or cross reference stream not found’
Here are two sample files that throw the same exception. po.pdf (86.6 KB) Attachment_1_duplicate.pdf (54.6 KB)
The version we are using is Aspose.Pdf 23.6.0 for multiple .NET 4.8 project/class library.
We were not able to replicate the error that you mentioned. Please note that we were not able to use all stamp settings as values were not in the code snippet shared by you. Nevertheless, attached are the output files for your kind reference. Can you please try using 24.4 version and let us know if you still notice any issues.
Hi!
Thank you for you assitance. The issue we are trying to solve in to have a source pdf and a stamping pdf. if the stamp pdf has lower page count than the source pdf. The last page of the stamping pdf is used till the end. However the stamp can be also provided as an image. My current code snippet throws me also an “Cannot access a closed stream”.
The most code I can share is
public static byte[] TransformDocument(byte[] document, Data tableData, string mimeType)
{
byte[] transformedDocument = new byte[0];
if (document == null)
{
transformedDocument = new byte[0];
}
if (templateDataTable.Count == 0)
{
transformedDocument = document;
}
else
{
/* hadnling other mime types */
if (mimeType == MimeType.Pdf)
{
var doc = AsposeImplementation.DocumentFromBytes(document);
if (tableData[0].MimeType == MimeType.Pdf)
{
var templateDocument = AsposeImplementation.DocumentFromBytes(tableData[0].TemplateBlob);
for (int i = 0; i < doc.Pages.Count; i++)
{
using (var fileStamp = new PdfFileStamp())
{
fileStamp.BindPdf(doc);
int templatePageIndex = i + 1;
var pageHeight = doc.Pages[i + 1].PageInfo.Height;
var pageWidth = doc.Pages[i + 1].PageInfo.Width;
if (templatePageIndex > templateDocument.Pages.Count)
templatePageIndex = templateDocument.Pages.Count;
¸¸
var templateStamp = AsposeImplementation.GetPDFStamp(templateDataTable[0], templateDataTable[0].TemplateBlob, i + 1, templatePageIndex);
fileStamp.AddStamp(templateStamp);
}
}
}
else
{
for (int i = 1; i <= doc.Pages.Count; i++)
{
if (templateDataTable.Count >= i)
{
using (var fileStamp = new PdfFileStamp())
{
var templateStamp = AsposeImplementation.GetImageStamp(templateDataTable[0], doc.Pages[i].PageInfo, templateDataTable[i - 1].TemplateBlob);
fileStamp.AddStamp(templateStamp);
}
}
}
}
using (var stamperStream = new MemoryStream())
{
doc.Save(stamperStream);
return stamperStream.ToArray();
}
}
else
{
transformedDocument = document;
}
}
return transformedDocument;
}
}
}
and for the helper functions
public static Aspose.Pdf.Document DocumentFromBytes(byte[] documentFromBytes)
{
LoadAsposeLicense();
if (documentFromBytes == null || documentFromBytes.Length == 0)
{
var doc = new Aspose.Pdf.Document();
doc.Pages.Insert(1);
return doc;
}
using (var asposeDocumentStream = new MemoryStream(documentFromBytes))
{
var doc = new Aspose.Pdf.Document(asposeDocumentStream);
return doc;
}
}
/// <summary>
/// Gets the image stamp.
/// </summary>
/// <param name="dataTemplateRow">The row from which to get the template settings.</param>
/// <param name="page">The page informations on which to stamp the image.</param>
/// <param name="imageBytes">The actual image on which to stamp</param>
/// <param name="isBackGround"></param>
/// <returns>Stamp object with the corresponding image and dimensions defined by the target page.</returns>
public static Aspose.Pdf.Facades.Stamp GetImageStamp(DsDocumentTemplate.TTemplateDataRow dataTemplateRow, PageInfo pageInfo, byte[] imageBytes, bool isBackGround = true)
{
LoadAsposeLicense();
// Scale image with the page size
var image = new MagickImage(imageBytes);
image.Scale((int)pageInfo.Width, (int)pageInfo.Height);
using (var imageStream = new MemoryStream(image.ToByteArray()))
{
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindImage(imageStream);
stamp.SetOrigin(dataTemplateRow.OffsetXNullable(), dataTemplateRow.OffsetYNullable());
stamp.IsBackground = isBackGround;
return stamp;
}
}
public static Aspose.Pdf.Facades.Stamp GetPDFStamp(DsDocumentTemplate.TTemplateDataRow templateDataRow, byte[] templatePdf, int pageToStampOn, int pageToBeStamped)
{
using(var stampStream = new MemoryStream(templatePdf))
{
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindPdf(stampStream, pageToBeStamped);
stamp.IsBackground = true;
stamp.SetOrigin(templateDataRow.OffsetXNullable(),templateDataRow.OffsetYNullable());
stamp.Pages = new[] {pageToStampOn };
//new PdfPageStamp(pageStamp)
//{
// Background = true,
// Height = targetPageInfo.Height,
// Width = targetPageInfo.Width,
// XIndent = templateDataRow.OffsetXNullable(),
// YIndent = templateDataRow.OffsetYNullable()
//};
return stamp;
}
}
Where for the helper functions I followed the official documentation. As of updating to 24.4 version we are not quite fond of it, because we figured out, that the (not sure if the Pdf or the Word lib was the problem) library had problems with managing byte arrays from Image Magick .NET and so we decided that first we upgrade the IM library and then resolve all other libraries. Also one question. Do you have any support available in the GMT or CEST time zones? Kind regards, Aleksander Kovač
So the error that you posted in your first post is occurring in case of PDF document being used as stamp? In case you cannot immediately update the API version, you can try a 30-days free temporary license and test using 24.4 version in a separate sample project whether issue is resolved by using it or not. Furthermore, please share some steps for our reference to help us in reproducing the issue so that we can address it accordingly.
No time zone is specified for providing support in our forums. We provide it 24/7. However, we reply and communicate on first come first serve basis and reply time from us can vary depending upon the other issues reported before yours.
Ok, i tried to upgrade to the latest version, but the dependency Newtonsoft.Json 13.0.3 does not contain any assembly references that are compatible with .net 4.8 which is currently needed, also I get multiple errors regarding package incompatibility when coupling it with other projects.
EDIT:
Using this snippet it now works on 24.3.0, but for the image part I wonder if this can be simplified or used with multiple functions. I can’t help but wonder why can’t wrap some parts into methods. I’ll post the solution to my PDF stamping with a PDF later.
public static byte[] GetImageStamp(TemplateDataDataTable templateDataTable, byte[] sourceDocument)
{
LoadAsposeLicense();
if (sourceDocument is null || sourceDocument.Length.Equals(0))
sourceDocument = CreateEmptyDocument(templateDataTable);
using (var stream = new MemoryStream(sourceDocument))
{
var doc = new Aspose.Pdf.Document(stream);
for(var i = 1; i <= doc.Pages.Count; i++)
{
if(templateDataTable.Count >= i)
{
using (var imageStream = new MemoryStream(templateDataTable[i - 1].TemplateBlob))
{
var stamp = new ImageStamp(imageStream)
{
// set desired stamp settings
};
doc.Pages[i].AddStamp(stamp);
}
}
}
using(var stampedDocument = new MemoryStream())
{
doc.Save(stampedDocument);
return stampedDocument.ToArray();
}
}
}
Hi!
I having issues, when the stream was open an the Aspose objects were passed to another variables. Newertheless I was able to arhive my goal with 23.6.0
The code for both stamping the PDF with the images and other PDF is the following:
public static byte[] MakeImageStamp(Data templateDataTable, byte[] sourceDocument)
{
LoadAsposeLicense();
using (var stream = new MemoryStream(sourceDocument))
{
var doc = new Aspose.Pdf.Document(stream);
var fileStamp = new PdfFileStamp();
fileStamp.BindPdf(doc);
for (var i = 1; i <= doc.Pages.Count; i++)
{
if(templateDataTable.Count >= i)
{
var imagetemplateContent = new MagickImage(templateDataTable[i - 1].TemplateBlob);
var size = new MagickGeometry((int)doc.Pages[i].PageInfo.Width, (int)doc.Pages[i].PageInfo.Height)
{
IgnoreAspectRatio = true
};
imagetemplateContent.Resize(size);
using (var imageStream = new MemoryStream(imagetemplateContent.ToByteArray()))
{
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindImage(imageStream);
stamp.SetOrigin(templateDataTable[i-1].OffsetXNullable(), templateDataTable[i-1].OffsetYNullable());
stamp.IsBackground = true;
stamp.Pages = new int[] { i };
fileStamp.AddStamp(stamp);
}
}
}
using(var stampedDocument = new MemoryStream())
{
doc.Save(stampedDocument);
fileStamp.Close();
return stampedDocument.ToArray();
}
}
}
and
public static byte[] MakePDFStamp(Data templateDataTable, byte[] sourceDocument)
{
LoadAsposeLicense();
byte[] tempArray = null;
using(var templateDocumentStream = new MemoryStream(templateDataTable[0].TemplateBlob))
{
var templateDocument = new Aspose.Pdf.Document(templateDocumentStream);
using(var sourceDocumentStream = new MemoryStream(sourceDocument))
{
var doc = new Aspose.Pdf.Document(sourceDocumentStream);
var fileStamp = new PdfFileStamp();
fileStamp.BindPdf(doc);
for (int i = 1; i <= doc.Pages.Count; i++)
{
int pageIndex = i;
if (pageIndex > templateDocument.Pages.Count)
pageIndex = templateDocument.Pages.Count;
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindPdf(templateDocumentStream, pageIndex);
stamp.SetOrigin(templateDataTable[pageIndex-1].OffsetXNullable(), templateDataTable[pageIndex-1].OffsetYNullable());
stamp.IsBackground = true;
stamp.Pages = new[] { i };
fileStamp.AddStamp(stamp);
}
using (var documentSavingStream = new MemoryStream())
{
doc.Save(documentSavingStream);
tempArray = documentSavingStream.ToArray();
fileStamp.Close();
}
}
}
return tempArray;
}
Aspose.PDF does not free any resource until the opened document is closed or saved. Which is why you may be facing some issues like that. Nevertheless, it is nice to know that you are able to sort this out. Please feel free to create a new topic in case you face any other issues.