How can you read the fields from a password-protected PDF using iText when you do have the PDF password? - security

I have a PDF created from LiveCycle Designer in PDF 1.7.
I'd like to read some fields in that PDF on the server side at times. I have the password that protects the PDF on the server side.
I am able to use iText for this for non-encrypted PDFs just fine...
PdfReader reader = new PdfReader(request.getInputStream());
AcroFields af = reader.getAcroFields();
Map<String, AcroFields.Item> afFields = af.getFields();
for (String key : afFields.keySet()) {
System.out.print(key + " = ");
System.out.println(af.getField(key));
}
But when I do that same thing for a PDF that is password protected, this seems to break down. I get no fields returned.
Is there some way I can send that password into iText and be able to read the fields?
I also have access to the LiveCycle ES3 SDK as well. Maybe they provide an API to do that?

The answer, in case anyone was seeking for it, was to abandon the use of iText when trying to read data from a LiveCycle created PDF from your java app. I was so used to using Open Source APIs, I forgot to utilize the LiveCycle Web Services that they provided.
They provide a workbench product that lets you string web services together. And one of the many web services offered was an EncryptionService that can decrypt a password protected PDF, and then another service that can get an XML representation of the data in the PDF.
So I simply called those two services, and done.

Related

Auto load Office Centralized deployed custom Add-in using upload XML manifest file

I have created a customized add-in to PowerPoint and I deployed that through Centralized Deployment using upload manifest file in the Office 365 admin center.
I want this add-in to be loaded automatically when the user opens a document, for this I was used Open XML SDK to configure Office documents to automatically open a specified add-in
https://github.com/OfficeDev/Office-OOXML-EmbedAddin
But currently, I am not able to load it automatically. I am getting an error "Add-in Warning This add-in is no longer available."
.
I have mentioned two lines of code used in the program , here we used two ids for webextension and WebExtensionStoreReference.
please advice on these two lines to what parameter and values I want to use correctly
We.WebExtension webExtension1 = new We.WebExtension(){ Id = "{52811C31-4593-43B8-A697-EB873422D156}" };
We.WebExtensionStoreReference webExtensionStoreReference1 = new We.WebExtensionStoreReference() { Id = "af8fa5ba-4010-4bcc-9e03-a91ddadf6dd3", Version = "1.0.0.0", Store = "EXCatalog", StoreType = "EXCatalog" };
please help if anyone knows about this....!!

Generate html email body in Azure Function

In my application, I need to send templated HTML emails from an Azure Function.
The content is fairly large and getting the HTML to work in all clients can be pretty hard, even with the help of something like https://litmus.com/pre-send-testing. For this reason, I do not want to to use string concatenation/interpolation. I want to have the email content in a file I can view/edit in an IDE.
I need to replace some content with text for the specific recipient.
Ideally, I would like to have conditional logic in the template to avoid too much duplication (although this is not essential).
I have used the excellent https://github.com/toddams/RazorLight nuget package in other environments but unfortunately it does not work in Azure Fucntions.
Are there any other solutions for text templating for HTML that work in Azure Functions?
At the moment my best option is something like this (where Body.html is an embedded resource file):
StringBuilder body = new StringBuilder();
Stream template = this.GetType().Assembly.GetManifestResourceStream("EmailTemplating.Body.html");
using var reader = new StreamReader(template, Encoding.UTF8);
body.Append(reader.ReadToEnd());
body.Replace("{{recipient-name}}", "Jim");
In the end, we used https://github.com/rexm/Handlebars.Net which has good templating features (standard Moustache/Handlebars functionality) and worked a charm in Azure Functions.
Did you consider storage for the purpose? You can store a template file say template.html in a blob container and leverage it whenever required (download the file into a MemoryStream and make the Stream the content of the Function’s response/ the content for the next action based on your reqirement.

How to handle data import and export from a Windows Universal app

I am developing a Windows Universal app that collects results of races. It saves each race result in a sql-lite database in an application folder so the user can view previous results. I have further requirements, however, for saving and opening race results.
I need to be able to export the results of a race as a CSV file so that they can be opened by a third-party application that might be running on a separate machine on a different operating system.
I need to be able to export the results as an HTML file that can be uploaded/included in the user's own web site.
I need the user to be able to print the results (which I was thinking could just be done by printing the HTML file from a browser)
I would like the user to be able to choose to import the results of a race created by my own legacy application in my own format.
It seems, however, that we are restricted in a Windows Universal app to saving files to just very specific folders under very specific circumstances if we have requested that app capability. Therefore I am getting access denied errors both saving and reading files using the FileOpenPicker and FileSavePicker.
I think I probably need to view the export and import of results in a different way, but after a lot of searching I have not been able to come up with the right and recommended solution to this. So the question is how should I be handling the import and export of results? Should I be using the user's documents folder, or their OneDrive? Do I need to create a web application for my app so that the user can store results in the cloud and download them from there?
CSV and HTML are both text files with some encoding. So your question is about how to read/write files with JS.
Here is example how to create html page with FileSavePicker:
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
savePicker.fileTypeChoices.insert("Web page", [".html"]);
savePicker.suggestedFileName = "New page";
savePicker.pickSaveFileAsync().then(function (file)
{
if (file) {
var _WriteThis="<!DOCTYPE html>" + "\r\n";
_WriteThis = _WriteThis + "<html><head><title>Web page title</title>" + "\r\n";
// .....
Windows.Storage.FileIO.writeTextAsync(file, _WriteThis, Windows.Storage.Streams.UnicodeEncoding.utf8);
}
});
This example doesn't required any special rules and you can save file anywhere on you PC HDD or USD stick without setting capabilities in manifest (except system folders)
Same way you can save in csv format

Document support (rtf, doc, docx) for UWP/Windows 10 Mobile

How can I display documents (doc, docx, rtf) in an UWP app? The WebView isn't able to do this.
Other options would be calling an external application with Windows.System.Launcher.LaunchUriAsync (e.g. Word) or using a 3rd party library. The requirement is to have the data in the app, because you don't have control over it, if it's handled to another one. Another option would be to convert it to another format (e.g. PDF) which UWP can handle (not really).
Any ideas?
If you would like to display word or pdf files in the UWP app you can use WebView control with Google Docs Viewer - I was using it for the online documents.
This is the code:
XAML:
<WebView x:Name="MyWebView"/>
Code behind:
public WebViewPage()
{
this.InitializeComponent();
loadWebView();
}
void loadWebView()
{
var googleDocsViewer = "http://drive.google.com/viewerng/viewer?embedded=true&url=";
var pdf = "http://www.uma.es/precarios/images/pdfs/wd-spectools-word-sample-04.doc";
MyWebView.Navigate(new Uri(googleDocsViewer + pdf));
}
I did not test it with local files, but I think that should also work. Please try and let me know.
UWP can actually handle RTF files with RichEditBox - for more info about that see here in the official documentation (I don't know about RichTextBlock). For Docx support I can recommend a third-party library by Syncfusion, which you can get for free if you meet certain requirements.

How to Upload images from local folder to Sitecore

`webClient.UploadFile("http://www.myurl.com/~/media/DCF92BB74CDA4D558EEF2D3C30216E30.ashx", #"E:\filesImage\Item.png");
I'm trying to upload images to sitecore using webclient.uploadfile() method by sending my sitecore address and the path of my local images.But I'm not able to upload it.I have to do this without any API's and Sitecore Instances.
The upload process would be the same as with any ASP.net application. However, once the file has been uploaded you need to create a media item programtically. You can do this from an actual file in the file system, or from a memory stream.
The process involves using a MediaCreator object and using its CreateFromFile method.
This blog post outlines the whole process:
Adding a file to the Sitecore Media Library programatically
If you're thinking simply about optimizing your developer workflow you could use the Sitecore PowerShell Extensions using the Remoting API as described in this this blog post
If you want to use web service way than you can use number of ways which are as follows:
a) Sitecore Rocks WebService (If you are allowed to install that or it is already available).
b) Sitecore Razl Service(It is third party which need license).
c) Sitecore Powershell Remoting (This needs Sitecore PowerShell extensions to be installed on Sitecore Server).
d) You can also use Sitecore Service which you can find under sitecore\shell\WebService\Service.asmx (But this is legacy of new SitecoreItemWebAPI)
e) Last is my enhanced SitecoreItemWebAPI (This also need SitecoreItemWebApi 1.2 as a pre-requisite).
But in end except option d you need to install some or other thing in order to upload the image using HTTP, you should also know the valid credentials to use any of above stated methods.
If your customers upload the image on the website, you need to create the item in your master database. (needs access and write right on the master database) depend on your security you might consider not build it with custom code.
But using the Sitecore webforms for marketers module With out of the box file upload. Create a form with upload field and using the WFFM webservices.
If you dont want to use Sitecore API, then you can do the following:
Write a code that uploads images into this folder : [root]/upload/
You might need to create folder structure that represent how the images are stored in Sitecore, eg: your images uploaded into [root]/upload/Import/ will be stored in /sitecore/media library/Import
Sitecore will automatically upload these images into Media library
Hope this helps
Option: You can use Item Web API for it. No reference to any Sitecore dll is needed. You will only need access to the host and be able to enable the Item Web API.
References:
Upload the files using it: http://www.sitecoreinsight.com/how-create-media-items-using-sitecore-item-web-api/
Enable Item Web Api: http://sdn.sitecore.net/upload/sdn5/modules/sitecore%20item%20web%20api/sitecore_item_web_api_developer_guide_sc66-71-a4.pdf#search=%22item%22
I guess that is pretty much what you need, but as Jay S mentioned, if you put more details on your question helps on finding the best option to your particular case.
private void CreateImageIteminSitecore()
{
filePath = #"C:\Sitecore\Website\ImageTemp\Pic.jpg;
using (new SecurityDisabler())
{
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Resources.Media.MediaCreatorOptions options = new Sitecore.Resources.Media.MediaCreatorOptions();
options.FileBased = true;
options.AlternateText = Path.GetFileNameWithoutExtension(filePath);
options.Destination = "/sitecore/media library/Downloads/";
options.Database = masterDb;
options.Versioned = false; // Do not make a versioned template
options.KeepExisting = false;
Sitecore.Data.Items.MediaItem mediaitemImage = new Sitecore.Resources.Media.MediaCreator().CreateFromFile(filePath, options);
Item ImageItem = masterDb.GetItem(mediaitemImage.ID.ToString());
ImageItem.Editing.BeginEdit();
ImageItem.Name = Path.GetFileNameWithoutExtension(filePath);
ImageItem.Editing.EndEdit();
}
}

Resources