Dynamically add image to powerpoint openxml - c#

I am creating power point 2007 files using the openxml. I am able to add slides, shapes, text and manipulate them to create custom reports. However, I can not find an example on how to dynamically load an image into my power points. In principle I imagine that it would involve adding the image as a resource and then adding a reference to that resource. Any example code would be great help.
Thank you.

You will first need to add an ImagePart to your SlidePart like this:
ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, "rId3");
The "rId3" needs to be the relationshipId that corresponds to your image that you are adding to the presentation. You could also leave that parameter blank and a default relationship id will be created for you. Next you need to feed that image part the actual image:
imagePart.FeedData(new MemoryStream(photo.ToArray()));
If you are still having trouble take a look at these two blog posts. They both show some code mid way down about adding photos to a presentation.
Creating a report presentation based on data
Adding repeating data to PowerPoint

Related

Overlay between two PDF in C#

I'm looking for a way to get the result of an overlay between two pdf documents.
We have a document with a single page and only a header and another document with multiple pages and full content (header and body). We're looking for way to generate an overlay pdf between those documents, so that the resulting document with the content gets its header overwritten in each page with the single page document header. Basically like this:
Is there a opensource c# library, which can handle this and not convert the text to a picture.
I looked at PdfSharp and docnet, but couldn't figure it out with either of them.
So far we are using pdfbox, but we'd like to get rid of the java dependency.
Simple solution with PDFsharp: draw a white rectangle that hides the original header, then draw the new header on top of the rectangle.
Drawback: The old header is still contained in the document.

Deleting Images With Specific Hyperlink Using iTextSharp

I have created a Word document where I have inserted some images, added hyperlinks (to these images), and converted the document to pdf. Is there any way to find the position of the image that has a specific hyperlink using iTextSharp library? I have found solutions that can return the image or the hyperlink text but it's not exactly what I need.
My end goal is to find the image with a specific URL and delete it (along with the associated URL) while saving its location (have to save x, y, height, and width before deletion).
Thank you.
You have found solutions that can return:
the image and its position,
the hyperlink and its position.
And that's exactly what you need. Now compare the positions of the image with the positions of the hyperlinks and you'll know which image corresponds with which link.
You are asking to find images with a specific URL, but there is no such thing in PDF. In a PDF, each page is described using a page dictionary. In this page dictionary, there is:
an entry named /Contents (required): this refers to the content stream(s) of the page and the content stream(s) contain references to images (stored as /XObject in the /Resources entry of the page dictionary).
an entry named /Annots (optional): this refers to all the annotations that are added on top of the content. Hyperlinks are stored in link annotations.
Links are not aware of the content they cover. Content is not aware of the annotations that cover them. That's why you didn't find an answer to your question. You've been making the wrong assumptions about clickable images.

How to get the file format of an image shape in powerpoit using interop

I need to get all the GIF pictures inside of a PowerPoint presentation (2007 and 2010) using interop and c#, but the shape.PictureFormat.GetType() does not contain any useful information, any idea?
When user adds an image the original file name (with extension) is saved by default into shape "alt text" (right click on shape /size and position / alternative text).
But the user can change it, so for some images you could haven't the data.
Instead, if you have control over image inserting you could store that information into a specific shape.tag property and then read it later.

C# PDF work with tables

I have a pdf file with some table inside.
I want to read this document and change some existing row and add new rows too.
Is there a way do do this?
I'm afraid you won't have any luck.
Unfortunately you don't get 'rows' in a PDF - there is no concept of a table in PDF - only text and vector graphics.
This means you will have to manually add the vectors and the text in the right places to give the illusion of a table.

How to print a table of generated images in C#

I need to print a set of generated images in a table like structure with headings. These heading and images are never displayed on the screen. The images are generate QR codes for a series of URLS so they can easier be read in by a scanner. There need to be a header on each column and a text id field on each row but apart from that the rows would be 4-6 columns of QR codes (2d barcode).
I have found samples for printing images and samples for printing text and even a sample to print a datagrid shown on the screen but nothing for printing text and images in a table like structure. Could anyone help me out with a basic example. The table is expected to go over multiple pages vertically so I would also need to put the heading row on each page.
Even pointing me in the right direction would be useful.
This is for a windows application where I want to have code kick off a print job with no user interaction. Using dotnet 4.0.
See my method for creating and printing FixedDocument here including source code. This method will easily allow you to generate aligned tables with images and text and save them as XPS or print them to a printer.

Categories