我正在使用PDFTron,它可以很好地和花花公子来处理PDF格式的东西。我用xamarin制作了一个应用程序,人们开放了很多pdf来签名。这样也可以。
然而,当一个人放大和缩小时,问题就开始了。然后记忆突然开始填满。放大几个文档后应用程序崩溃..
任何人都知道发生了什么?
这是所有魔法发生的活动:
private PDFViewCtrl _mPdfViewCtrl;
SetupViewer(filePath);
public override void OnBackPressed()
{
base.OnBackPressed();
_syncManager = null;
DisposePdfCtrl();
Finish();
}
_mPdfViewCtrl.Doc.Save(filePath, 0);
private void SetupViewer(string filePath)
{
try
{
PDFNet.SetDefaultDiskCachingEnabled(true);
PDFNet.SetViewerCache(100 * 1024 * 1024, false);
}
catch (pdftron.Common.PDFNetException ex)
{
Logger.log(Title, "Failed to setup viewer");
}
try
{
Logger.log(Title, $"Setting up pdf viewer");
SetContentView(Resource.Layout.PdfView);
var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
SupportActionBar.Title = "Sign Document";
Logger.log(Title, $"Toolbar is setup.");
_mPdfViewCtrl = FindViewById<PDFViewCtrl>(Resource.Id.pdfviewctrl);
_mPdfViewCtrl.PagePresentationMode = PDFViewCtrl.PagePresentationModes.e_single_page;
_mPdfViewCtrl.PageViewMode = PDFViewCtrl.PageViewModes.e_fit_page;
_mPdfViewCtrl.PageRefViewMode = PDFViewCtrl.PageViewModes.e_fit_page;
_mPdfViewCtrl.SetHighlightFields(true);
Logger.log(Title, $"Opening file in viewer: {filePath}");
var docToOpen = new PDFDoc(filePath);
docToOpen.InitStdSecurityHandler("");
if (!_allowChange)
{
docToOpen.FlattenAnnotations();
}
Logger.log(Title, "setting file to pdf viewer");
_mPdfViewCtrl.Doc = docToOpen;
var toolManager = new ToolManager(_mPdfViewCtrl);
Logger.log(Title, "setting file to pdf viewer");
_mPdfViewCtrl.ToolManager = toolManager;
}
catch (Exception ex)
{
Logger.log(Title, $"Error while setting up pdf view: {ex.Message}");
}
}
protected override void OnPause()
{
base.OnPause();
DisposePdfCtrl();
}
protected override async void OnResume()
{
base.OnResume();
try
{
if (!_busy)
{
_mPdfViewCtrl?.Resume();
}
}
catch (ObjectDisposedException)
{
SetupViewer(filePath);
}
}
protected override void OnDestroy()
{
base.OnDestroy();
DisposePdfCtrl();
}
bool disposed = false;
private void DisposePdfCtrl()
{
if (_disposing)
return;
_disposing = true;
if (disposed) return;
try
{
var oldTool = _mPdfViewCtrl.ToolManager;
var oldDoc = _mPdfViewCtrl.Doc;
_mPdfViewCtrl.Doc.Unlock();
_mPdfViewCtrl?.PurgeMemory();
_mPdfViewCtrl?.CloseDoc();
_mPdfViewCtrl?.CloseTool();
oldDoc?.Dispose();
oldTool?.Dispose();
_mPdfViewCtrl?.Dispose();
_mPdfViewCtrl = null;
_syncManager = null;
GC.Collect();
this.Dispose();
} catch (Exception ex)
{
}
disposed = true;
_disposing = false;
}
public override void OnLowMemory()
{
base.OnLowMemory();
Logger.log(Title, "Low on memory");
_mPdfViewCtrl?.PurgeMemory();
}