|
Has it occurred to you that when you drop out of the while loop above that line then m_Stream.Position will be equal to the length of the stream ... it's why you drop out of the loop
|
|
|
|
|
hi i want to know , how i can get each page total rows . using itextsharp dll .
i want to put all of my code onStartPage
public class MyPdfPageEventHelpPageNo : iTextSharp.text.pdf.PdfPageEventHelper
{
public override void OnStartPage(PdfWriter writer, Document document)
{
}
}
ty for any help
|
|
|
|
|
Is it a PDF you are reading, or one that you are creating, that you want the page count for?
If you are reading a PDF you could get gate the page into a string(this example will extract page 1).
string page = PdfTextExtractor.GetTextFromPage(new PdfReader(fileName), 1,new SimpleTextExtractionStrategy());
Then count the new line characters in the string.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
modified 2-May-14 8:11am.
|
|
|
|
|
No , the pdf that im creating.
|
|
|
|
|
In which case I guess you have answered your own question.
If you are creating it yourself you will be inserting lines, therefore you will know how many lines you have inserted into the PDF.
Or to put it another way - if you are creating the PDF why is it that you don't know how many lines are in the PDF?
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
i know how many lines it'll write on pdf file but bcz of the different height between lines i can't figure out how many line first page can contain , and how many other lines second page can contain .
let's say i have 200 line with different height , how should i know how many page it takes . it sure that it depends on the line height .
|
|
|
|
|
There are a number of ways to do this – what I did, as I knew that I had the same font size on the page , was to print 100 lines at that font size to see how many pages that took.
If you are using different font sizes then this will probably not work for you – at which point I would suggest google.
What I would look for is to see if anyone has a formula for calculating the line height – there will be a number of considerations such as DPI that may need to be taken into account.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hi,
we are developing an mobile application and we have used WCF service to fetch SQL Server data through online.
We are trying to authenticate each WCF Service call(server) by passing headers from client (mobile application). For this we have generated a token and passed the same in headers of each client call.
We have stored the tokens in HttpRuntime.Cache. But after few minutes [in idle mode] the cache entry is cleared.
Note: If continuously server and client communicates, it works perfectly.
Below is our WCF service Cache code:
HttpRuntime.Cache.Insert(key, Token, null, DateTime.Now.AddHours(1),Cache.NoSlidingExpiration);
if some other better solution available, kindly suggest how we can save the tokens alone in server and authenticate the same from client for each service call.
|
|
|
|
|
|
Okay, so I'm a self-taught programmer and have been brushing up on all the 'boring' bits that CS students do that most of us self-taught ignore. Things like Algorithms and Data Structures (particularly). So I found a nice exercise book that explains how algorithms work, but then leaves the implementation to the reader.
This works well for me as I'm the kind of person for whom knowledge 'sticks' better if I can "figure it out for myself".
So, I've just finished the Chapter on Sorting and quite easily managed to implement working Bubble Sort, Radix Sort, Mergesort etc. I really struggled getting Quicksort to work though - lots of out of bounds errors that I found hard to track down. So, now I do have it working - I'm wondering whether I just set about coding the algorithm (I'm using C#) the wrong way in the first place.
So, my question, I'll post my code below, and I'd really appreciate it if you guys could tell me (mentor style I guess) how I could have done a better job if I did it again. What I don't want is a long discussion of "you chose a silly pivot value", remember I implemented this from an exercise and that told me explicitly to use the left-most value of each sub-array as the pivot for each partition.
So, here's the code that basically creates the object and calls the sort method:
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Exercise 24.10 - Quicksort\n\n");
Quicksort sort = new Quicksort(12);
Console.WriteLine("Unsorted: {0}\n", sort);
sort.Sort();
Console.WriteLine("\n Sorted: " + sort);
Console.Write("\nPress any key to continue . . . ");
Console.ReadKey(true);
}
}
and here's the object that implements the Quicksort & the partitioning:
class Quicksort
{
private int[] data;
private Random rng = new Random();
public Quicksort(int size)
{
data = new int[size];
for(int i=0; i<data.Length;i++)
data[i]=rng.Next(0,100);
}
public void Sort()
{
recSort(0, data.Length-1);
}
private void recSort(int left, int right)
{
if(left<right) {
int pivot = Partition(left, right);
recSort(left, pivot-1);
recSort(pivot+1, right);
}
}
private int Partition(int left, int right)
{
int i=left;
int j=right+1;
int pivot = data[left];
while(i<j) {
do {
j--;
} while (data[i]<data[j]);
if(i<j)
Swap(i,j);
do {
i++;
} while (data[j]>data[i]);
if(i<j)
Swap(i,j);
}
return j;
}
private void Swap(int i, int j)
{
int temp=data[i];
data[i]=data[j];
data[j]=temp;
}
public override string ToString()
{
StringBuilder temp = new StringBuilder((data.Length*6)+1);
for(int i=0; i<data.Length; i++)
temp.AppendFormat("[{0:00}] ", data[i]);
return temp.ToString();
}
}
Sample output (with debugging turned on) looks like this:
Exercise 24.10 - Quicksort
Unsorted: [64] [48] [79] [43] [75] [54] [81] [94] [75] [66] [57] [61]
SW 64/61: [61] [48] [79] [43] [75] [54] [81] [94] [75] [66] [57] [64]
SW 79/64: [61] [48] [64] [43] [75] [54] [81] [94] [75] [66] [57] [79]
SW 64/57: [61] [48] [57] [43] [75] [54] [81] [94] [75] [66] [64] [79]
SW 75/64: [61] [48] [57] [43] [64] [54] [81] [94] [75] [66] [75] [79]
SW 64/54: [61] [48] [57] [43] [54] [64] [81] [94] [75] [66] [75] [79]
SW 61/54: [54] [48] [57] [43] [61] [64] [81] [94] [75] [66] [75] [79]
SW 54/43: [43] [48] [57] [54] [61] [64] [81] [94] [75] [66] [75] [79]
SW 57/54: [43] [48] [54] [57] [61] [64] [81] [94] [75] [66] [75] [79]
SW 81/79: [43] [48] [54] [57] [61] [64] [79] [94] [75] [66] [75] [81]
SW 94/81: [43] [48] [54] [57] [61] [64] [79] [81] [75] [66] [75] [94]
SW 81/75: [43] [48] [54] [57] [61] [64] [79] [75] [75] [66] [81] [94]
SW 79/66: [43] [48] [54] [57] [61] [64] [66] [75] [75] [79] [81] [94]
SW 75/75: [43] [48] [54] [57] [61] [64] [66] [75] [75] [79] [81] [94]
Sorted: [43] [48] [54] [57] [61] [64] [66] [75] [75] [79] [81] [94]
|
|
|
|
|
Hi all,
In below code, im opening a file selection dialog and then im asking if the user needs to delete a previous file with some data. When i say "Yes" to that the File.Delete() code doesn't work (don't delete the file) and nor gives a exception. What i'm doing here wrong, please?
Thanks.
if (selResult == DialogResult.OK)
{
DialogResult dr = MessageBox.Show("Do you want to delete previous data?", "Delete?", MessageBoxButtons.YesNo);
if (dr == DialogResult.OK)
{
try
{
File.Delete("data.txt");
}
catch(IOException copyError)
{
MessageBox.Show(copyError.ToString());
}
StreamWriter sw0 = new StreamWriter("data.txt", true);
sw0.Close();
}else if(dr == DialogResult.No)
{
MessageBox.Show("Cancelled");
return;
}
|
|
|
|
|
I suspect it is deleting the file, but you're immediately re-creating it after you've deleted it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Tnx for reply.
Yes im creating the file after the deletion coz i to write new data into it. but the new data just appends to the old file. any suggestions?
|
|
|
|
|
Try changing the second parameter of the StreamWriter constructor (append ) to false .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
SO SORRY EVERYONE! itz my bad. I checked the DialogResult as OK, while i have set the dialog to "YesNo" mode. It works.
Sorry again!
|
|
|
|
|
I work for a company that has a software product that operates with a standardized programdata directory/file structure. In that selection of directories and files there are many xml files that has a bunch of information that we dig through when researching to find root cause or trouble-shooting with customers, etc. By the way, I'm a qa test engineer. I want to build a tool (preferably in c# because i'm working on learning it) that has a way to point out the location of an exported or stored \programdata\our_application\data and it does it's thing. This tool would go through the directories and files and pull out specific information/data from the xmls like, what locale the user was in, what mode was the user working in, what worksite, whether or not debugging is turned on, etc. Then it would display this information on a GUI that I'd like to design with possibly checkboxes to turn some of it off if it isn't wanted or some sort of control over what information it delivers. Our Dev and QA teams would keep this handy and when they started to research an issue they'd run it and it would display all the information that we currently have to dig around in directories and xml files for. It would be nice if I could make it where the data items/nodes displayed could be changed in the same GUI when the "send"? button was pushed which would then make changes in the app when run again.
Any suggestions? Location of a sample that I can use to copy? Am I totally using the wrong language? Anything helps!
Thank you in advance for your help.
|
|
|
|
|
This seems a perfectly reasonable tool to use C# for. If I were you, I would write this with Windows Forms because you aren't going to want the added complexity of learning WPF on top of this. In order to query for the files, you would be looking at using something like this to retrieve the XML files (assuming you are looking in a flat directory structure):
DirectoryInfo di = new DirectoryInfo(pathToFolder);
FileInfo[] files = di.GetFiles("*.xml"); In this example, I'm retrieving the FileInfo because we can use this to determine things like when the file was last accessed - this is a handy way to remove files you have already looked at. In order to parse the files, you should probably look into using XLinq (that's XML for LINQ) - if you Google on this, you'll find lots of examples on how to use this.
Good luck with your development, and don't forget to come back if you have particular problems you are stuck with.
|
|
|
|
|
A better syntax for "private protected"?
C# vNext will have a new accessibility modifier. The C# team had first proposed to use "private protected", but maybe someone can find a better syntax for it.
On this survey[^] every syntax that's been proposed so far has been gathered together for everyone to vote on her/his favorite.
WHAT IS THE NEW ACCESSIBILITY MODIFIER ABOUT? ... This post[^] on StackOverflow has a great explanation.
WHERE CAN YOU JOIN THE DISCUSSION? ... Read the motives behind all these proposals - and help shape the future of your favorite programming language - on the CodePlex discussion forum
Go ahead and choose your favorite. The C# team will gathering up answers in mid May.
C# vNext language design - private protected - FamilyAndAssembly[^]
|
|
|
|
|
You forgot the link to CodePlex:
https://roslyn.codeplex.com/discussions/541194[^]
This might be better in the Lounge or Insider News, as it's not really a question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Since the link was already on the survey...
Good point but this is C# related and that's why I didn't mark it as a question.
|
|
|
|
|
Hi all,
y = 2;
string yString = y;
This of course does not work ,Cannot implicitly convert type 'int' to 'string'.
But this is no problem:
y = 2;
string yString = "" + y;
Why??
Regards,
Grooover
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Because the designers of .NET C# decided that the "+" operator between strings ... if the item before the plus-sign is a string ... would automatically invoke conversion of all items to the right of the plus-sign to Type String.
You can see an even more dramatic example of this if you execute:
int v = 1;
Int32 w = 2;
Int64 x = 3;
double y = 4;
float z1 = 5;
Single z2 = 6;
string yString = "" + v + w + x + y + z1 + z2; Yep, it compiles. So, you can infer that ... given a lack of parentheses) arithmetical operator evaluation for the plus sign is "turned off."
If you think this is kind of strange, you may not be alone
“I speak in a poem of the ancient food of heroes: humiliation, unhappiness, discord. Those things are given to us to transform, so that we may make from the miserable circumstances of our lives things that are eternal, or aspire to be so.” Jorge Luis Borges
|
|
|
|
|
Thank You for your explanation,
Learn something every day.
thanks
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Thing of beauty, .NET.
Regards,
Rob Philpott.
|
|
|
|
|
The concatenation operators are replaced by calls to one of the overloaded string.Concat methods. There are versions with string or object parameters, e.g Concat(string, string, string), Concat(object, object, object), and if possible the more efficient (string, string, ...) versions will be used.
This gives us, well me really, the opportunity to play with ILDASM and have a look at what the C# compiler decides to do.
private static String StringConcat(String a, String b, String c) {
return a + b + c;
}
private static String ObjectConcat(String a, int b, DateTime c) {
return a + b + c;
}
and the IL shows the use of the different Concat methods.
.method private hidebysig static string StringConcat(string a,
string b,
string c) cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: call string [mscorlib]System.String::Concat(string,
string,
string)
IL_0008: ret
}
.method private hidebysig static string ObjectConcat(string a,
int32 b,
valuetype [mscorlib]System.DateTime c) cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: box [mscorlib]System.Int32
IL_0007: ldarg.2
IL_0008: box [mscorlib]System.DateTime
IL_000d: call string [mscorlib]System.String::Concat(object,
object,
object)
IL_0012: ret
}
Alan.
|
|
|
|
|