Attaching file to PDF via Access VBA using Adobe SDK - vba

I'm trying to automatically add an attachment to a PDF file through VBA.
From what I can tell it is possible to handle this through FileAttachment annotations.
Dim testAnno As Object
Dim props As Object
Set testAnno = jso.AddAnnot
Set props = testAnno.getProps
props.Type = "FileAttachment"
' Code to attach file to PDF as attachment ......
testAnno.setProps props
I've found the following example in the Adobe documentation so essentially looking for a VBA equivalent to this:
var annot = this.addAnnot({
page: 0
type: "FileAttachment",
point: [400,500],
author: "A. C. Robat",
contents: "Call Smith to get help on this paragraph.",
cAttachmentPath: "/d/a.pdf" ,
});

Related

When creating a Google Sheet with C#, how do I select a folder location?

I have the following code that creates a Google Sheet in my root drive folder:
static void CreateSheet()
{
// Create a new sheet with a single tab
string sheetName = "Test Create Sheet";
var NewSheet = new Google.Apis.Sheets.v4.Data.Spreadsheet();
NewSheet.Properties = new SpreadsheetProperties();
NewSheet.Properties.Title = sheetName;
var newSheet = service.Spreadsheets.Create(NewSheet).Execute();
SpreadsheetId = newSheet.SpreadsheetId;
Sheet = "Sheet1";
}
I cannot seem to find syntax to update the location by folderid.
Is this even an option?
Is this even an option? [Answer:] No
According to the official Google documentation for creating a spreadsheet using the Sheets API:
"There’s no option to create a spreadsheet directly within a specified Drive folder using the Sheets API. By default, the created spreadsheet is saved to the user’s root folder on Drive."
However, there are alternative options to saving a file to a Drive folder provided in the official documentation that will point you in the right direction.

Append to meeting invite body with or without Redemption

We are developing an Outlook VSTO add-in.
Right now I am trying to append some information to a meeting invite the user is in the process of composing. I want the content to appear in the body like what clicking the Teams-meeting button would do, where formatted text and links are appended to the end of the body.
Since the content is HTML and the Outlook Object Model does not expose an HTMLBody property for AppointmentItems, I try to set it via Redemption:
// Dispose logic left out for clarity but everything except outlookApplication and outlookAppointment is disposed after use
Application outlookApplication = ...;
AppointmentItem outlookAppointment = ...; // taken from the open inspector
NameSpace outlookSession = outlookApplication.Session;
RDOSession redemptionSession = RedemptionLoader.new_RDOSession();
redemptionSession.MAPIOBJECT = outlookSession.MAPIOBJECT;
var rdoAppointment = (RDOAppointmentItem)redemptionSession.GetRDOObjectFromOutlookObject(outlookAppointment);
string newBody = transform(rdoAppointment.HTMLBody); // appends content right before HTML </body> tag
rdoAppointment.BodyFormat = (int)OlBodyFormat.olFormatHTML;
rdoAppointment.HTMLBody = newBody;
Problem
The Outlook inspector window is not updating with the appended content. If I try to run the code again, I can see the appended content in the debugger, but not in Outlook.
Things I have tried:
Saving the RDOAppointmentItem
Also adding the content to Body property
Using SafeAppointmentItem instead of RDOAppointmentItem; didn't work because HTMLBody is a read-only property there
Setting PR_HTML via RDOAppointment.Fields
Paste the HTML via WordEditor (see below)
Attempt to use WordEditor
Per suggestion I also attempted to insert the HTML via WordEditor:
// Dispose logic left out for clarity but everything except inspector is disposed after use
string htmlSnippet = ...;
Clipboard.SetText(htmlSnippet, TextDataFormat.Html);
Inspector inspector = ...;
Document wordDoc = inspector.WordEditor;
Range range = wordDoc.Content;
range.Collapse(WdCollapseDirection.wdCollapseEnd);
object placement = WdOLEPlacement.wdInLine;
object dataType = WdPasteDataType.wdPasteHTML;
range.PasteSpecial(Placement: ref placement, DataType: ref dataType);
... but I simply receive the error System.Runtime.InteropServices.COMException (0x800A1066): Kommandoen lykkedes ikke. (= "Command failed").
Instead of PasteSpecial I also tried using PasteAndFormat:
range.PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);
... but that also gave System.Runtime.InteropServices.COMException (0x800A1066): Kommandoen lykkedes ikke..
What am I doing wrong here?
EDIT: If I use Clipboard.SetText(htmlSnippet, TextDataFormat.Text); and then use plain range.Paste();, the HTML is inserted at the end of the document as intended (but with the HTML elements inserted literally, so not useful). So the general approach seems to be okay, I just can't seem to get Outlook / Word to translate the HTML.
Version info
Outlook 365 MSO 32-bit
Redemption 5.26
Since the appointment is being displayed, work with the Word Object Model - Inspector.WordEditor returns the Document Word object.
Per Dmitrys suggestion, here is a working solution that:
Shows the inserted content in the inspector window.
Handles HTML content correctly with regards to both links and formatting (as long as you stay within the limited capabilities of Words HTML engine).
using System;
using System.IO;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using Word = Microsoft.Office.Interop.Word;
namespace VSTO.AppendHtmlExample
{
public class MyExample
{
public void AppendAsHTMLViaFile(string content)
{
// TODO: Remember to release COM objects range and wordDoc and delete output file in a finally clause
Outlook.Inspector inspector = ...;
string outputFolderPath = ...;
string outputFilePath = Path.Combine(outputFolderPath, "append.html");
Word.Document wordDoc = inspector.WordEditor;
File.WriteAllText(outputFilePath, $"<html><head><meta charset='utf-8'/></head><body>{content}</body></html>", Encoding.UTF8);
Word.Range range = wordDoc.Content;
range.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
object confirmConversions = false;
object link = false;
object attachment = false;
range.InsertFile(fileName,
ConfirmConversions: ref confirmConversions,
Link: ref link,
Attachment: ref attachment);
}
}
}

Get text from PDF in Google

I have a PDF document that is saved in Google Drive. I can use the Google Drive Web UI search to find text in the document.
How can I programmatically extract a portion of the text in the document using Google Apps Script?
See pdfToText() in this gist.
To invoke the OCR built in to Google Drive on a PDF file, e.g. myPDF.pdf, here is what you do:
function myFunction() {
var pdfFile = DriveApp.getFilesByName("myPDF.pdf").next();
var blob = pdfFile.getBlob();
// Get the text from pdf
var filetext = pdfToText( blob, {keepTextfile: false} );
// Now do whatever you want with filetext...
}

How to send saved pdf which exists within a folder using .net mvc 5

I am using Rotativa. MVC to generate a PDF from a view, so I can send an email with the PDF as an attachment. The following code does so:
var p = ControllerContext;
var h = new ViewAsPdf("Index") { FileName = "TestViewAsPdfHm.pdf" };
var hmm = h.BuildPdf(p);
var memStream2 = new SysIO.MemoryStream(hmm);
MailMessage mm = new MailMessage("From#gmail.com", "To#gmail.com");
mm.IsBodyHtml = true;
mm.Attachments.Add(new Attachment(memStream2, "BuildPdfOption.pdf"));
My question is "How do I obtain a PDF file saved i.e. in my MVC application's Content/Pdf folder, from within in c# code, so I can attach it to an email in the same manner?"
I have tried many times with file,stream readers and with HttpContext.Server.MapPath, but without success. Using the MapPath option just had a textual document in the email that I couldn't open.

OCR at OneNote using VBA [duplicate]

I need to do the simple Program whcih need to extract text from image using Onenote Interop? Could any one suggest me the appropriate document for my concept please?
Text recognized by OneNote's OCR is stored in the one:OCRText element in the XML file structure in OneNote. e.g.
<one:Page ...>
...
<one:Image ...>
...
<one:OCRData lang="en-US">
<one:OCRText><![CDATA[This is some sampletext]]></one:OCRText>
</one:OCRData>
</one:Image>
</one:Page>
You can see this XML using a program called OMSPY (it shows you the XML behind OneNote pages) - http://blogs.msdn.com/b/johnguin/archive/2011/07/28/onenote-spy-omspy-for-onenote-2010.aspx
To extract the text you would use the OneNote COM interop (as you pointed out). e.g.
//Instantialize OneNote
ApplicationClass onApp = new ApplicationClass();
//Get the XMl from the selected page
string xml = "";
onApp.GetPageContent("put the page id here", out xml);
//Put it into an XML document (from System.XML.Linq)
XDocument xDoc = XDocument.Parse(xml);
//OneNote's Namespace - for OneNote 2010
XNamespace one = "http://schemas.microsoft.com/office/onenote/2010/onenote";
//Get all the OCRText from the page
string[] OCRText = xDoc.Descendants(one + "OCRText").Select(x => x.Value).ToArray();
See the "Application Interface" docs on MSDN for more info - http://msdn.microsoft.com/en-us/library/gg649853.aspx