Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Convert string from RenderPageToString |
Post Reply |
Author | |
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
Posted: 28 Nov 05 at 6:57AM |
I'm new to C# and I'm new to iSEDQuickPDF, so my question
may be easy to answer by more experienced programmers. How can I convert the string output from RenderPageToString to a System.Drawing.Image? Could anybody suply some sample code? If RenderPageToVariant works with C#, I also would like to know how to convert variant to Image. Thanks in advance for any help. |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Pirmin!
If you want to create an image from a document-page why not use RenderPageToDocument? It works fine. Best regards, Ingo |
|
Cheers,
Ingo |
|
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
|
Hi Ingo! Yes, you are right. The Function RenderDocumentToFile works very well. I have used it till now. But what I want is, displaying the page in a form (kind of a viewer) and I think it's not necessary to save the picture as a file on the hard disk and load it again into the RAM for displaying it. I will do this, if I won't find a better way. I think the functions RenderPageToStream, RenderPageToString and RenderPageToVariant are just made for what I'm trying to. RenderPageToStream is only available in the Delphi edition. RenderPageToVariant sounds to me like something for visual basic (I'm not sure). So my favorite candidate is RenderPageToString to use. As a trial I have saved a page as a BMP-file and than I have rendered the same page to a string. When I opened the BMP-file I saw the content. The string with the return value from RenderPageToString had the same content in the beginning. This already looked promising to me. But the string only showed five characters. First I thought, no more characters are displayed because of a debugger issue. But than I read the property Length of the string and I saw that also the length only is 5. So something must be wrong with what I'm trying to do or the function does not work. If it would work I still have no idea how to convert a string with the bitmap content to an Image from a PictureBox. Best regards, Edited by Pirmin |
|
chicks
Debenu Quick PDF Library Expert Joined: 29 Oct 05 Location: United States Status: Offline Points: 251 |
Post Options
Thanks(0)
|
Don't know if this will help you at all, but here's an example of a viewer in VB6 that uses RenderPageToVariant():
http://www.geocities.com/sea_sbs/files/VBViewPDF.zip |
|
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
|
Thank you chicks, Perhaps I can modify the code from VBViewPDF to use it in C#. Maybe I still will try it this week. But I'm quite sure, that this wouldn't help me. I have observed (using a HEX-Editor) that the position of the first zero in the BMP-file is the position where the string ends. It seems to me that the bitmap stream produced by RenderPageToString, might have been written correctly to the memory where the string points to. By the way, is it possible to view the memory of a string variable in C#? I could not find out how. If I could do that, I would see if my theory is correct. When I use the string function ToCharArray, the resulting char array also only gets the size of the string length (5 in my example). I think, without getting a string with the correct property Length, there is no way to convert it to an Image. Only when I succeed in doing this, I can go further, looking for a way to convert it. So the next thing I will do is open a ticket at www.isedquickpdf.com asking if there could be an error in the function RenderPageToString. Best regards, |
|
Michel_K17
Newbie www.exp-systems.com Joined: 25 Jan 03 Status: Offline Points: 297 |
Post Options
Thanks(0)
|
Hi Pirmin,
Unfortunately, it is highly unlikely that you will get an answer from iSed. They have not replied to any messages, postings or e-mails in the last 3 months. Just thought you should know before you get your hopes up. |
|
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
|
Hi Michel_K17 You are right, my ticket is still open. Unexpectedly I have found a part of a solution for my first problem (getting the length of the returned string from RenderPageToString). Till now I have worked, using the DLL version. I thought, there must be something wrong. A DLL made for C++ can not make strings with a lenght information. Only the position of the string terminator (zero) is used to show where it ends. With this in mind, I wanted to do my trials with the ActiveX library. When I tried the function StringResultLength after RenderPageToString, it got exactly the same number as the size of the BMP-file produced with RenderDocumentToFile. I see, I have to say RTFM to myself. My first attempts afterwards let me assume that, when I want to access the string part after the zero, the garbage collector already has killed it. So next week in my spare time, I must find out, how to get the entire data of the string. Best regards, |
|
Michel_K17
Newbie www.exp-systems.com Joined: 25 Jan 03 Status: Offline Points: 297 |
Post Options
Thanks(0)
|
Hi Pirmin,
Yip! I always tend to check the manual last too! For my VB6 project, I switched from the DLL to the ActiveX version as it was much better behaved: With ActiveX, the library it does not take down my app if it crashes, which used to happen with an older version. |
|
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
|
Hi Folks, Finally I found the solutions to my problems. Last night I couldn't sleep until I got it. As I thought, the reason for the first problem was the assignement of one string type to a different one. In the file iSQP0511DLLSource\DLLiSED.pas I saw, that the Delphi return type of the function iSEDRenderPageToString was PChar, which is only a pointer to characters with no length info. new import: old implementation of the wrapper function: new implementation of the wrapper function: Using this patch, the function RenderPageToString does, what it is expected to do. The only drawback of my patch is, the library has to be compiled slightly different as described by iSED (using the option /unsafe). Maybe later on, I will try to the job better. For now the result is satisfactory to me. The second problem (assigning the string to an Image object) was just finding the proper functions. Hints I have found in the file of which chicks posted the URL. Thanks! To show the effects of the original iSEDQuickPDF 5.11 DLL wrapper for .NET and the patched one, you can write a C# console program (call it Test.cs) and put it to somewhere what I will call the working directory. Don't forget to replace the parameter string for the function UnlockKey with your unlock key. From the file iSQP0511DLL.zip extract iSEDQuickPDF.dll and iSQP0511DotNet.cs to your working directory. Rename iSQP0511DotNet.cs to iSQP0511DotNet0.cs and make a copy of it, named iSQP0511DotNet1.cs. To iSQP0511DotNet1.cs apply the patches described before. Then create a batch file (you may call it build.cmd) in the working directory with the following content: Execute build.cmd, which should create the two files Test0.exe and Test1.exe in the working directory. Copy a PDF file you like to the working directory (don't use the "iSEDQuickPDF 5.11 Reference Guide.pdf") and rename it to Test.pdf. Test0.exe only will produce Page_1_of_Test_A.bmp (and some temporary files) and trows an exeption while Test1.exe will output Page_1_of_Test_A.bmp and Page_1_of_Test_B.bmp. If you compare the two BMP-files you see, they differ in a few bytes. I don't know why. When you open the two BMP-files with a Graphic Viewer, you won't see any difference. As I indicated before, the file "iSEDQuickPDF 5.11 Reference Guide.pdf" causes problems. Page_1_of_Test_A.bmp produced from it, in a Graphik Viewer shows only a blank page, while Page_1_of_Test_B.bmp appears to be a good bitmap. Edited by Pirmin |
|
frankjr
Beginner Joined: 29 Oct 05 Location: United States Status: Offline Points: 4 |
Post Options
Thanks(0)
|
Thank you Pirmin for your analysis and work..I found myself headed down the exact same trail, and then decided to check here before I jumped off the cliff... For me to compile the wrapper, I needed one more necessary change in the dll import section... old import: new import:
Forgive me if I am wrong, but that is what I had to do to get it to compile. I took the liberty of using Emacs and a macro to modify each and every call the returned a string as Pirmin has told us to do. The newly modified wrapper is as follows: ----- CUT HERE ----- //====================================================================================== Edited by Michel_K17 - 17 Nov 07 at 11:37AM |
|
Frank Busalacchi Jr
www.krankensoftware.com |
|
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
|
Hi Frank A happy new year and thank you for your post. I haven't seen it before, sorry. In the last days I have been trying other iSED functions in the C# environment. I'm wondering if all my problems with the library for C# do not exist in the Delphi environment. Maybe for the Delphi environment the code has been tested more thoroughly. |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Pirmin!
Perhaps i'm wrong but ... ;-) QuickPDF-functions are separated modules which you can bind with your code... The functioncode stay the same. So i don't think that C# should be a problem. For example i've made dlls including quickpdf-functionality and they were used in .net-environments (without problems). Your second point (while rendering always the first document was rendered): You must get the id of the second document and have to change the actual documents with this id then it should work. |
|
Cheers,
Ingo |
|
frankjr
Beginner Joined: 29 Oct 05 Location: United States Status: Offline Points: 4 |
Post Options
Thanks(0)
|
Primin, If you cut and paste the wrapper code I posted, and compile it with your app, does it not work? Since implementing the change you pointed out (BSTR instead of C# strings 0 terminated etc), the library seems to work wonderfully for me. All the issues I was having have disappeared.
Of course if you use the ActiveX version of the library, you should have no issues either because the activeX version uses BSTR. -Frank |
|
Frank Busalacchi Jr
www.krankensoftware.com |
|
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
|
Hi Frank, I have tried your wrapper code. Best regards, Edited by Pirmin |
|
Pirmin
Team Player Joined: 28 Nov 05 Status: Offline Points: 28 |
Post Options
Thanks(0)
|
The "more problems" in my last post have been just programming errors of myself. So I'm more more happy with the library now.
|
|
frankjr
Beginner Joined: 29 Oct 05 Location: United States Status: Offline Points: 4 |
Post Options
Thanks(0)
|
I'm glad things are working for you Pirmin. Since you pointed out the BSTR issue, and I modified the wrapper code to implement your suggestion, the library has been working beautifully for me.
-Frank
|
|
Frank Busalacchi Jr
www.krankensoftware.com |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store