DevExpress WinForms XtraRichEdit - Export Document to an Image - devexpress

I'm looking for an ability to export documents (e.g. doc, rtf, txt) as images. Does XtraRichEdit support such functionality? This is definitely supported by Aspose.Words, but I'm not sure about DevExpress.

This can be done by using the XtraPrinting Library. Please refer to the code below:
using DevExpress.XtraPrinting;
//...
PrintableComponentLink link = new PrintableComponentLink(printingSystem1);
link.Component = richEditControl1;
link.CreateDocument();
link.ExportToImage(#"c:\image.png", new ImageExportOptions()
{
Format = System.Drawing.Imaging.ImageFormat.Png,
ExportMode = ImageExportMode.DifferentFiles,
Resolution = 96
});

Related

Xamarin - CachedImage - Access the downloaded file

I am using the CachedImage component of ffimageloading. I have a kind of gallery with a carousel view.
All the images are loaded through an internet URL, they are not local images. I would like to add the image sharing function. But I don't want to download the file again, I would like to know if there is a way to access the file that the CachedImage component already downloaded to be able to reuse it in the share function.
try using MD5Helper
var path = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey")'
Thanks Jason
I share with you how part of my code is:
var key = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey");
var imagePath = await ImageService.Instance.Config.DiskCache.GetFilePathAsync(key);
var tempFile = Path.Combine(Path.GetTempPath(), "test.jpg");
if (File.Exists(tempFile))
{
File.Delete(tempFile);
}
File.Copy(imagePath, tempFile);
await Share.RequestAsync(new ShareFileRequest
{
Title = "Test",
File = new ShareFile(tempFile)
});
The temporary file I believe, since the cached file has no extension and the applications do not recognize the type.

PDF content search in asp.net c#

Actually my requirement is to search pdf files using the pdf content.
I have a folder with a lot of PDF files.
I would like to develop an ASP.net application that enables the user to
search pdf using the content provided by them inside a textbox.
how to perform this task?
thank u in advance.
Your task may be split into following subtasks:
Develop indexer that will index all of your PDF files
Develop the code to locate relevant PDF whenever a search performed (using the index, of course)
Develop functionality that will open relevant PDF or show a warning if nothing was found
To build index you may use some integrated solution like Apache Lucene or Lucene.Net or convert each PDF into text and build index from the text yourselves.
You may try Docotic.Pdf library for the indexer part (disclaimer: I work for Bit Miracle).
The library could be used to extract text from PDFs. It can extract text with or without formatting. The extracted text can be used to create an index.
The library can also retrieve a collection of words with their bounding rectangles from PDFs. This might be useful if you need to know exact position of a text in a file.
If you don't want to build an index then you still can use Docotic.Pdf to perform searches using a code like the following:
PdfDocument doc = new PdfDocument("file.pdf");
string textToSearch = "some text";
for (int i = 0; i < doc.Pages.Count; i++)
{
string pageText = doc.Pages[i].GetText();
int count = 0;
int lastStartIndex = pageText.IndexOf(textToSearch, 0, StringComparison.CurrentCultureIgnoreCase);
while (lastStartIndex != -1)
{
count++;
lastStartIndex = pageText.IndexOf(textToSearch, lastStartIndex + 1, StringComparison.CurrentCultureIgnoreCase);
}
if (count != 0)
Console.WriteLine("Page {0}: '{1}' found {2} times", i, textToSearch, count);
}
You can use any library for that, try iTextSharp its a free one.
You can read pdf as text like this:
public string ReadPdfFile(string fileName)
{
StringBuilder text = new StringBuilder();
if (File.Exists(fileName))
{
PdfReader pdfReader = new PdfReader(fileName);
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
pdfReader.Close();
}
return text.ToString();
}
try Zoom Search it has a plugin for extracting pdf documents text (which you can search against) , and its easy to customize your search.You will need the standard edition which is not free (about $49).Zoom search does the searching for you out of the box, you do not need to do any complicated stuff eg if you prefer to extract the text from the pdf and then some how index it in a database for search or trying to use Lucene search engine which will require you to do implement /and customise(a bit of work).
Zoom works well with ASP.NET and you just need to use the GUI for customizing your search(not a lot of coding is required).

Annotation in pdfclown

I am trying to put a sticky note at some x,y location. For this i am using the pdfclown annotation class in .net.
Below is what is available.
using files = org.pdfclown.files;
public override bool Run()
{
files::File file = new files::File();
Document document = file.Document;
Populate(document);
Serialize(file, false, "Annotations", "inserting annotations");
return true;
}
private void Populate(Document document)
{
Page page = new Page(document);
document.Pages.Add(page);
PrimitiveComposer composer = new PrimitiveComposer(page);
StandardType1Font font = new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false);
composer.SetFont(font, 12);
annotations::Note note = new annotations::Note(page, new Point(78, 658), "this is my annotation...");
note.IconType = annotations::Note.IconTypeEnum.Help;
note.ModificationDate = new DateTime();
note.IsOpen = true;
composer.Flush();
}
Link for annotation
This is putting a sticky note at 78, 658 cordinates in a blank pdf.
The problem is that i want that sticky note in a particular pdf which has some data. How can i modify it...thanks for the help..
I'm the author of PDF Clown -- this is the right way to insert an annotation like a sticky note into an existing page:
using org.pdfclown.documents;
using annotations = org.pdfclown.documents.interaction.annotations;
using files = org.pdfclown.files;
using System.Drawing;
. . .
// Open the PDF file!
using(files::File file = new files::File(#"C:\mypath\myfile.pdf"))
{
// Get the document (high-level representation of the PDF file)!
Document document = file.Document;
// Get, e.g., the first page of the document!
Page page = document.Pages[0];
// Insert your sticky note into the page!
annotations::Note note = new annotations::Note(page, new Point(78, 658), "this is my annotation...");
note.IconType = annotations::Note.IconTypeEnum.Help;
note.ModificationDate = new DateTime();
note.IsOpen = true;
// Save the PDF file!
file.Save(files::SerializationModeEnum.Incremental);
}
Please consider that there are lots of options about the way you can save your file (to an output (in-memory) stream, to a distinct path, as a compacted file, as an appended file...).
If you look at the 50+ samples accompanying the library's distribution, along with the API documentation, you can discover how expressive and powerful it is. Its architecture strictly adheres to the official Adobe PDF Reference 1.7.
enjoy!

How do I read in FILE contents in QML?

I just need something similar to Fstream to read file IO in QML. Why is there no file IO?
If your file is plain text you can use XMLHttpRequest. For example:
var xhr = new XMLHttpRequest;
xhr.open("GET", "mydir/myfile.txt");
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var response = xhr.responseText;
// use file contents as required
}
};
xhr.send();
I know this is old question but you might be still interested in answer.
Here it is: Reading a line from a .txt or .csv file in qml (Qt Quick)
In short, you have here explained how to read files in QML: http://www.developer.nokia.com/Community/Wiki/Reading_and_writing_files_in_QML
All you need is to extend QML with C++.
QML has no built-in file I/O. But - judging from the tone of your post - you already knew that.
How do I read in FILE contents in QML?
You can extend QML's functionalities using C++.
The Getting Started Programming with QML tutorial from the Qt Reference Documentation shows you how to build a text editor. This includes file I/O using C++.
Why is there no file I/O?
Because QML is based on JavaScript, and JavaScript has no built-in file I/O either.
QML is designed as an (easy) way to build a user interface. You need an actual program to do the rest.
There is built-in file I/O available for QML with the Felgo SDK (formerly V-Play) FileUtils. It works cross-platform on desktop, iOS and Android. More info and examples are also in the latest blog post.
It looks like this:
var documentsData = fileUtils.readFile("subfolder/file.json")
function readConfigFile() {
var xhr = new XMLHttpRequest;
var configaddress = "File:///" + root + "/webconfig.txt" //root = "c:/folder/file.ini";
console.log(configaddress);
xhr.open("GET", configaddress);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var response = xhr.responseText;
var js = JSON.parse(response)
if (js.address != "") {
service_address = js.address
}
// use file contents as required
}
};
xhr.send();
}
What do you want to read the file for?... if its simple data.. then you are probably better off using QML Offline storage API. Look for that section here.
If you want to deploy a db with your application read this conversation.
If you really want to read the file still, learn C++ and expose your code to QML. That, then, is beyond the scope of my answer.

AS3: reading embedded metadata in flex

I saw that you can embed meta-data into images very much like you can in mp3s, here.
Can someone point me to a tutorial of how to embed and read this sort of information w/ photoshop and flex together?
I really wouldn't know where to start... Tried googling but I'm not sure I have the right keywords down.
Thanks!
I've written a small snippet on the matter. this snippet is far from being proper tested, and is most definite not written in a clear and coherent way. But for now it seems to work. I'll update as I work on it.
private function init(event:Event):void
{
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
var s:String = "link/to/asset.jpg";
ldr.load(new URLRequest(s));
}
private function imgLoaded(e:Event):void{
var info:LoaderInfo = e.target as LoaderInfo;
var xmpXML:XML = getXMP(info.bytes);
//trace(xmpXML);
var meta:XMPMeta = new XMPMeta(xmpXML);
}
private function trim(s:String):String{
return s.replace( /^([\s|\t|\n]+)?(.*)([\s|\t|\n]+)?$/gm, "$2" );
}
private function getXMP(ba:ByteArray):XML{
var LP:ByteArray = new ByteArray();
var PACKET:ByteArray = new ByteArray();
var l:int;
ba.readBytes(LP, 2, 2);
/*
http://www.adobe.com/devnet/xmp.html
read part 3: Storage in Files.
that will explain the -2 -29 and other things you see here.
*/
l = LP.readInt() - 2 -29;
ba.readBytes(PACKET, 33, l);
var p:String = trim(""+PACKET);
var i:int = p.search('<x:xmpmeta xmlns:x="adobe:ns:meta/"');
/* Delete all in front of the XMP XML */
p = p.substr(i);
/*
For some reason this left some rubbish in front, so I'll hardcode it out for now
TODO clean up
*/
var ar:Array = p.split('<');
var s:String = "";
var q:int;
var j:int = ar.length;
for(q=1;q<j;q++){
s += '<'+ar[q];
}
i = s.search('</x:xmpmeta>');
i += ('</x:xmpmeta>').length;
s = s.slice(0,i);
/* Delete all behind the XMP XML */
return XML(s);
}
Originally from http://snipplr.com/view/51037/xmp-metadata-from-jpg/
Photoshop (CS4+ I think) can also add XMP headers (XML style) which will be easier to parse than bytes but it contains different information.
http://code.google.com/p/exif-as3/
Here is a class that should do the job. It is non-commercial only but there is another option.
www.ultrashock.com/forums/server-side/extracting-metadata-from-photos-86065.html
Here is a php script that will do it that could be ported to as3 - it might be easier than creating one from scratch. If you did want php to read the info I would use the built in exif functions :)
Well AS3 don't have a built-in class to read jpg header.
BUT, if you are loading the image using URLLoader you can use the ByteArray to read if manually.
You can find the spec here:
http://www.obrador.com/essentialjpeg/HeaderInfo.htm
If you need some tutorial of using Bytearray you can start from here:
How to convert bytearray to image or image to bytearray ?
or here:
http://digitalmedia.oreilly.com/pub/a/oreilly/digitalmedia/helpcenter/flex3cookbook/chapter8.html?page=7
The principle is the same -read the bytes, convert them to readable data using the spec above and use it.
Good luck!
Yes, entirely possible. ByteArray is your friend.
You may want to give a read to this:
http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
This may also be of use, but I'd rather go with the first option:
http://download.macromedia.com/pub/developer/xmp/sdk/XMPLibrary-v1.0.zip

Resources