I am developing application on Windows Phone 8.1. I am using RichTextBlock to display rich content: text, images, hyperlinks.
Here is how to create image for rich text block:
new InlineUIContainer
{
Child = new Image
{
Source = new BitmapImage(new Uri("http://img.jpg", UriKind.Absolute))
}
};
I tried to create hyperlink with image inside like that:
hyperlink.Inlines.Add(CreateImageInlineUIContainer(...));
This line of code throws an exception:
ArgumentException: A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
Additional information: Value does not fall within the expected range.
Am I missing something? Are there any other ways to add hyperlink with image to a RichTextBlock?
Related
I am using docx4j to bind a custom XML part to a word document, but I get an error message that I cannot resolve. I have done these steps:
Inserted content controls into a Word document.
Create an XML file with data.
Use the Word 2007 Content Control Toolkit to bind the cuxtom XML parts to the content controls.
When I open the document the binding is successful and the XML data appear in the document. However, when I run Java code to bind the docx file to the xml file I get an error:
org.docx4j.openpackaging.exceptions.Docx4JException: No xpathStorageItemId found, does the document contain content controls that are bound?
The code I am using to make the binding is from the docx4j examples
try{
WordprocessingMLPackage wordMLPackage = Docx4J.load(new File(input_DOCX));
File inputFile = new File(input_XML);
FileInputStream xmlStream = new FileInputStream(inputFile);
Docx4J.bind(wordMLPackage, xmlStream, Docx4J.FLAG_BIND_INSERT_XML & Docx4J.FLAG_BIND_BIND_XML);
Docx4J.save(wordMLPackage, new File(OUTPUT_DOCX), Docx4J.FLAG_NONE);
System.out.println("Saved: " + OUTPUT_DOCX);
}catch(IOException ex){
ex.printStackTrace();
}catch(Docx4JException ex){
ex.printStackTrace();
}
There are some content controls on the document that are not associated with a custom XML part. Could that be the cause of the error? Must all content controls have an XPATH?
I am trying to show an Image and text on windows phone. The text works but the image does not show up at all the docs on msdn says that it should though
here is my code ...
ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("Hello World!"));
XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/Square71x71Logo.scale-240.png");
((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "red graphic");
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
Results
Expected Results
Image Square71x71Logo.scale-240.png
You cannot include an image in a toast on Windows Phone 8.1. The template will always be the app's logo then two text fields.
This is documented near the top of the Toast Template Catalog documentation on MSDN.
I'm writing some javascript for a Windows 8 app. I'm trying to render a drawing to a canvas element that is a child of a dynamically created document.
I've got this function returning a new document:
initPrintDoc: function () {
var emptyDoc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null),
emptyBody = document.createElement('body'),
emptyCanvas = document.createElement('canvas'),
debugDiv = document.createElement('div'),
debugMsg = document.createTextNode("[PRINT] : This is a test print source.");
//Initialize attributes for elements
emptyBody.setAttribute('id', 'pdf-container');
emptyCanvas.setAttribute('id', 'render-output');
debugDiv.setAttribute('id', 'debug-output');
debugDiv.appendChild(debugMsg);
emptyBody.appendChild(debugDiv);
emptyBody.appendChild(emptyCanvas);
emptyDoc.documentElement.appendChild(emptyBody);
return emptyDoc;
},
The returned document object is not the document object that is displayed in the Windows 8 App UI at runtime. I am using this dynamically created document as the parameter for the MSApp.getHtmlPrintDocumentSource(). Unfortunately, no matter what I do to the canvas element that is inside this document, the canvas never shows a rendering in the actual printout, nor in the simple preview window found in the charms bar after clicking a selected printer.
My question is: does a canvas element require its container document to be displayed in the browser window? Can you manipulate a canvas element in a dynamically created document, and expect those manipulations to show when you display that document?
I'm working to refactor a PDF form web application that is using the Active PDF Toolkit and the FDFToolkit from Adobe. My goal is to use iTextSharp to:
Pre-populate the form fields with data from the database
Allow the user to attach a signature and/or barcode image via FDF
Item #1 is not the problem. Item #2 is the biggest challenge. Let me provide some background:
This is a web application which renders the PDF form once. After the initial load, there are 2 key buttons on the form which submit the PDF form to a URL with an action parameter in the query string. These buttons are called "Save" and "Sign". The Save button takes the FDF field dictionary and saves it to the database. The Sign button looks up the signature for the logged-in user and attaches the signature image to the FDF and writes the FDF to the HTTP Response.
The FDFToolkit supports attaching an image to a field using this method:
FDFSetAP(string bstrFieldName, short whichFace, string bstrFileName, short pageNum)
iTextSharp does not offer a comparable method in the FdfWriter class. I've considered subclassing the FdfWriter class and adding my own method to attach an image, but wanted to reach out here to see if anyone has had the same problem.
I have been able to overlay an image on top of a field using this method, but this is in the underlying PDF and not the FDF.
AcroFields.FieldPosition pos = _Stamper.AcroFields.GetFieldPositions("SIGNATUREFIELD").First();
Image signature = Image.GetInstance("Signature.gif");
image.SetAbsolutePosition(pos.position.Left, pos.position.Bottom);
image.ScaleToFit(pos.position.Width, pos.position.Height);
PdfContentByte pcb = _Stamper.GetOverContent(pos.page);
pcb.AddImage(image);
Thanks!
I've put images on forms by using the PdfStamper and making Pushbutton fields. You can replace your existing field with a Pushbutton field and set the Pushbutton to READ_ONLY so that it can't be pressed and it will look like a static image. This will keep the image you're trying to add as a field annotation instead of adding it to the page content.
using (PdfStamper stamper = new PdfStamper(new PdfReader(inputFile), File.Create(outputFile)))
{
AcroFields.FieldPosition fieldPosition = stamper.AcroFields.GetFieldPositions(fieldName)[0];
PushbuttonField imageField = new PushbuttonField(stamper.Writer, fieldPosition.position, fieldName);
imageField.Layout = PushbuttonField.LAYOUT_ICON_ONLY;
imageField.Image = iTextSharp.text.Image.GetInstance(imageFile);
imageField.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS;
imageField.ProportionalIcon = false;
imageField.Options = BaseField.READ_ONLY;
stamper.AcroFields.RemoveField(fieldName);
stamper.AddAnnotation(imageField.Field, fieldPosition.page);
}
I'm building a Win8/WinJS app that loads pictures from the local pictures library. Everything is generally working fine for loading valid images and displaying them in a list view.
Now I need to detect corrupt images and disable parts of the app for those images.
For example, open a text file and enter some text in it. Save the file as .jpg, which is obviously not going to be a valid jpg image. My app still loads the file because of the .jpg name, but now I need to disable certain parts of the app because the image is corrupt.
Is there a way I can check to see if a given image that I've loaded is a valid image file? To check if it's corrupt or not?
I'm using standard WinRT / WinJS objects like StorageFile, Windows.Storage.Search related objects, etc, to load up my image list based on searches for file types.
I don't need to filter out corrupt images from the search results. I just need to be able to tell if an image is corrupt after someone selects it in a ListView.
One possible solution would be to check the image's width and height properties to determine whether it is valid or not.
Yeah, the contentType property will return whatever the file extension is. The best way I can find it to look at the image properties:
file.properties.getImagePropertiesAsync()
.done(function(imageProps) {
if(imageProps.width === 0 && imageProps.height === 0) {
// I'm probably? likely? invalid.
});
where SelectImagePlaceholder is an Image Control.. =)
StorageFile file;
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
try
{
// Set the image source to the selected bitmap
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(fileStream);
SelectImagePlaceholder.Source = bitmapImage;
//SelectImagePlaceholder.HorizontalAlignment = HorizontalAlignment.Center;
//SelectImagePlaceholder.Stretch = Stretch.None;
this.SelectImagePlaceholder.DataContext = file;
_curMedia = file;
}
catch (Exception ex)
{
//code Handle the corrupted or invalid image
}
}