Openxml word insert image - image

I have an excel sheet converted to html, then HTML converted to word. There is one missing thing: images from excel sheet are in format of base64 string and they are overlay on table, not a part of cell. How can I add such images to my docx file?
I want an image overlay on table starting over a special cell (like E18).

1- Base64 string must be converted to memorystream to be used as image source
ImagePart imgp = mainPart.AddImagePart(ImagePartType.Png);
MemoryStream M = new MemoryStream(Convert.FromBase64String(o.Base64String));
imgp.FeedData(M);
2- Drawing object with anchor must be created to accommodate the image. Inline drawing is not useful. Anchor object helps flow image above text to any place.
3- Most samples on the net add the drawing to document or body or run.... For purpose of my question (reference point inside of cell), we easily add drawing to cell object.
This post shows adding drawing to cell object. This post shows use of Anchor object.

Related

how to autosize textbox while updating text in dxf document using ezdxf

I am new to ezdxf. I have an engineering drawing in dxf format. I have to modify certain text in the existing document. I have the updations required in a dictionary. I loop through all the TEXT entities and comparing whether it is in the dictionary. If so, I update it with the corresponding value using e.dxf.set() method. But if the new string is longer than the enclosed text box, it passes across. Is it possible to autofit the surrounding text box by any means?

How to save images into playerprefs and display them to another scene?

I'm a beginner in Unity. And so far of what I read, playerprefs could store image in a byte form. Still, I'm having trouble in this one. Because, I'm having an error in converting texture2d to bytes. In which, I use this code
Texture tex = Resources.Load("Sprites/white_black") as Texture2D;
byte[] texbyte = tex.EncodeToPNG();
// ^ this line always result as NullReferenceException on my console.
I have two scenes: Scene1 is images that were going to save to playerprefs which is an example below:
While in Scene 2, all the images that were saved in playerprefs will be show using a button like in below pic:
Also, if you could recommend me other solution I'll search on it. Thank you.
You should not save images in PlayerPrefs but you could just save the name of the sprite to PlayerPrefs, and then load it in another scene from resources, like so: Resources.Load(spriteName);

Aspose PDF .Net repeating same image multiple times in a table

I'm trying to add a table to a PDF. Each row will have an image in a column. There are 3 images which will repeat in the rows.
If I just directly add the image to table cell like below, performance is very poor. It may be cause each image is treated as a separate new one.
cell.Paragraphs.Add(new Image(imagePath + "on.png"));
The below article describes how to add images to resources and reuse it. But I'm not able to figure out how this should be applied to a table cell. To be precise I'm able to add Aspose.Pdf.Image to a cell but not Aspose.Pdf.XImage.
https://docs.aspose.com/display/pdfnet/Manipulate+Images#ManipulateImages-AddImagetoExistingPDFFile
You can try to reuse the same Image object.
Image img = new Image(imagePath + "on.png");
cell.Paragraphs.Add(img):
cell.Paragraphs.Add(img):

itext7 PdfButtonFormField setImage method does not work on a signed pdf

I am using itext7 java library as shown below to add PdfButtonFormField to an existing pdf :
String src = "sample.pdf";
String dest = "acro_sample_empty_fields.pdf";
PdfDocument pdf = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
PdfButtonFormField button = PdfFormField.createPushButton(pdf, new Rectangle(Integer.parseInt(control.xCord), Integer.parseInt(control.yCord),Integer.parseInt(control.width), Integer.parseInt(control.height)), control.name, control.value);
form.addField(button, page);
String resource = "sample.png";
button.setImage(resource);
After this i use the following code to fill the form like below :
String src = "1540982441_313554925_acro_sample_empty_fields_signedFinal.pdf";
String dest = "acro_sample_filled_fields.pdf";
PdfReader reader = new PdfReader(src);
File output = new File(dest);
OutputStream outputStream = new FileOutputStream(output);
PdfDocument document = new PdfDocument(reader,
new PdfWriter(outputStream),
new StampingProperties().useAppendMode());
PdfAcroForm form = PdfAcroForm.getAcroForm(document, true);
Map<String, PdfFormField> fields = form.getFormFields();
String resource = "sample_test.png";
((PdfButtonFormField)fields.get(control.name)).setImage(resource);
Everything works fine for a normal pdf. But if i digitally sign the created pdf and then try to fill it. then the image is not set properly.
For a normal pdf the image on the push button is changed as expected. But on the digitally signed pdf the image is not set.
I have tried looking for this on google but no luck yet. Any help will be appreciated. Thanks in advance.
I tested the code in this answer with the signed but unfilled PDF you shared. As you didn't share a sample image, though, I used one of my own.
A more precise observation
You say
Everything works fine for a normal pdf. But if i digitally sign the created pdf and then try to fill it. then the image is not set properly. For a normal pdf the image on the push button is changed as expected. But on the digitally signed pdf the image is not set.
This is not entirely true, the image is set but not all PDF viewers show it.
In detail: If you set the image in the signed PDF using your code, Adobe Reader indeed shows merely a grey box
but other PDF viewers, e.g. Foxit or Chrome's built-in viewer, do show the replacement image
Thus, the image is set for the digitally signed PDF, too. The actual problem is that Adobe Reader does not display it!
The cause
After some analysis and having followed some red herrings, the cause of the problem appears to be that if Adobe Reader displays a PDF with a changed AcroForm button appearance and
the PDF is not signed, then Adobe Reader simply uses the updated appearance stream; but if
the PDF is signed, then Adobe Reader tries to ignore the updated appearance stream and construct a new appearance from appearance characteristics information.
(Other PDF viewers, though, appear to always use the updated appearance stream.)
iText does create an appearance characteristics dictionary for the button (so Adobe Reader assumes it can ignore the updated appearance and can construct an new one based on this dictionary) but unfortunately does not add some button specific information to it, neither when constructing the button nor when changing the button. This in particular concerns the following two entries:
I
stream
(Optional; push-button fields only; shall be an indirect reference) A form XObject defining the widget annotation’s normal icon, which shall be displayed when it is not interacting with the user.
TP
integer
(Optional; push-button fields only) A code indicating where to position the text of the widget annotation’s caption relative to its icon:
0 No icon; caption only
1 No caption; icon only
2 Caption below the icon
3 Caption above the icon
4 Caption to the right of the icon
5 Caption to the left of the icon
6 Caption overlaid directly on the icon
Default value: 0.
(ISO 32000-2, Table 192 — Entries in an appearance characteristics dictionary)
As iText does not supply the TP value, the Default value kicks in and Adobe Reader creates a button appearance with "No icon; caption only". As no caption is defined, the result is a grey box.
A work-around
The most simple work-around is to remove the whole appearance characteristics dictionary during image update, i.e. replace
((PdfButtonFormField)fields.get(control.name)).setImage(resource);
by
PdfButtonFormField button = (PdfButtonFormField)fields.get(control.name);
button.setImage(resource);
if (button.getPdfObject().containsKey(PdfName.MK)) {
button.setModified();
button.getPdfObject().remove(PdfName.MK);
}
(SetButtonImage helper method setLikeGautamAnandImproved)
Now Adobe Reader does not find any appearance characteristics and, therefore, cannot ignore the updated appearance stream.
A fix
Alternatively we can add the missing appearance characteristics entries, e.g. like this:
PdfButtonFormField button = (PdfButtonFormField)fields.get(control.name);
button.setImage(resource);
PdfWidgetAnnotation widget = button.getWidgets().get(0);
PdfDictionary characteristics = widget.getAppearanceCharacteristics();
if (characteristics != null) {
characteristics.setModified();
characteristics.put(PdfName.I, widget.getNormalAppearanceObject());
characteristics.put(PdfName.TP, new PdfNumber(1));
}
(SetButtonImage helper method setLikeGautamAnandImproved2)
The result looks slightly different, though:
As you see, there is a small frame around the image. Most likely you can make it vanish by setting other characteristics accordingly.

Convert string automatically to inline image

I'm using InDesign's data merge to generate playing cards for my game. Is it possible to convert a specific string to an inline image?
"You may roll :red_die: and add the rolled valued to this card's value"
For example the :red_die: in the text above would be automatically converted to an inline icon of a red coloured die.
No you can't this way. But you can place images with datamerge to the condition some fields of your source is set as an image one meaning having a "#" prefix. InDesign will process fields like #image as an image to place. It's up to you to add such a field in your source. However you can't nest it within another datamerge tag so it may not work eventually.
Other solution is using F/C dialog to replace :red_die: with clipboard content (your image) or to use scripting. You may also consider variable content plugin like EasyCatalog.

Resources