Just-in-time Debugger when export thumbnail from multiple PDF files

Hello,

I developing for Universal App (Windows Store and Windows Phone)
I have about 10 PDF files in local storage, each PDF file only have 1 page
Use a loop through 10 files to export 10 thumbnail picture of it, synchronously. But the “Just in time Debugger” window appears, and the app crash

Here’s the code

`

var temp = await StaticData.issueFolder.GetFilesAsync();

using (PDFDraw draw = new PDFDraw())
{
PDFDoc doc;
draw.SetDPI(48);
foreach (var page in PDFPageList)
{
string fileName = page.file;
fileName = fileName.Substring(fileName.LastIndexOf(’/’) + 1);
var tempFile = await StaticData.issueFolder.GetFileAsync(fileName);

IRandomAccessStream stream = await tempFile.OpenAsync(FileAccessMode.Read);
doc = new PDFDoc(stream);
if (!doc.InitStdSecurityHandler(StaticData.password))
{
//StatusTextBlock.Text = "Incorrect Password: " + StaticData.password;
}

// C) Rasterize the first page in the document and save the result as PNG.
var pg = doc.GetPage(1);
//draw.Export(pg, StaticData.issueFolder.Path + “\” + fileName.Split(’.’)[0] + “.png”);
//TODO: fix the bug here
WriteableBitmap wb = await draw.GetBitmapAsync(pg);
}
}

`

Thanks in advanced

Does the PDFDrawTest sample work for you?

Does the error happen on any file? or one in particular?

What is the exact error that you get?

The code looks fine, but I recommend you use a “using” statement for PDFDoc object, otherwise files can remain locked after you expect them to be released. Or at least call doc.Dispose() when you are done.

using(PDFDoc doc = new PDFDoc(stream))

Hello Ryan,

Thank you for helping me with this

This is the only details I can get

Unhandled exception at 0x1122ADA2 (PDFNetUniversalApps.Windows.dll) in TestMultiPDF.Windows.exe: 0xC0000005: Access violation reading location 0x00000158.

The sample worked fine. This bug happen on any file.

One strange thing is that this bug will occurred on the 3rd or 4th file of any list.
For example, i have 0.pdf, 1.pdf, 2.pdf, …, 10.pdf. The bug will hit on 2.pdf or 3.pdf. If I delete the 0.pdf, the bug will hit at 3.pdf or 4.pdf. So it’s not the file specific.

I apply the using technique and also try to call doc.Dispose after use but no luck.

Hi there,

I tried to replicate your code as best I could. I got the following:

StorageFolder folder = await Package.Current.InstalledLocation.GetFolderAsync(“FilesForDraw”);
string outpath = ApplicationData.Current.TemporaryFolder.Path;
if (folder != null)
{

IReadOnlyList files = await folder.GetFilesAsync();
if (files != null && files.Count > 0)
using (PDFDraw draw = new PDFDraw())
{
PDFDoc doc;
draw.SetDPI(48);
int i = 0;
foreach (StorageFile file in files)
{
i++;
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
doc = new PDFDoc(stream);
if (!doc.InitStdSecurityHandler(""))
{
//StatusTextBlock.Text = "Incorrect Password: " + StaticData.password;
}

// C) Rasterize the first page in the document and save the result as PNG.
var pg = doc.GetPage(1);
System.Diagnostics.Debug.WriteLine(“Starting with thumb #” + i);
draw.Export(pg, outpath + “\” + file.DisplayName + “.png”);
//TODO: fix the bug here

Windows.UI.Xaml.Media.Imaging.WriteableBitmap wb = await draw.GetBitmapAsync(pg);
//System.Diagnostics.Debug.WriteLine(“finished with thumb #” + i);
}
}
}

This seems to be working just fine for me.
Could you confirm that you are using the latest version (6.3.2). If this is still the case, we would need some sample we can run to reproduce it. If you can modify the PDFDraw sample to cause these problems, that would be very helpful.

Best Regards,
Tomas Hofmann

Hello Tomas Hofmann,

I confirmed that I’m using the latest version.

Finally I figured it out. It turn out that I didn’t initialize the PDFNet library with the license I have.

The fix is really simple. Add this line of code to page Constructor

`
PDFNet.Initialize(“your license key”);

`

As a result, if you didn’t do that, on every single thumbnail will have a blue transparent “DEMO” text, which is very difficult to see at 48 DPI. And you only can export about 3 thumbnail before the app crash.

This should be noted in the official document.

Hi,

Could you clarify. Did you not call PDFNet.Initialize at all, or did you call it with a blank string or nothing?
Not calling it at all is a problem, which calling it without a license key should have made the app run fine, but with demo stamps.

Best Regards,
Tomas Hofmann

Hello Tomas,

I’m not calling PDFNet.Initialize at all, and surprisingly, it run fine. It can render the PDF on screen, zoom in or zoom out, even click on the link and email on the PDF pages. The only feature that doesn’t work so far is export thumbnail images. Maybe it’s a bug on how the SDK deals with demo restrictions.

I try to call it without the license key, the “DEMO” stamp placed on every thumbnail as expected.

And calling it with license key and everything is okay.