I have doubt in convert TextFrame into image, please help to do this in VSTO or OpenXmlSDK with/without third party library, if any one have idea, please share with me....
Word.Shapes shapes = Globals.ThisAddIn.Application.ActiveDocument.Shapes;
foreach (Word.Shape shape in shapes)
{
if (shape.TextFrame.HasText >= 1)
{
//how to convert TextFrame into as a Image
}
else
{
shape.Delete();
}
}
Thanks in Advance,
Saran
One way would be
Get x,y coordinate of textbox in word doc (use vsto)
Save file to pdf or xps (use vsto)
Convert xps or pdf to image (use any free third party library)
Extract image image using x,y cordinate obtained in step 1. (Use
GDI)
Related
I'm developing a powerpoint vsto addin and I'm trying to export a specific slide as an image using Slide.Export method, But the problem is, the Export method is not embedding fonts. The generated image always have system installed font. Below is the code snippet i'm using:
private void SaveSlideAsImage(Slide slide, string filePath, float w, float h)
{
if (File.Exists(filePath))
File.Delete(filePath);
slide.Export(filePath, "jpg", (int)w, (int)h);
}
Can anyone help me how I can export a specific slide as image an which should have embedded font ?
Update
This is how the slide look like before export:
And this is how it look like after export. So you can see text is not matching and it could be because of embedded font
Update 2:
I have copied the only slide and then exported it. Now text is exported fine but now you can see font is different then the font in slide
and this is what i manually save and exported from powerpoint save as. Everything looks exact match of what's in slide:
I would like to create Image from Barcode128 using iText7.
In iText5 it works well like as follows:
var barcode = new Barcode128();
...
System.Drawing.Image image = barcode.CreateDrawingImage(Color.Black, Color.White);
However there is no such method CreateDrawingImage in iText7. How do I achieve the same functionality in iText 7? Could you please advise?
UPDATE:
Such functionality has been indeed removed from iText7 and it was a conscious decision. iText7 provides all the means to put a barcode to a PDF document, however generating an image is a different story.
I am trying to convert an image file to a PDF document with a defined page size (letter size).
Currenlty I am able to convert an image to a PDF document without defining any page dimensions (default dimensions of the PDF is the image size). I would like to define the page dimensions on the creation of the document, and place the image on that page (possibly with margins).
The following code snippet shows how I am currently converting an image file to a PDF document without setting any dimensions for the page:
async static Task<bool> ConvertImageToPDF(TestFile file)
{
pdftron.PDF.PDFDoc pdfdoc = new PDFDoc(); //Initialize a new PDF document
pdftron.PDF.Convert.ToPdf(pdfdoc, file.InputFile); //Use the Convert.ToPdf to generate the file from the image file
await pdfdoc.SaveAsync(file.OutputFile, SDFDocSaveOptions.e_linearized); //Save the PDF document generated from the conversion
pdfdoc.Destroy();
pdfdoc = null;
}
Any help or direction for assigning dimensions (letter size) to a PDF page and inserting the image file in that page would be more than welcome.
If ToPDF is given an image then PDFNet will query the DPI information of the image metadata and make page dimensions to match the DPI and resolution of the source.
If you like, you can always post-process the PDF generated by ToPDF.
Or, you can follow the AddImage sample code to do everything yourself.
https://www.pdftron.com/pdfnet/samplecode.html#AddImage
I'm working on a project which generally is collecting data and drawing results in charts. (Using C#) I need to save my charts in a PDF file. My question is, how to save charts in a PDF file without loosing resolution? My point is how to draw vector graphics instead of raster graphics?
I tried iTextSharp to create PDF file but the result is not satisfying at all!
I'm new here, so I'm not able to upload pictures.
Here is the result after saving my file:
https://www.dropbox.com/s/ruwtc82hfosxk6y/Test.pdf?dl=0
Here is the PDF that I need to create:
https://www.dropbox.com/s/jvu5uu069imo9xc/nir%20well%20abfar.pdf?dl=0
There are two ways I know of to get high-quality images from your Chart into a PDF.
One is by using vector formats:
Use chart.SaveImage with one of the three emf formats.
Convert the resulting emf file to wmf
Insert the wmf file into your iTextSharp document.
1 and 3 are one-liners. But step 2 is not. In fact I haven't found a working c# solution at all. The best was a weird reference to an edit that has disappeared here ..
If you can use some other program to do the conversion you will get nice results like this demo pdf file.. I used Illustrator for the conversion.
Two: If you can't get step 2 to work, you can still get nice results, if you use raster images with a nice and high resolution. Here is how to do it:
First we hide the Chart, so we don't scare the user. Then we make it as large as we want the output to be. Then we DrawToBitmap and finally we reset the chart again..:
Size s = chart1.Size;
chart1.Hide();
// pick your size in pixels
// I simply multiply my screen size..:
chart1.Size = new System.Drawing.Size(s.Width * 5, s.Height * 5);
using (Bitmap bmp = new Bitmap(chart1.ClientSize.Width, chart1.ClientSize.Height))
{
// you should set the resolution,
// although I didn't find a way for iTextSharp to use it visually
bmp.SetResolution(600, 600);
using (Graphics G = Graphics.FromImage(bmp))
{
G.SmoothingMode = SmoothingMode.HighQuality;
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
chart1.DrawToBitmap(bmp, chart1.ClientRectangle);
bmp.Save(yourImageFile, ImageFormat.Png);
}
}
chart1.Size = s;
chart1.Show();
You could also use SaveImage and save a few lines, but you can't set the resolution of the png file there and it will be saved at the currnt screen resolution, which is 96dpi here..
Now you have a large image and will probably have to scale it down in iTextSharp:
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(yourImageFile);
img .ScalePercent(15); // scale to fit your needs..
doc.Add(img );
Note that the legend and the labels get very small this way, so you may have to enlarge them before saving. I also found that, when scaling down, the image is rather bright until you zoom in..
Here are two screenshots, one from the chart, the other from the pdf documnet after zooming in a lot (300%)..:
I want to copy some text or area with (x,y) from existing pdf and paste it to a new pdf.
i am using pdfsharp.how to do this?
can anybody help?
If you want to extract text, look at these threads:
C# PDFSharp: Examples of how to strip text from PDF?
C# Extract text from PDF using PdfSharp
If you want to extract an image of the page (or a part of it), look at this thread:
Export PDF to JPG(s) in C#