Adding an image to a header causes image in document to disappear - c#

I have code that creates a Word document using the OpenXml SDK. Part of the code adds an image to the front page of the document, and everything works perfectly. When I add code to include an image in the header as well, the front page image no longer displays--it doesn't even show a placeholder or a red x indicating the image is not found. The header image does display as expected.
I use the same function (BuildImage) to create the Drawing object in both cases. When building the header, if I comment out the line that appends that drawing, then the front page image remains. If I leave it in, then the front page image disappears.
Header h = new Header();
Paragraph p = new Paragraph();
Run r = new Run();
Drawing drawing = BuildImage(imageRelId, "logo_small.jpg", 150, 47);
r.Append(drawing); <-- This line causes the issue. If skipped, the image appears on front page
p.Append(r);
h.Append(p);
I have verified the document.xml, header.xml, all _rels files, etc after unzipping and everything looks fine to me. The image paths and media folder look good as well. If I do a comparison of the document.xml with and without the header image in the Word file, they are identical. I have no idea why the front page image will not show up.
I'm not sure if something changed in Word recently because everything did use to work using this code that has been untouched for over a year. This just started happening about a week ago.

Related

How to set image width when adding to a MigraDoc document?

I'm generating a PDF file with MigraDoc. Now I need to add an image to the PDF, but if the image is bigger than the page, it is cut, as if part of it is outside the page. I tried to set the image width to a smaller size, but It's not working properly :
var sec = doc.AddSection();
var p = sec.AddParagraph();
var img = p.AddImage(imgFile);
img.Width = "10cm";
img.LockAspectRatio = true;
But in the result PDF, it seems its ignoring the width I'm setting, It appears with the same size it was before.
Found the solution, it was dumber then I thougt. I was testing in a small console applcation, but I was generating the pdf to "Result2.pdf" and opening "Result.pdf". Sorry. 😳

Page resolution of the printed version of a document printed from a RichTextBox

I have a RadRichTextBox that have a RadDocument loaded. This is then used to print mentioned document using richTextBox.Print().
The main problem is that the resolution of the printed page is tied to the zoom of the document in the viewer (RadRichTextBox), i.e. if I have the document zoomed way out (small pages on screen) the resolution on the printed paper is terrible. On the other hand, if I zoom in, the resolution becomes really good.
Obviously, I want to always print at the best possible resolution, is there a way to achieve this?
In the end I went with a work around that works by saving the scaling, setting it to a high number, then restoring it after printing the document.
Size sf = richTextBox.ScaleFactor;
richTextBox.ScaleFactor = new Size(10,10);
richTextBox.Print(/*... settings ...*/);
richTextBox.ScaleFactor = sf;
This looks weird, as the documents zooms in while the document is printing, but the printed document have a proper resolution.

Top and bottom of Photo captured using CameraCaptureUI is getting stretched

CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.MaxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.HighestAvailable;
StorageFile file = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
This shows up the camera, and I am able to preview and click to capture the image. The captured image is shown in another window over the original camera image windows. I am able to crop and click to save this captured image.
However, right after I click save, the image is getting stretched, and after it is saved, it remains stretched as well. In essence, the image I capture and save is being stretched,
I tried removing the crop and it works fine, but I need the crop feature as well.
What am I doing wrong? Should I be using any other values for these settings?
This was working fine till December if I remember correctly.
Any help here is appreciated. Screenshots added below
, ,

Fast Report Showing Images From Database

Hello everyone who codes. I a working on a project that uses reporting a lot. My problem or i wanna do is: In my folder there are a lot of material images. I am showing material images according to its stock code. For example i have 200 image of my stock parts. 3 of 200 havent got image so their imageUrls are 'null'. Instead of Stock Parts that havent got image, my program shows one before parts image. So i want to do this. If a part hasnt got image , my report wont show image or will show empty white image. I dont know that am i clearly explain my problem. Here is simple code of my report page.
private void Picture1_BeforePrint(object sender, EventArgs e)
{
if ((String)Report.GetColumnValue("Stock_Products.ResimUrl") != null)
Picture1.ImageLocation = ((String)Report.GetColumnValue("Stock_Products.ResimUrl"));
else
{
}
}
You can either try making a white image and saving the link to it as a const and then use that image whenever the url to the part image is null or make a new Bitmap object and fill it with white and use that. The first one is better imo because it's only going to take one variable in your code whilst the bitmap image is going to occupy some lines.

How to add bookmark using MigraDoc?

I want to add Bookmark in my PDF using MigraDoc.
For example: two images on a single page.
1. Images1
2. Images2**
and the same name bookmark will generate.
If I click on image1 bookmark that image will be shown to me. Remember both images are on single page.
MigraDoc creates bookmarks automatically for headings.
To create bookmarks without visible text on the page, you can create headings with a font size of e.g. 0.0001 and white colour.
There is one drawback: up to PDFsharp 1.50 beta 1, these bookmarks jump to the correct page, but not the correct area on the page. So with two images on one page, the bookmarks will not work as intended by the OP.

Categories

Resources