Using iText7 with Adobe Sign PDF. Need to remove protection - itext7

Can anyone tell me if they have had any success in using iText7 and was able to remove the protection level access in order to merge signed documents from Adobe Sign with other PDF documents? I have been trying this for days with no success. Adobe Support says it can't be done and iText requires payment for support. Here is my code:
ReaderProperties readerProperties = new ReaderProperties().SetPassword(new System.Text.UTF8Encoding().GetBytes("password"));
PdfReader pdfReader = new PdfReader(new System.IO.MemoryStream(response.RawBytes), readerProperties);
pdfReader.SetUnethicalReading(true);
//pdfReader = TryToUnlockPdf(pdfReader);
MemoryStream baos = new MemoryStream();
using (iText.Kernel.Pdf.PdfDocument pdfDoc = new iText.Kernel.Pdf.PdfDocument(pdfReader, new PdfWriter(baos)))
{
if (Configuration.GetValue<bool>("IsTestingLocally"))
{
CreateIfMissing(Path.GetDirectoryName("c:/tmp/" + doc.name));
if (System.IO.File.Exists("c:/tmp/" + doc.name)) System.IO.File.Delete("c:/tmp/" + doc.name);
System.IO.File.WriteAllBytes("c:/tmp/" + doc.name, baos.ToArray());
}
pdfReader.Close();
}
The response.RawBytes is the PDF bytes coming back from Adobe's Agreement.
Thanks in advance.
EDIT: The "password" value listed in here is a dummy value. I took out the password value.
The issue is as follows. I can download the PDF file from Adobe Sign fine. The file is locked, however, I have the password, so that's fine too.
The issues is, even though the file is unlocked, when I write the file to my folder, it says it is corrupted. So it seems as if the password works fine, but the file will not write correctly.

Related

Xamarin Community Toolkit CameraView video file location supplied becomes invalid IOS and Android

I'm using the CameraView to capture a series of short videos. I want these videos to be viewable at a later time from within the app. I'm using the MediaCaptured event to get the path of captured videos and saving these paths in a SQLite db.
The first problem is on iOS, the path is valid while the app is open, but if I close the app and open it again the path is no longer valid. I've worked around this by copying the video to the AppDataDirectory but this seems bad because I haven't figured out how to delete the original so now two copies of the video exist.
The second problem is on both iOS and Android, after some amount of time (a few days or a week or more) these paths become invalid for some unknown reason.
What is the correct way to deal with this?
private void MediaCaptured(object obj)
{
MediaCapturedEventArgs args = obj as MediaCapturedEventArgs;
string sPath = "";
switch (Device.RuntimePlatform)
{
case Device.iOS:
//On iOS args.Video.File returns a path that isn't valid when the app is restarted. To get around this issue I am copying the file to the App Data Directory.
//The drawback is there are now two video files and I can't delete the original.
var pathSplit = args.Video.File.Split('/');
sPath = Path.Combine(FileSystem.AppDataDirectory, pathSplit[pathSplit.Length - 1]);
File.Copy(args.Video.File, sPath);
//TODO Should probalby be deleting the original video but not sure how (or if its possible).
break;
case Device.Android:
sPath = args.Video.File;
break;
}
SavePathToDB(sPath);
}

Add download to Firefox via Firefox extension

This is my first Firefox extension which I'm developing with addon-builder [builder.addons.mozilla.org/] .
My question is simple but after trying many things, for many days, I'm unable to get results.
I want to know: How to add a file download to Firefox downloader??
I've a url like: http:// example.com/file.zip and a file location like: D:\myFolder.
I want to add this download via my firefox extension.
The things which I've searched are:
https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIWebBrowserPersist#saveURI%28%29
https://developer.mozilla.org/en-US/docs/Code_snippets/Downloading_Files
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
const WebBrowserPersist = Components.Constructor("#mozilla.org/embedding/browser/nsWebBrowserPersist;1",
"nsIWebBrowserPersist");
var persist = WebBrowserPersist();
var targetFile = Services.dirsvc.get("Desk", Ci.nsIFile);
targetFile.append("file.bin");
// Obtain the privacy context of the browser window that the URL
// we are downloading comes from. If, and only if, the URL is not
// related to a window, null should be used instead.
var privacy = PrivateBrowsingUtils.privacyContextFromWindow(urlSourceWindow);
persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE
| persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
persist.saveURI(uriToSave, null, null, null, "", targetFile, privacy);
Can you just gimme a start from where I should get the easiest possible download function.
Components.utils.import("resource://gre/modules/Services.jsm");
var {downloads}=Services;
downloads.addDownload(/*parameters*/); //see documentation for parameters.
Documentation for addDownload: nsIDownloadManager#addDownload()
Documentation and directory for the wide range of services provided by Services.jsm: Services.jsm

path from isolated storage windows phone

hi i have a simple question how i can find the path of a file which had been already saved in the isolated storage
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(App.filePath, FileMode.Create, store))
{
byte[] buffer = new byte[1024];
while (e.Result.Read(buffer, 0, buffer.Length) > 0)
{
stream.Write(buffer, 0, buffer.Length);
}
stream.Close();
}
now i would read this file
i need this path to use it as a parameter of method
Epub epub =new Epub([file path])
any help will be greatly appreciated
If a file is in IsolatedStorage you either put there yourself or it's the one created by the system to store settings.
If you put it there you must have had the path at some point previously. You just need to track the file names (and paths) you're using.
You should not try and access the settings file directly.
Try this
using (var AppStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] filenames=AppStorage.getFileNames();
//choose the filename you want or
//enumerate directories and read file names in each directory
string[] directories=AppStorage.getDirectories();
}
For each directory you have to add the filepath upto that directory just like in any windows file browsing.
Hope it helps.Post your further queries.
There is no need for you to get the path to the file if you are the one who put the file in the isolated storage. The entire guide to how properly read and write files to the app isostore is available here, and this should be your starting point.
The entire reading routine is limited to this:
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fileStream))
{
Console.WriteLine("Reading contents:");
Console.WriteLine(reader.ReadToEnd());
}
}
Where myIsolatedStorage is equal to IsolatedStorageFile.GetUserStoreForApplication() (akak your local app storage box).
No need for Reflection, as you showed in the comments. The can be relative to a folder, when you're attempting to read, so something like /MyFolder/myFile.txt will work as well, given that the folder exists.
Your problem is this - pushing the relative path in the isostore to the Epub class, which probably does not read directly from the isostore and uses a full path instead. The nature of the Windows Phone OS is such that it won't let a third-party application without proper permissions to access content directly through a full path reference. So you need to figure out a way to pass binary content to the class instead of a path.

count image hash(md5) in adobe air

I use HTML+JAVASCRITP+CSS develop desktop software in adobe air platform
I download md5.js that count md5 value as same php md5 value
air.filestream function read location of file and send to md5.js to count hash ,normal file(js,php,css,txt) can count as same php md5 value, but count image file get wrroy hash,the image isn't change.
var fileStream = new air.FileStream();
var target = new air.File(file.nativePath);
fileStream.open(target , air.FileMode.READ);
var str = fileStream.readMultiByte(target.size,'utf-8'); alert(window.md5(str));
You should use this library that does reading binary data.
Then, unzip the swc and get the swf file to a lib folder in your app path.
You must check the xml file to get the qualified name of the md5 function you want to use
(.by.blooddy.crypto.MD5.hashBytes(data) )
Add an script include line on the html header
<script src="lib/library.swf" type="application/x-shockwave-flash"></script>
and you can use the function trought the window.runtime object:
hash = window.runtime.by.blooddy.crypto.MD5.hashBytes(data);
and this hash will be the same you can get with a md5 in php.
By the way you must read the file using readBytes instead of readMultiByte.
adobe link (Using ActionScript libraries within an HTML page)

WP7 app version

A Windows Phone 7 app, it seems, has two places with version number - one in AssemblyInfo.cs (via AssemblyVersion/AssemblyFileVersion attributes), the other is WMAppManifest.xml. Those two seem uncorrelated - changing one does not affect the other. The Marketplace, it seems, uses the one from the manifest - can someone please confirm this?
The real question is - how do I retrieve the one from manifest programmatically to display on the About screen?
The WmAppManifest.xml number is in use. First two digits are relevant for Marketplace (it is checked when you do the update) next two are for your internal usage.
This is a regular XML file, open it as a XDocument and parse it. An example.
EDIT: the example is extraneous. For just the version, use:
string Version = XDocument.Load("WMAppManifest.xml")
.Root.Element("App").Attribute("Version").Value;
To get App Version from "WMappManifest.xml", this solution might be a bit more efficient than lukas solution:
For WP7:
var xmlReaderSettings = new XmlReaderSettings
{
XmlResolver = new XmlXapResolver()
};
using (var xmlReader = XmlReader.Create("WMAppManifest.xml", xmlReaderSettings))
{
xmlReader.ReadToDescendant("App");
return xmlReader.GetAttribute("Version");
}
For WP8:
using (var stream = new FileStream("WMAppManifest.xml", FileMode.Open, FileAccess.Read))
{
string appVersion = XElement.Load(stream).Element("App").Attribute("Version").Value;
}

Resources