Create images from PDF file pages in C# - c#

I want to get images from PDF file pages. I know that a good solution is to use ghostscriptsharp. It has a special method to get a single page or multiple pages.
GeneratePageThumbs(string inputPath, string outputPath, int firstPage, int lastPage, int width, int height)
Here is my complete code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GhostscriptSharp;
namespace GetPages
{
class Program
{
static void Main(string[] args)
{
GhostscriptWrapper.GeneratePageThumbs(#"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
#"C:\Users\User\Desktop\Test", 1, 3, 130, 130);
}
}
}
But when I use this method I have exception.
ExternalException
Ghostscript conversion error

So i fix this!The problem lies in the fact that 2 parameter should be the name of your image you get as a result, not a path where to save the image!
Here is the code works correctly:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GhostscriptSharp;
namespace GetPages
{
class Program
{
static void Main(string[] args)
{
GhostscriptWrapper.GeneratePageThumbs(#"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
"Example.png", 1, 3, 130, 130);
}
}
}
Thank you!Question is closed.

replace "Example.png" by "Example%d.png" to get all 3 Pages.

Related

I'm trying to use the c# file handle, but it's not available

c# File handler error.I can't find it.
use SafeFileHandle filehandle -> error
I tried to copy it, but it didn't work out well.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.Win32.SafeHandles;
namespace test
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("검색할 경로를 입력하세요.");
string result1 = Console.ReadLine();
Console.WriteLine("파일 확장자를 입력하세요.");
string result2 = Console.ReadLine();
Filehandle file1 = new Filehandle();
file1.FileCheck(result1,result2);
}
}
You need to install the package in your project before you can use it.
dotnet add package Microsoft.Win32.SafeHandles

Comparing multiple XML files

I am re-wording this from an original post I made: I have two XML files, and they are related to a given year each. For example, 18/19 and 17/18. They conform to the same structure and below is small sample from one of these files. What I want is, in C#, to compare all records in these files where the Given Name, the Family Name, the NI Number and the Date of birth are the same, BUT the Learner Ref Number is different. I need to be able to compare, then push only these records into a data table so I can then push them into a spreadsheet (the spreadsheet bit I can do). I currently have the below as a starting block, but am still very much stuck.
Firstly, I have my Import button press for which:
private void Btn_Import_Click(object sender, RoutedEventArgs e)
{
ILRChecks.ILRReport.CrossYear();
}
Then this goes to look at the Class of which eventually pushes the file to my location:
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ILRValidation;
using InfExcelExtension;
namespace ILRChecks
{
internal static partial class ILRReport
{
internal static void CrossYear()
{
DataSet ds_CrossYearChecks =
ILRValidation.Validation.CrossYearChecks(Global.fileNames);
string output = Path.Combine(Global.foldername, "ULIN_Issues" +
".xlsx");
ds_CrossYearChecks.ToWorkBook(output);
}
}
}
And this is the bit I'm stuck on, which is the production of finding the differences:
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ILRValidation
{
public static partial class Validation
{
public static DataSet CrossYearChecks(DataSet ds_CrossYearChecks)
{
return CrossYearChecks(ds_CrossYearChecks);
}
public static DataSet CrossYearChecks(string[] xmlPath)
{
DataSet ds_xmlCrossYear = new DataSet();
return CrossYearChecks(ds_xmlCrossYear);
}
}
}
XML:
<Learner>
<LearnRefNumber></LearnRefNumber>
<ULN></ULN>
<FamilyName></FamilyName>
<GivenNames></GivenNames>
<DateOfBirth></DateOfBirth>
<Ethnicity></Ethnicity>
<Sex></Sex>
<LLDDHealthProb></LLDDHealthProb>
<NINumber></NINumber>
<PriorAttain></PriorAttain>
<MathGrade></MathGrade>
<EngGrade></EngGrade>
<PostcodePrior></PostcodePrior>
<Postcode></Postcode>
<AddLine1></AddLine1>
<AddLine3></AddLine3>
<Email></Email>
<LearnerEmploymentStatus>
<EmpStat>10</EmpStat>
<DateEmpStatApp>2015-09-01</DateEmpStatApp>
<EmpId>153421665</EmpId>
<EmploymentStatusMonitoring>
<ESMType>LOE</ESMType>
<ESMCode>4</ESMCode>
</EmploymentStatusMonitoring>
<EmploymentStatusMonitoring>
<ESMType>EII</ESMType>
<ESMCode>4</ESMCode>
</EmploymentStatusMonitoring>
</LearnerEmploymentStatus>
<LearningDelivery>
<LearnAimRef></LearnAimRef>
<AimType></AimType>
<AimSeqNumber></AimSeqNumber>
<LearnStartDate></LearnStartDate>
<LearnPlanEndDate></LearnPlanEndDate>
<FundModel></FundModel>
<ProgType></ProgType>
<StdCode></StdCode>
<DelLocPostCode></DelLocPostCode>
<CompStatus></CompStatus>
<SWSupAimId></SWSupAimId>
<LearningDeliveryFAM>
<LearnDelFAMType></LearnDelFAMType>
<LearnDelFAMCode></LearnDelFAMCode>
<LearnDelFAMDateFrom></LearnDelFAMDateFrom>
</LearningDeliveryFAM>
<LearningDeliveryFAM>
<LearnDelFAMType></LearnDelFAMType>
<LearnDelFAMCode></LearnDelFAMCode>
</LearningDeliveryFAM>
<LearningDeliveryFAM>
<LearnDelFAMType></LearnDelFAMType>
<LearnDelFAMCode></LearnDelFAMCode>
</LearningDeliveryFAM>
<LearningDeliveryFAM>
<LearnDelFAMType></LearnDelFAMType>

UI TestStack White Get Value from a DataCell

Does anyone know how to get Vlaue from a ""DataCell(DataGridViewTextBoxCell)"?
I need to get a value from DataCell using its "Name" = "Symbol Row 0" or "RuntimeId" = "42 1966418 3 1 0"".
My current code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.WindowItems;
namespace UI_006
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Application application = TestStack.White.Application.Attach(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Window Calcwindow = application.GetWindow(SearchCriteria.ByText("toto"), InitializeOption.NoCache);
application.WaitWhileBusy();
}
}
}
My UISpy SceenShot:

C# connecting (referencing) couple *.cs files

I have couple questions about referencing methods / variables between two or more *.cs files. I know that there are similar topics, but I still don't quite understand what is going on.
I'm using Visual Studio Community 2015.
So here is the problem. I have 2 files, those files are First.cs and Second.cs. They are saved in completely different, known locations on hard disc.
Inside First.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Forum
{
class First
{
static void Main(string[] args)
{
}
public int GiveMeNumber()
{
return 5;
}
}
}
Inside Second.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Forum
{
class Second
{
int number = // method from file First.cs
}
}
How do I access method GiveMeNumber() from First.cs in Second.cs as assignment for int number? How do I tell my compiler where are those files?
Thanks for any help :)
Like Alex said in his comment.
You can create a solution/project, add existing item, and browse to your first.cs and second.cs.
Mark both files with the public-keyword
for example:
namespace Forum
{
public class Second
{
int number = // method from file First.cs
}
}
Then both class can be used within each other.
So you could do
var first = new First();
var number = first.GiveMeNumber();
you probably want to do it the other way around, because I think you have a console app where your First class has a main-method.
does that help>?

C# PhantomJS Xpath Issues

code:
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using OpenQA.Selenium.PhantomJS;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium;
namespace Scrape
{
class Program
{
static void Main(string[] args)
{
PhantomJSDriver driver = new PhantomJSDriver();
driver.Navigate().GoToUrl("http://www.regmovies.com/theatres/theatre-folder/edwards-west-oaks-mall-stadium-14-rpx-9364");
var nodes = driver.FindElementsByXPath(".//*[#id='content']/div/div/div[2]/div[1]/div/div[2]/div[1]/div/div[1]/h3/a");
foreach(var node in nodes)
{
Console.WriteLine(node.Text);
}
Console.Read();
}
}
}
the xpath is valid because it returns something on firebug
however it doesn't show any text.
whats going on?
however setting the xpath to
var nodes = driver.FindElementsByXPath("//a");
yields the movie names but not the specific xpath. what's going on?
Try waiting for the results to appear before getting the show links:
IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible((By.CssSelector("div.results"))));

Categories