Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new button for attach scanned PDF to Lotus Notes document #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAPS2.Core/NAPS2.Core.csproj
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="MimeKit, Version=1.22.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814, processorArchitecture=MSIL">
<HintPath>..\packages\MimeKit.1.22.0\lib\net40\MimeKit.dll</HintPath>
</Reference>
157 changes: 91 additions & 66 deletions NAPS2.Core/WinForms/FDesktop.Designer.cs

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion NAPS2.Core/WinForms/FDesktop.cs
Original file line number Diff line number Diff line change
@@ -693,7 +693,7 @@ private void UpdateToolbar()
// "All" dropdown items
tsSavePDFAll.Text = tsSaveImagesAll.Text = tsEmailPDFAll.Text = tsReverseAll.Text =
string.Format(MiscResources.AllCount, imageList.Images.Count);
tsSavePDFAll.Enabled = tsSaveImagesAll.Enabled = tsEmailPDFAll.Enabled = tsReverseAll.Enabled =
tsSavePDFAll.Enabled = tsSaveImagesAll.Enabled = tsEmailPDFAll.Enabled = tsReverseAll.Enabled = tsSendLN.Enabled =
imageList.Images.Any();

// "Selected" dropdown items
@@ -1022,6 +1022,18 @@ private void ImportDirect(DirectImageTransfer data, bool copy)
}
}

private async void Send2LN(List<ScannedImage> images)
{
if (await exportHelper.SendPDF2LN(images))
{
if (appConfigManager.Config.DeleteAfterSaving)
{
imageList.Delete(imageList.Images.IndiciesOf(images));
DeleteThumbnails();
}
}
}

#endregion

#region Keyboard Shortcuts
@@ -1458,6 +1470,11 @@ private void tsEmailSettings_Click(object sender, EventArgs e)
FormFactory.Create<FEmailSettings>().ShowDialog();
}

private void tsSendLn_Click(object sender, EventArgs e)
{
Send2LN(imageList.Images);
}

#endregion

#region Event Handlers - Image Menu
@@ -2080,5 +2097,6 @@ private int GetDragIndex(DragEventArgs e)
}

#endregion

}
}
1,795 changes: 956 additions & 839 deletions NAPS2.Core/WinForms/FDesktop.resx

Large diffs are not rendered by default.

514 changes: 494 additions & 20 deletions NAPS2.Core/WinForms/FDesktop.ru.resx

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions NAPS2.Core/WinForms/WinFormsExportHelper.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using NAPS2.Config;
using NAPS2.ImportExport;
using NAPS2.ImportExport.Email;
using NAPS2.ImportExport.Images;
using NAPS2.ImportExport.Pdf;
using NAPS2.Lang.Resources;
using NAPS2.Logging;
using NAPS2.Ocr;
using NAPS2.Operation;
using NAPS2.Scan.Images;
@@ -177,5 +181,97 @@ public async Task<bool> EmailPDF(List<ScannedImage> images)
}
return false;
}

public async Task<bool> SendPDF2LN(List<ScannedImage> images)
{
if (!images.Any())
{
// return false;
}

var tempFolder = new DirectoryInfo(Path.Combine(Paths.Temp, Path.GetRandomFileName()));
var emailSettings = emailSettingsContainer.EmailSettings;
var invalidChars = new HashSet<char>(Path.GetInvalidFileNameChars());
var attachmentName = new string(emailSettings.AttachmentName.Where(x => !invalidChars.Contains(x)).ToArray());
if (string.IsNullOrEmpty(attachmentName))
{
attachmentName = "Scan.pdf";
}
if (!attachmentName.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase))
{
attachmentName += ".pdf";
}
attachmentName = fileNamePlaceholders.SubstitutePlaceholders(attachmentName, DateTime.Now, false);
tempFolder.Create();

Object ws, uidoc, doc, rtf, embObj;
try
{
var changeToken = changeTracker.State;
string targetPath = Path.Combine(tempFolder.FullName, attachmentName);
string pdfFileSaved = await ExportPDF(targetPath, images, false, null);
if (pdfFileSaved != null)
{
// instantiate a Notes session and workspace
//Type NotesSession = Type.GetTypeFromProgID("Notes.NotesSession");
//Object sess = Activator.CreateInstance(NotesSession);
Type NotesUIWorkspace = Type.GetTypeFromProgID("Notes.NotesUIWorkspace");
if (NotesUIWorkspace == null) throw new NullReferenceException("Not found Notes.NotesUIWorkspace");
ws = Activator.CreateInstance(NotesUIWorkspace);
if (ws == null) throw new NullReferenceException("Not found Notes.NotesUIWorkspace");
uidoc = NotesUIWorkspace.InvokeMember("EditDocument", BindingFlags.InvokeMethod, null, ws, new Object[] { true });
if (uidoc == null) throw new NullReferenceException("Not found opened document in Notes.NotesUIWorkspace");

Type NotesUIDocument = uidoc.GetType();
doc = NotesUIDocument.InvokeMember("Document", BindingFlags.GetProperty, null, uidoc, null);
Type NotesDocument = doc.GetType();

/* rtf = NotesDocument.InvokeMember("GetFirstItem", BindingFlags.InvokeMethod, null, doc, new Object[] { "Body" });
Type NotesRichTextItem = rtf.GetType();
*/
// bring the Notes window to the front
String windowTitle = (String)NotesUIDocument.InvokeMember("WindowTitle", BindingFlags.GetProperty, null, uidoc, null);
Interaction.AppActivate(windowTitle);

/* embObj = NotesRichTextItem.InvokeMember("EmbedObject", BindingFlags.InvokeMethod, null, rtf, new Object[] { 1454, "", "d:\\Download\\scan17_33_39.pdf" });
bool resSave = (bool)NotesDocument.InvokeMember("Save", BindingFlags.InvokeMethod, null, doc, new Object[] { true, true });
if (resSave)
{
changeTracker.Saved(changeToken);
return true;
}
*/

StringCollection paths = new StringCollection();
paths.Add(@pdfFileSaved);
Clipboard.SetFileDropList(paths);

NotesUIDocument.InvokeMember("GotoField", BindingFlags.InvokeMethod, null, uidoc, new Object[] { "Body" });
NotesUIDocument.InvokeMember("Paste", BindingFlags.InvokeMethod, null, uidoc, null);

changeTracker.Saved(changeToken);
return true;


}

}
catch (Exception ex)
{
Log.ErrorException(MiscResources.ErrorSaving, ex);
MessageBox.Show(ex.Message);
}
finally
{
tempFolder.Delete(true);
uidoc = null;
//sess = null;
ws = null;
}

return false;

}

}
}
4 changes: 2 additions & 2 deletions NAPS2/appsettings.xml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
<AlwaysRememberDevice>false</AlwaysRememberDevice>
<DisableGenericPdfImport>false</DisableGenericPdfImport>
<NoUpdatePrompt>false</NoUpdatePrompt>
<DeleteAfterSaving>false</DeleteAfterSaving>
<DeleteAfterSaving>true</DeleteAfterSaving>
<DisableSaveNotifications>false</DisableSaveNotifications>
<SingleInstance>false</SingleInstance>
<ComponentsPath></ComponentsPath>
@@ -52,7 +52,7 @@
</CustomPageSize>
-->
<PageAlign>Right</PageAlign>
<Resolution>Dpi100</Resolution>
<Resolution>Dpi200</Resolution>
<AfterScanScale>OneToOne</AfterScanScale>
<Brightness>0</Brightness>
<Contrast>0</Contrast>
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# NAPS2 (Not Another PDF Scanner 2)

NAPS2 is a document scanning application with a focus on simplicity and ease of use. Scan your documents from WIA- and TWAIN-compatible scanners, organize the pages as you like, and save them as PDF, TIFF, JPEG, PNG, and other file formats. Requires .NET Framework 4.0 or higher.
This fork NAPS2 lets sending PDF document to Lotus Notes with only a couple clicks.
Added button "Send to LN"
The "Send to LN" button allows you to attach a scanned PDF file to a previously opened Lotus Notes document with one click. Requires installed Lotus Notes client.
Attachment name set from choosing "Email Settings". If you'd like images to be deleted after they're sended to LN to avoid accidental duplication, use the DeleteAfterSaving element in appsettings.xml.

Visit the NAPS2 home page at [www.naps2.com](http://www.naps2.com).
For additional information visit the NAPS2 home page at [www.naps2.com](http://www.naps2.com).

Other links:
- [Documentation](http://www.naps2.com/support.html)