How to position an image on the page in MS Word - c#

I'm trying to edit a word document via code, just want to Insert two images, one on top left and another on top right of the first page... word.interop documentation states that Word.Range is used to position things.. but im having hard time wrapping my head around how this is used?? How do i specify "top left & Right of first page" Using Word.Range???
doc.InlineShapes.AddPicture(imagePath); which inserts images on top of the document, but dunno how to control position of it further
doc.InlineShapes.AddPicture(imagePath);
I Expect to have to be able to Specify location of images to be at top left and right of page 1.

.InlineShapes allows you to add inline shapes – shapes that are part of the textual flow.
These shapes are inserted at a range (a position within the text), not absolute coordinates within a page.
To add a shape that does not flow with text, use .Shapes.

Related

In iText 7 .net , how to determine data coordinates

I have a pdf that I want to grab a specific piece of info from.
My issue isn't how do I get it, my issue is I'm not under standing the coordinates of the rectangle.
I get the x,y, height & width, but not as it related to the actual page.
lets say for arguments sake I have a business letter with the date to the far right and address to far left. How do I grab the date?
ex:
(space space space space space space space space ) 01/02/2017
Mr Jones
some Address
blah, blah, blah.
Dear....
When ever I have tried to reference where I think the date should be, I end up with an empty value.
Thanks for any thoughts and or suggestions.
This is just one of the tries:
Rectangle rect = new Rectangle(96, 822, 72, 8);
This is harder than you might think.
Content isn't just placed on a page.
It's placed on a box on a page.
Both the content, the box, and the page are allowed to have custom transformations, and rotations.
And then of course there is the issue of how the coordinate system is defined. The origin usually lies in the bottom left corner. But this is again something that can be configured.
I would debug your problem by implementing a simple class that extends SimpleTextExtractionStrategy. In the method eventOccurred you should see events passing by of type TextRenderInfo. Those events contain the text being rendered and the bounding box. Print out the text, and its corresponding bounding box. Then at least you know where iText thinks your content is.

Is it possible to use Interop to select text in a Powerpoint TextFrame by location (top and left offset)?

I'm attempting to automate the basic process of editing text in a TextFrame in Powerpoint via Interop, and I've hit a snag. I need to be able to begin the text editing process at a particular location on screen, and after crawling MSDN I still don't know of a way to do it. The use case boils down to this:
My service receives an X and Y coordinate
I tell Powerpoint to select the shape at that location
I tell Powerpoint to place the blinking cursor at the location it would be if the user had clicked there himself to start editing text.
It's the third step that's tripping me up. Word has RangeFromPoint, which returns a text range. In Powerpoint, though, that method returns a shape. I can use TextRange.Characters() to place the cursor manually within the shape's text range, but that accepts character index values rather than screen coordinates.
Anyone know how to go about this (other than brute forcing in mouse messages via Win32 calls)?
Every bit of text, down to the character level, can be treated as a Range; every text range has .BoundLeft, .BoundTop, .BoundHeight and .BoundWidth properties that return the coordinates of a rectangle that bounds the text range.
For example, this snippet will give you the left coordinate of the third text character in the currently selected shape:
With ActiveWindow.Selection.ShapeRange(1)
Debug.Print .TextFrame.TextRange.Characters(3, 1).BoundLeft
End With
Coordinates are returned in Points. It sounds like you already have a handle on converting screen coordinates to PPT coordinates.

Create a 5 star-rating control with hover images without JavaScript

Is there a way to implement a 5-star rating control, that supports changing the images of the 5 stars upon hover, without the use of Javascript? A click would need to perform a HTTP POST
To get a better understanding I searched for a sample and found http://orkans-tmp.22web.net/star_rating/ (Scroll to "Quick example with SELECT options")
As far as my knowledge of HTML goes, it is not possible to have multiple images / buttons that perform a Post (to know which rating was given by the user), and simultaneously change multiple background images.
Here is an example from CSS3 Secrets
jsfiddle
You can use css selectors to get what you want done without javascript.
You can change the image using CSS. Just apply a class and give it the :hover option.
i.e.
.star:hover
{
color:blue;
}
I assume that you would want all previous stars to change color as well on hover, this would be possible, but quite difficult. We'll start with an image of 5 starts (all highlighted) and an image of a single unhighlighted start. Place five of the unhighlighted starts right on top of each other (set the absolute postion). Adjust the intend of the stars so that each is indented more than the last and they are laid out properly (without actually overlapping each other). Add a CSS on hover that's different for each one. It will need to replace the image with the 5 stared highlighted image. The width will need to be set so that only the appropriate number of stars is shown. The z-index will need to be set so that it is on top of the unhighlighted images of all previous stars.
Is it possible 2 use the OnMouseOver and OnMouseOut option to create the same effect of a hover?

Printing to a Dot Matrix Printer

I am printing a rdlc report to Dot matrix printer using this code . The report is in the format of a bill receipt. What i want is that the printer should stop exactly at the point where the receipt is fully printed (i.e. the end of the text to be printed) and not take in the rest of the paper and print nothing on it.
As loads of receipts are to be printed and there can be long queues, it will be time consuming if the end user has to reload the paper (which has been wasted) back to the printer. Hence i am looking for way by which the printer can stop the paper intake as soon as the text to be printed is complete.
It sounds like what you're asking for is how to print receipts as a continuous stream, instead of page by page. The code you linked to is entirely page driven and page oriented. You can work within a page-dominated view system, but you're going to have to do extra work.
You should be able to print multiple things on one page by changing the PrintPage code to output more than one image chunk per page. You will have to manage the offset of each rectangle to place the 2nd image below the 1st, and you will have to figure out what you want to do with the next report page does not fit on the space remaining on the current page. I expect the output will be clipped to the current page, so if you draw outside the page boundaries (past the end of the page) nothing will be output.
You could choose to advance to the next page when the next report image does not fit in the space remaining on the current page.
Or, you could print as much as will fit on this page, and then print the rest of that report image on the top of the next page. To do this, you will need to calculate the intersection of the remaining space on page 1 and the report image rectangle, and save the height of that intersection. End the page. When page 2 rolls around, print that same report image again, but this time offset the output rect by the height of the rectangle that was printed on the previous page. This is assuming a clipping rectangle is already in place on the print device handle (which is very likely).
The downside of splitting a report across pages like this is that you may end up with graphs or even lines of text that are cut off or split between pages. These will be hard to read. If you know the font height and line spacing and how the report is laid out I suppose you could make a calculated guess about where the lines of text fall in the output rectangle and round your output rectangle down to the nearest whole multiple of the line height, but this is getting deep into hacky kludge territory.

Adding a footer in itextsharp c# [duplicate]

I am trying to create a pdf document in c# using iTextSharp 5.0.6. I want to add header and footer to every page in OnStartPage and OnEndPage events respectively.
In case of footer there is a problem that the footer is created right where the page ends whereas I would like to be at the bottom of page.
Is there a way in iTextSharp to specify page height so that footer is always created at the bottom.
Thanks!
The page's height is always defined:
document.PageSize.Height // document.getPageSize().getHeight() in Java
Keep in mind that in PDF 0,0 is the lower left corner, and coordinates increase as you go right and UP.
Within a PdfPageEvent you need to use absolute coordinates. It sounds like you're either getting the current Y from the document, or Just Drawing Stuff at the current location. Don't do that.
Also, if you want to use the same exact footer on every page, you can draw everything into a PdfTemplate, then draw that template into the various pages on which you want it.
PdfTemplate footerTmpl = writer.getDirectContent().createTemplate( 0, 0, pageWidth, footerHeight );
footerTmpl.setFontAndSize( someFont, someSize );
footerTmpl.setTextMatrix( x, y );
footer.showText("blah");
// etc
Then in your PdfPageEvent, you can just add footerTempl at the bottom of your page:
writer.getDirectContent().addTemplateSimple( footerTmpl, 0, 0 );
Even if most of your footer is the same, you can use this technique to save memory, execution time, and file size.
Furthermore, if you don't want to mess with PdfContentByte drawing commands directly, you can avoid them to some extent via ColumnText. There are several SO questions tagged with iText or iTextSharp dealing with that class. Poke around, you'll find them.

Categories

Resources