Issue re-opening a PDF document too quickly.

69 views
Skip to first unread message

Steve McCoole

unread,
Aug 31, 2017, 12:40:04 PM8/31/17
to PDFTron PDFNet SDK
Hi all,

I'm trying to create a react native wrapper for PDFNet and have run into an issue on UWP. If I try to reopen the same PDF document quickly I am getting an access exception when I try to create the stream to pass to the PDFDoc() constructor. When the component unmounts, I am trying to close and clean up the PDFDoc and PDFViewCtrl as completely as possible. It definitely seems to be timing related as delays will always allow it to succeed. I'm wondering if there is something that is in PdfViewCtrl.closeDoc() or PDFDoc.Dispose that is holding the stream for just long enough to be an issue?

Code is shown below. I'm aware that I don't have error handling in the code yet. That will be added but right now I'm just trying to figure out the basics of integrating it with React Native. Any ideas how I might be able to avoid the issue? Thanks!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using ReactNative.UIManager;
using ReactNative.UIManager.Annotations;
using pdftron.PDF;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media;

namespace Com.ObjectPartners.OPIPdfNet
{
public class OPIPdfNetViewManager : SimpleViewManager<Border>
{
public override string Name => "OPIPdfNet";

public OPIPdfNetViewManager() : base() => pdftron.PDFNet.Initialize();

public override void OnDropViewInstance(ThemedReactContext reactContext, Border view)
{
base.OnDropViewInstance(reactContext, view);
PDFViewCtrl pdfView = (PDFViewCtrl)view.Child;
PDFDoc doc = pdfView.GetDoc();
pdfView.CloseDoc();
doc.Dispose();
pdfView.FreeResources();
}

protected override Border CreateViewInstance(ThemedReactContext reactContext) => new Border
{
Background = new SolidColorBrush(Colors.Green),
Child = new PDFViewCtrl()
};

[ReactProp("src")]
public async void SetSourceAsync(Border view, string source)
{

StorageFile file = await StorageFile.GetFileFromPathAsync(source);

// Create a PDFDocument and use it as the source for the PDFViewCtrl
if (file != null)
{
Windows.Storage.Streams.IRandomAccessStream stream = await
file.OpenAsync(FileAccessMode.ReadWrite);
PDFDoc doc = new PDFDoc(stream);
PDFViewCtrl pdfView = (PDFViewCtrl)view.Child;
pdfView.SetDoc(doc);
}

}
}
}

Shakthi Wijeratne

unread,
Sep 1, 2017, 2:27:18 PM9/1/17
to PDFTron PDFNet SDK
Hi Steve,

Your code looks good. Can you reproduce this issue with our sample code? Or does this only happen in your project?

Shakthi,

Steve McCoole

unread,
Sep 6, 2017, 4:31:31 PM9/6/17
to PDFTron PDFNet SDK
Thanks Shakthi, I can't really reproduce the problem with the sample code because I have to go through the dialog box to reopen the file and it takes enough time that I am not able to cause the issue to happen.  My code above is being used along with a grid of icons for the PDF documents so I can close and re-open the file rapidly.  I did find if I skip straight to passing the StorageFile reference to the PDFDoc() constructor it makes the issue impossible to reproduce on my code as well.  Maybe that helps shed some light on what might be going on?

Thanks,
Steve

Ryan

unread,
Sep 6, 2017, 7:52:30 PM9/6/17
to PDFTron PDFNet SDK
So you don't get the issue if you use the StorageFile object directly with the PDFDoc constructor?

PDFDoc(StorageFile)

And that the issue occurs with

PDFDoc(IRandomAccessStream)

If so, does anything prevent you from using the former? 

Steve McCoole

unread,
Sep 11, 2017, 12:28:44 PM9/11/17
to PDFTron PDFNet SDK on behalf of Ryan
Yes, that's right.  I don't see the issue when using the constructor with the StorageFile directly.  There's nothing that stops me from using it since the files are local on the device.  I had just not found that signature and tried it out before I posted initially.  I had just gotten it switched and tested a few hours before I read your post and replied.  Thanks!

--
You received this message because you are subscribed to the "PDFTron PDFNet SDK" group (http://www.pdftron.com/pdfnet/forum.html).
---
You received this message because you are subscribed to a topic in the Google Groups "PDFTron PDFNet SDK" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pdfnet-sdk/WW_agVFUMjI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pdfnet-sdk+unsubscribe@googlegroups.com.
To post to this group, send email to pdfne...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve McCoole, Principal Technologist Mobile Development
Object Partners Inc.  www.objectpartners.com

Reply all
Reply to author
Forward
0 new messages