the name 'imagePdfDocument' does not exist in current context - c#

Why I am getting the error "the name 'imagePdfDocument' does not exist in current context."
Can anyone tell me how to fix it and why is this error message showing..
Thanks in advance.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using C1.Win.C1Tile;
using System.Diagnostics;
private void _exportImage_Click(object sender, EventArgs e)
{
List<Image> images = new List<Image>();
foreach (Tile tile in _imageTileControl.Groups[0].Tiles)
{
if (tile.Checked)
{
images.Add(tile.Image);
}
}
ConvertToPdf(images);
SaveFileDialog saveFile = new SaveFileDialog();
saveFile.DefaultExt = "pdf";
saveFile.Filter = "PDF files (*.pdf)|*.pdf*";
if (saveFile.ShowDialog() == DialogResult.OK)
{
imagePdfDocument.Save(saveFile.FileName);
}
}
private void ConvertToPdf(List<Image> images)
{
RectangleF rect = imagePdfDocument.PageRectangle;
bool firstPage = true;
foreach (var selectedimg in images)
{
if (!firstPage)
{
imagePdfDocument.NewPage();
}
firstPage = false;
rect.Inflate(-72, -72);`enter code here`
imagePdfDocument.DrawImage(selectedimg, rect);
}
}

Look what you have to do..... go to reference option of your project and uninstall the one which are identical, there may be same reference with different version.

Related

error in text direction when i try to extract text from arabic pdf file using itextsharp c#

i have problem in my code
i am trying to read text from arabic rtl file using itextsharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
namespace Masmo3
{
public partial class FrmMain : Form
{
string book = null;
public FrmMain()
{
InitializeComponent();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
BtnOpen.Enabled = false;
book = null;
using(OpenFileDialog Ofd = new OpenFileDialog() {Filter= "PDF files (*.pdf)|*.pdf|txt files (*.txt)|*.txt",ValidateNames= true, Multiselect= false})
{
if (Ofd.ShowDialog() == DialogResult.OK)
{
iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(Ofd.FileName);
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= reader.NumberOfPages; i++)
{
sb.Append(PdfTextExtractor.GetTextFromPage(reader, i));
book = sb.ToString();
}
reader.Close();
}
}
BtnOpen.Enabled = true;
}
}
}
this code show my text like "ﻢﯿﺣﺮﻟا ﻦﻤﺣﺮﻟا ﷲ ﻢﺴﺑ" its wrong because its rtl language the correct way "بسم الله الرحمن الرحيم"
what i can do to get correct text direction ?
"بسم الله الرحمن الرحيم"
please use ColumnText object to set the DIrection to be RTL
CT.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
Good luck bro

Trying to downoad images from a website but the loop never end why?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using HtmlAgilityPack;
using mshtml;
namespace Extract_Images
{
public partial class Form1 : Form
{
private string[] linkstoextract;
private int numberoflinks;
private int currentLinkNumber = 1;
private string mainlink;
private WebClient client;
private WebBrowser webBrowser1;
public Form1()
{
InitializeComponent();
webBrowser1 = new WebBrowser();
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
label1.Text = "Number of links: ";
mainlink = "http://www.test.com";
numberoflinks = 211;
ProcessNextLink();
}
private void ProcessNextLink()
{
if (currentLinkNumber < numberoflinks)
{
currentLinkNumber++;
string linktonav = mainlink + "index"+currentLinkNumber.ToString() + ".html";
webBrowser1.Navigate(linktonav);
}
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
ProcessImagesFromDocument();
ProcessNextLink();
}
private void ProcessImagesFromDocument()
{
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
if (bmp != null)
{
bmp.Save(#"d:\files\savedlinks\" + img.nameProp);
pictureBox1.Image = bmp;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
In the part:
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
if (bmp != null)
{
bmp.Save(#"d:\files\savedlinks\" + img.nameProp);
pictureBox1.Image = bmp;
}
}
Even if the bmp is not null after one iteration i'm getting exception on the bmp.Save line: Illegal characters in path
And i see in nameProp 395937.thumb?d=1348638415
The other problem is if i'm not using the lines:
bmp.Save(#"d:\files\savedlinks\" + img.nameProp);
pictureBox1.Image = bmp;
If i delete this two lines and using break point on the line:
if (bmp != null)
It will keep stop on this line for ever it will never stop it will keep stop on this line over and over again it will not stop on the foreach but only on this line.
What i want to do is to download from each link the images and also to make it optional to download specific images types like only jpg or only png.
Illegal characters in path error is because your file name is not a valid file name to save because it has invalid character like: '?'
Why the loop is endless, this need more debugging, Debug your code step by step, check the number of images on the first loop,
is it a huge unexpected number of images?
does the number increase on each loop? -> this may be a referencing issue.

How to display image in Excel

i am doing a WPF application to import my image from my folder into excel using c#. I had been successful with using microsoft excel but i would like to know if it is possible to view the file if the user does not have microsoft excel installed? Below is the code which i tried converting the image to a String but it does not display in the excel.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ExcelOpenXMLBasics;
//----------------------------------
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using Microsoft.Win32;
//----------------------------------
namespace WpfApplication2
{
public partial class Window2 : Window
{
List<String> stringValue;
List<int> intValue;
string Imagefile;
public Window2()
{
InitializeComponent();
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
}
private void btnCreateBasicWorkbook_Click(object sender, RoutedEventArgs e)
{
this.CreateBasicWorkbook("try7.xlsx", true);
}
private void CreateBasicWorkbook(string workbookName, bool createStylesInCode)
{
#region select file
OpenFileDialog fileChooser = new OpenFileDialog();
fileChooser.Filter = "image files (*.png)|*.png|All files (*.*)|*.*";
fileChooser.InitialDirectory = #"C:\";
fileChooser.Title = "Check if the image has been saved into PC disk";
bool? result = fileChooser.ShowDialog();
Imagefile = fileChooser.FileName;
#endregion
#region 1
DocumentFormat.OpenXml.Packaging.SpreadsheetDocument spreadsheet;
DocumentFormat.OpenXml.Spreadsheet.Worksheet worksheet;
System.IO.StreamReader styleXmlReader;
string styleXml;
spreadsheet = Excel.CreateWorkbook(workbookName);
if (spreadsheet == null)
{
return;
}
if (createStylesInCode)
{
Excel.AddBasicStyles(spreadsheet);
}
else
{
using (styleXmlReader = new System.IO.StreamReader("PredefinedStyles.xml"))
{
styleXml = styleXmlReader.ReadToEnd();
Excel.AddPredefinedStyles(spreadsheet, styleXml);
}
}
Excel.AddWorksheet(spreadsheet, "Test 1");
worksheet = spreadsheet.WorkbookPart.WorksheetParts.First().Worksheet;
#endregion
//BitmapImage _Image = new BitmapImage(new Uri(#"C:\Users\ifcdu1\Desktop\limin.PNG"));
//string _img = _Image.ToString();
//#"C:\Users\ifcdu1\Desktop\limin.PNG"
//byte imageArray1 = File.ReadAllBytes(#"C:\Users\ifcdu1\Desktop\limin.PNG");
byte[] imageArray = System.IO.File.ReadAllBytes(Imagefile);
string base64ImageRepresentation = Convert.ToBase64String(imageArray);
//string test = Imagefile;
//byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(test);
//string base64String = System.Convert.ToBase64String(bytes);
//Console.WriteLine("Base 64 string: " + base64String);
Excel.SetCellValue(spreadsheet, worksheet, 1, 1, base64ImageRepresentation, true);
#region 2
worksheet.Save();
spreadsheet.Close();
System.Diagnostics.Process.Start(workbookName);
#endregion
}
}
}
So if the user has Excel the image will show. Make it so that if the image does not show (there is no Excel) the image opens in something else like pain, or whatever program you want the image to be in.

C# Using Youtube API - How do I check the last time a particular user uploaded a video to Youtube?

I know how to upload a video to Youtube using Youtube API within C#
But I'd like to use the Youtube API to return a date when a particular user last uploaded a video.
My code for uploading a video using C# is below, but I really don't know how to do the above???
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.GData.Client;
using Google.YouTube;
using Google.GData.Extensions.MediaRss;
using Google.GData.YouTube;
using Google.GData.Extensions.Location;
namespace UploadLimit
{
public partial class Form1 : Form
{
string key = "somegarbage";
string appName = "SlowUpload";
string username = "blarg";
string password = "blarg";
public Form1()
{
InitializeComponent();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
txtFile.Text = dialog.FileName;
}
private void btnUpload_Click(object sender, EventArgs e)
{
YouTubeRequestSettings settings = new YouTubeRequestSettings(appName, key, username, password);
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "My Test Movie";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(txtFile.Text, "video/quicktime");
Video createdVideo = request.Upload(newVideo);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UploadLimit
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
You can get all the user's videos and get the latest date:
var videos = new YouTubeRequest().GetVideoFeed(userId).Entries
DateTime lastUploadDate = videos.Max(video => video.YouTubeEntry.Published)
To get the actual video's title:
var lastVideo = videos.Where(video => video.YouTubeEntry.Published == lastUploadDate).First();
var name = lastVideo.Title

Access Violation runtime error when getting WebBrowser .Url property

Getting an "Access Violation" runtime error when trying to get a WebBrowser's .Url property in an Outlook Add-In I'm writing. Need some help on how to get past this please. Research indicates I may need to set "FullTrust" permissionset, have tried that with no success.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security;
using System.Security.Permissions;
namespace MyAddin1
{
public partial class authForm : Form
{
public string currentUrl;
public authForm()
{
InitializeComponent();
}
private void formLoaded(object sender, EventArgs e)
{
WebBrowser browser = new WebBrowser();
browser.Location = new System.Drawing.Point(0, 0);
browser.Width = 870;
browser.Height = 510;
browser.Navigate("https://www.yammer.com/dialog/oauth?client_id=<redacted>&response_type=token");
browser.Show();
//runtime error occurs on following line
currentUrl = browser.Url.ToString();
browser.Url = new Uri("http://www.yahoo.com");
browser.Navigated += new WebBrowserNavigatedEventHandler(checkForToken);
this.Controls.Add(browser);
}
private void checkForToken(object sender, EventArgs e)
{
MessageBox.Show(currentUrl);
}
}
}
browser.Url is initially null, Change your code as below.
if (browser.Url != null)
{
currentUrl = browser.Url.ToString();
}

Categories