|
Bazewouelle wrote: Somehow the lenght of my file stream is 0.
What is the content of path and the length of C:\test.pdf ?
It's time for a new signature.
|
|
|
|
|
Somehow, the pdf had reset to 0 bytes... (?)
thanks again,
|
|
|
|
|
I see strange things:
1.
you have a something (probably a TextBox) that holds a path, yet you do not use its content. Instead you open a fixed file.
2.
If txtFilePath really is a TextBox, no need to test for Text==null as TextBox.Text never holds null, it always holds a real string ("" if no data is present).
3.
your while loop is bizarre.
4.
what makes you think the FileStream has length zero? there is nothing in the code to indicate that.
BTW: as you have been trying to extract text from a PDF file, which isn't necessarily all text, the whole approach is wrong. You should read the entire file as binary bytes, why not use File.ReadAllBytes() ?
|
|
|
|
|
thanks Luc, this helps too
|
|
|
|
|
If fs.length is 0, then there's nothing in your file.
And I want to point out something Luc said. Your while loop is an infinite loop. You never change munching, so munching will always be true.
Also, while we're talking about it...you don't need to test a boolean against a value within a while loop. You're simply adding an extra test that is unnecessary.
while (munching)
is the same as
while (munching == true)
and uses one less evaluation. If you want to test against false, you would write
while (!munching)
|
|
|
|
|
Thanks for the advice, its appreciated.
|
|
|
|
|
Hallo
I need to display in a TreeView an array with three fields: DisplayName, Value and Level (0-1) which determines if it is a child or a node.
Is there any way in .Net 2.0+ to bind a treeview to an array in the fashion of the ListBox, using DataSource, DisplayMember and ValueMember? (maybe the Level could be managed in a separate way)
I found a code snippet using these properties but it doesn't work, it seems dated back to earlier .Net, 1.1 or 1.0
Or should I go straight using an iteration that loops through the array?
Thanks in advance
|
|
|
|
|
The .Net treeview does not natively support binding like this. While you should indeed iterate though the array creating the appropriate nodes it would probably be best to subclass the treeview and add your own binding code so you can reuse it. Unfortunately the binding code would have to iterate through the datasource, and the structure would have to be fixed.
|
|
|
|
|
|
Greetings,
Here is an interesting question I hope.
In a nutshell, I am trying to convert to UTF8 an 8 bit encoded binary file and display into a RichTextBox.
I am learning to program against the Adobe PDF file format. The PDF Reference 1.7 tells at page 38 (2.2.1) that "PDF files are represented as sequences of 8-bit binary bytes".
In the hope of learning by looking at the source code of PDF documents, I created a very simple hello world text file in Notepad and printed it as PDF with all distiller options turned off. When you rename the test.pdf created as text.txt and view the result in Notepad you see an Ascii rendition of the 8 bit base code. You see enough readable material to understand what's going on.
Now when I load up that test.txt into a richtextbox, a part of the file (the bottom end, is missing). If I attempt to read the PDF directly using a binary reader I get the same results. So viewing the source in Notepad shows more than it does in a RichTextBox.
PDF experts recommends to convert to unicode first before displaying the source of a PDF.
So my question is how does one take a binary file, convert it to UTF8 and display it properly in a RichTextBox (w2k3r2sp2 with vs2010)?
And also, why is the richtextbox not displaying the bottom part of the file? Is there illegal characters in UTF8 or something to that effect?
I know its a lengthy question, and I appreciate your time. I spent all day yesterday in a rather futile effort at this...
Thank you!!
Antoine
|
|
|
|
|
You cannot do this with a PDF file (or many other binary types), as there is no direct correlation between binary data and text data. The structure of a PDF file includes dictionary elements, pointers, fonts, images etc that cannot be rendered directly into text, except with a program that can interpret the structure of the PDF file itself. Take a look at the PDF reference on the Adobe web site[^] for more information.
It's time for a new signature.
|
|
|
|
|
Hi Richard,
Thank you for answering.
I understand that that most text, fonts and graphics objects will be streamed into binary and FlateEncoded. I've read a few chapters so far. However here my purpose is not to retain the binary stream exactness but simply to see the variables names and their order. By converting to UTF8 the whole thing I will for sure break the pdf however I'll get to see somewhat the file structure and the elements name etc.
Please let me know if you can assist.
Thanks,
|
|
|
|
|
Bazewouelle wrote: I will for sure break the pdf however I'll get to see somewhat the file structure and the elements name etc.
Well, you may 'see' some of these things but that will not help with interpreting the content of the PDF. You will need to study the PDF reference document to understand how to extract the actual content from the file. One of the first things to understand is the dictionary structures as mentioned in the reference thus:
To support such random access to individual objects, every PDF file contain a cross-reference table that can be used to locate and directly access pages and other important objects within the file. The cross-reference table is stored at the end of the file, allowing applications that generate PDF files in a single pass to store it easily and applications that read PDF files to locate it easily. Using the cross-reference table makes the time needed to locate a page or other object nearly independent of the length of the document. This allows PDF documents containing hundreds or thousands of pages to be accessed efficiently.
It's time for a new signature.
|
|
|
|
|
Hi Richard,
Yes you are right. In C#, what is the best approach to open up and access the file then? I started to look yesterday and there are streamreaders, binaryreaders, filereaders, etc. I am a bit lost hence this post.
Thanks,
|
|
|
|
|
You will probably need to use a FileStream[^] to access the file, as it allows you to position the file pointer (seek) and read arbitrary amounts of binary or textual information.
It's time for a new signature.
|
|
|
|
|
Starting the right way then
Hey, thanks for the help, Richard, I appreciate it.
Best regards,
Antoine
|
|
|
|
|
i want to set html color code to forecolor of a label, i found the colorconverter.convertfromstring (),
is there any method that takes directly hexa vales to create the color in .net ..thanx
|
|
|
|
|
the Color constructors are documented in MSDN.
|
|
|
|
|
System.Drawing.Color myOrangeColor = System.Drawing.ColorTranslator.FromHtml("#CE560C");
(Remember, google is still out there)
The mind is like a parachute. It doesn’t work unless it’s open.
|
|
|
|
|
Create Procedure MultiTable
As
Begin
Select Name, Email from A
Select X,Y from B
Select J, K from C
End
When We call this Sp return result set in tables as table, table1, table2.
Can we give these table name what we want?
I mean instead of table, table1 it should give A,B..
SqlConnection conn = new SqlConnection("Con String");
SqlDataAdapter da = new SqlDataAdapter("MultiTable",conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
da.Fill(ds);
|
|
|
|
|
You cannot decide name of the resultset inside the SP.
The ADO.NET will give the default name, like
first resultset has name "Table",
second has "Table1", and so on.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Folloowing on from the above answer, ADO.NET assigns the first resultset the name "Table", the second "Table1", the third "Table2" and so on.
Therefore you can map these table names to names of your choosing:
da.TableMappings.Add("Table","A");
da.TableMappings.Add("Table1","B");
da.TableMappings.Add("Table2","C");
|
|
|
|
|
You could also add the tablenames as out parameters in the stored procedure.
@Table Text OUTPUT
,@Table1 Text OUTPUT
AS
BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Table = 'FirstTableName'
SET @Table1 = 'SecondTableName'
-- Insert statements for procedure here
SELECT * FROM A
SELECT * FROM B
END
And in code you just match the tablenames:
foreach (SqlParameter p in dataAdapter1.SelectCommand.Parameters)
{
dataSet1.Tables[p.ParameterName].TableName = (string) p.Value;
}
|
|
|
|
|
You can also bang in a nail with a pair of pliers - doesn't mean its a good idea!
|
|
|
|
|
If you only got pliers, than it's a good idea...
|
|
|
|