logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
mukesh  
#1 Posted : Thursday, July 14, 2016 1:14:03 PM(UTC)
mukesh

Rank: Member

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 20
United States

Thanks: 4 times
I load a pdf document through pdfToolbarMain's load button in WPF C# app.

When I try to close it on a click of a close button

pdfViewer1.CloseDocument();

, it throws an error saying "KeyNotFoundException was unhandled", "An unhandled exception of type 'System.Collection.Generic.KeyNotFoundException occured in mscorelib.dll

Stack trace shows this

at Patagames.Pdf.Pdfium.FPDFDOC_ExitFormFillEnvironment_native(IntPtr form_handle)
at Patagames.Pdf.Pdfium.FPDFDOC_ExitFormFillEnvironment(IntPtr form_handle)
at Patagames.Pdf.Net.PdfForms.Dispose(Boolean disposing)
at Patagames.Pdf.Net.PdfForms.Dispose()
at Patagames.Pdf.Net.PdfDocument.Dispose(Boolean disposing)
at Patagames.Pdf.Net.PdfDocument.Dispose()
at Patagames.Pdf.Net.Controls.Wpf.PdfViewer.CloseDocument()
at WPF_PDFium_NUGET.MainWindow.BtnClose_Click(Object sender, RoutedEventArgs e) in c:\DEV\Prototypes\PDF\WPF_PDFium_NUGET\WPF_PDFium_NUGET\MainWindow.xaml.cs:line 87
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at WPF_PDFium_NUGET.App.Main() in c:\DEV\Prototypes\PDF\WPF_PDFium_NUGET\WPF_PDFium_NUGET\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Paul Rayman  
#2 Posted : Thursday, July 14, 2016 4:27:24 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Could you please provide sample project where this issue can be reproduced?
mukesh  
#3 Posted : Friday, July 15, 2016 12:20:49 AM(UTC)
mukesh

Rank: Member

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 20
United States

Thanks: 4 times
BtnClose_Click function has this line pdfViewer1.CloseDocument(); which results in crash every time.

I am also trying to wrap up this evaluation phase of these controls by this weekend. Can you also provide me the code snippets to fill fields in a pdf doc with values and how to extract values of fields in an editable pdf document?


using Patagames.Pdf.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace WPF_PDFium_NUGET
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
protected bool isChanged { get; set; }


public MainWindow()
{
InitializeComponent();
PdfCommon.Initialize();
pdfViewer1.DocumentLoaded += pdfViewer1_DocumentLoaded;
pdfViewer1.FillForms.FieldChanged += FillForms_FieldChanged;
}


void pdfViewer1_DocumentLoaded(object sender, EventArgs e)
{
isChanged = false;


//throw new NotImplementedException();
}


private void btnSave_Click(object sender, RoutedEventArgs e)
{

SaveDocument(false);


}

private void SaveDocument(bool isConfirmFirst)
{

if (isChanged == true)
{
var msgBoxResult = MessageBoxResult.Yes;

if (isConfirmFirst == true)
{
//Save only if the user has changed anything in the form.
msgBoxResult = MessageBox.Show("Save the changes?", "Save Form", MessageBoxButton.YesNo);
}

if (msgBoxResult == MessageBoxResult.Yes)
{
if (pdfViewer1.FillForms.ForceToKillFocus() == true)
{
//User Wants to Save
pdfViewer1.Document.Save("MKSTest.pdf", Patagames.Pdf.Enums.SaveFlags.NoIncremental);
}
}
}
}

private void BtnClose_Click(object sender, RoutedEventArgs e)
{
SaveDocument(true);
pdfViewer1.CloseDocument();

}

void FillForms_FieldChanged(object sender, EventArgs e)
{
isChanged = true;
//throw new NotImplementedException();
}

private void btnTest_Click(object sender, RoutedEventArgs e)
{
//{
// string text=null;

// var asdf = PdfFieldCollections
// f
// foreach (var field in doc.FormFill.InterForm.Fields)
// {
// text += field.ToString();

// }

// MessageBox.Show(text);

//Open and load a PDF document from a file.
using (var doc = PdfDocument.Load("MKSTest.pdf"))

foreach (var page in doc.Pages)
{
//Gets number of characters in a page or -1 for error.
//Generated characters, like additional space characters, new line characters, are also counted.
int totalCharCount = page.Text.CountChars;

//Extract text from page to the string
string text = page.Text.GetText(0, totalCharCount);

//MessageBox.Show(text);
}

//}
}


}
}
mukesh  
#4 Posted : Friday, July 15, 2016 4:43:40 PM(UTC)
mukesh

Rank: Member

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 20
United States

Thanks: 4 times
Can someone please respond to the issue I am experiencing. I didn't assume closing a pdf doc would be much complicated action.

I am under time pressure to evaluate if this toolkit should be purchased by our company to meet the business needs.
Paul Rayman  
#5 Posted : Sunday, July 17, 2016 4:31:38 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
I have tried your code. It works fine for me.
Please note, MKSTest.pdf must point to a new file.
You can't save changes in the same file which already opened in the Viewer.

Could you please provide a full solution with all necessary files (including your source PDF document)?

Edited by user Sunday, July 17, 2016 4:44:17 AM(UTC)  | Reason: Not specified

Paul Rayman  
#6 Posted : Sunday, July 17, 2016 4:49:10 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Originally Posted by: mukesh Go to Quoted Post
Can you also provide me the code snippets to fill fields in a pdf doc with values and how to extract values of fields in an editable pdf document?


Please find the code snippet here: https://forum.patagames....xtracting-data-from-them

Paul Rayman  
#7 Posted : Wednesday, July 20, 2016 7:31:32 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
An issue from first topic was fixed - http://forum.patagames.c...-on-Jul-21--2016#post439
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.