We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Local link not working if link and link location are on different pages - only in 11.5.0

Hi,


Part of our PDF generation process uses xslt and xml data. We are finding that we have issues when the PDF that this generates contains local links that point to other pages within the document (rather than the same page the link is on).

Using version 11.5.0 this results in an Object reference not set to an instance of an object exception.

Note this all worked fine in versions prior to 11.5.0 (e.g 11.4.0 and 9.4.0 - 9.4.0 was the original version we were using until we decided to upgrade recently).

I have created a small test example that is just a link to some text that is on another page to show the problem. The error occurs during converting the Aspose.Pdf.Generator.Pdf to a Aspose.Pdf.Document.Document and then adding those pages to an in-progress document.
i.e.:
using (var contentDocument = new Document(pdf))
{
outputDocument.Pages.Add(contentDocument.Pages); // Error thrown here
contentPages = contentDocument.Pages.Count;
}
The full test code to show this issue is below. If you force the Footnote link and Footnote text to be on the same page (e.g. change it to be in the 1 Section) then there is no error.
Note that in our actual code the link and text are all in the same Section and it is just the content that is pushing them to different pages.
public void FootnoteErrorExample()
{
var license = new License();
license.SetLicense(“Aspose.Pdf.lic”);
<span style="color:blue;">var</span> dummyXml = <span style="color:#a31515;">"<DummyData></DummyData>"</span>;
<span style="color:blue;">var</span> xslt = <span style="color:maroon;">@"<?xml version='1.0' encoding='utf-8'?>
                    <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
                      <xsl:template match='/'>
                        <Pdf xmlns='Aspose.Pdf'>
                            <Section>
                                <Text>
                                    <Segment LinkType='Local'>
                                        <xsl:attribute name='TargetID'>
                                            <xsl:text>test-footnote-link</xsl:text>
                                        </xsl:attribute>
                                        Footnote link
                                    </Segment>
                                </Text>
                            </Section>
                            <Section>
                                <Text>
                                    <Segment>
                                        <xsl:attribute name='Id'>
                                            <xsl:text>test-footnote-link</xsl:text>
                                        </xsl:attribute>
                                        Footnote text
                                    </Segment>
                                </Text>
                            </Section>
                         </Pdf>
                      </xsl:template>
                    </xsl:stylesheet>"</span>;

<span style="color:blue;">try</span>
{
    <span style="color:blue;">var</span> outputDocument = <span style="color:blue;">new</span> <span style="color:darkblue;">Document</span>();

    <span style="color:blue;">var</span> pdf = <span style="color:blue;">new</span> <span style="color:darkblue;">Pdf</span>();
    pdf.<span style="color:darkcyan;">BindXML</span>(<span style="color:darkcyan;">GenerateStreamFromString</span>(dummyXml), <span style="color:darkcyan;">GenerateStreamFromString</span>(xslt));
    pdf.<span style="color:darkcyan;">Save</span>(<span style="color:maroon;">@"D:\temp\generated.pdf"</span>);

    <span style="color:blue;">var</span> contentPages = 0;
    <span style="color:blue;">using</span> (<span style="color:blue;">var</span> contentDocument = <span style="color:blue;">new</span> <span style="color:darkblue;">Document</span>(pdf))
    {
        outputDocument.<span style="color:purple;">Pages</span>.<span style="color:darkcyan;">Add</span>(contentDocument.<span style="color:purple;">Pages</span>);
        contentPages = contentDocument.<span style="color:purple;">Pages</span>.<span style="color:purple;">Count</span>;
    }
}
<span style="color:blue;">catch</span> (<span style="color:darkblue;">Exception</span> e)
{
    <span style="color:darkblue;">Assert</span>.<span style="color:darkcyan;">Fail</span>(e.<span style="color:purple;">Message</span>);
}

}

private Stream GenerateStreamFromString(string value)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(value);
writer.Flush();
stream.Position = 0;
return stream;
}


Hi Chris,


Thanks for your inquriy. Please note we have introduced new XSD schema of Aspose.Pdf(new generator), so we will appreciate it if you please change your xml and xslt as per new schema and use following code snippet for the conversion. Hopefully it will help you to resolve the issue.

Document doc = new
Document();<o:p></o:p>

doc.BindXml(myDir + "sample.xml","sample.xsl");

doc.Save(myDir + "testxml.pdf");


Best Regards,

The new XSD has too much missing compared to the older one used in Aspose.Pdf.Generator. e.g.:

  • MarginTop/Bottom/Left/Right for Text and Segments (TextFragment and TextSegment in the new XSD)
  • IsKeptWithNext for Text (TextFragment in the new XSD)
  • Can’t see anyway to create bulleted lists that aren’t numbered lists - used to use UserLabel on a Heading element
  • No TargetId and Id for Segments so can’t link to them in the PDF
  • plus others


Regardless of what XML/XSLT generator is used there still seems to be a fundamental issue with Aspose 11.5.0 that causes it to fail when loading a PDF with hyperlinks across pages.


The following code loading the Test.pdf attached crashes at outputDocument.Pages.Add(contentDocument.Pages); attached ConvertedTest.pdf is blank.
In Test.pdf the Footnote link is a link to the 2nd page to Footnote text.

This worked fine in 11.4.0 and earlier.
using (var outputDocument = new Document())
{
try
{
using (var contentDocument = new Document(@“D:\temp\Test.pdf”))
{
contentDocument.Save(@“D:\temp\ConvertedTest.pdf”); // This ends up as a blank PDF
outputDocument.Pages.Add(contentDocument.Pages); // Crashes here
}
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}


Hi Chris,

ckling:
Regardless of what XML/XSLT generator is used there still seems to be a fundamental issue with Aspose 11.5.0 that causes it to fail when loading a PDF with hyperlinks across pages.

The following code loading the Test.pdf attached crashes at outputDocument.Pages.Add(contentDocument.Pages); attached ConvertedTest.pdf is blank.
In Test.pdf the Footnote link is a link to the 2nd page to Footnote text.

This worked fine in 11.4.0 and earlier.
using (var outputDocument = new Document())
 {
     try
     {
         using (var contentDocument = new Document(@"D:\temp\Test.pdf"))
         {
             contentDocument.Save(@"D:\temp\ConvertedTest.pdf");   // This ends up as a blank PDF
             outputDocument.Pages.Add(contentDocument.Pages);      // Crashes here
         }
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }



Thanks for sharing your findings. I have tested your scenario with shared document using Aspose.Pdf for .NET 11.5.0 and managed to observe the reported issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWNET-40623 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

We are sorry for the inconvenience caused.

Best Regards,

Hi Chris,

ckling:
The new XSD has too much missing compared to the older one used in Aspose.Pdf.Generator. e.g.:
  • MarginTop/Bottom/Left/Right for Text and Segments (TextFragment and TextSegment in the new XSD)
  • IsKeptWithNext for Text (TextFragment in the new XSD)
  • Can't see anyway to create bulleted lists that aren't numbered lists - used to use UserLabel on a Heading element
  • No TargetId and Id for Segments so can't link to them in the PDF
  • plus others



Thanks for feedback. We have logged an enhancement ticket PDFNEWNET-40624 in our issue tracking system. Our product team will investigate it and will rectify accordingly. We will keep you updated about the issue resolution progress in this forum thread.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-40623) have been fixed in Aspose.Pdf for .NET 11.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Thanks. We have downloaded the new version and this is working great now.


Cheers
Chris

Hi Chris,


Thanks for your feedback. It is good to know that you have managed to resolve the issue(PDFNEWNET-40623) with latest release.

Please feel free to contact us for any further query or concern, we will be more than happy to extend our support.

Best Regards,