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!
SaveToString corrupt with Image |
Post Reply |
Author | |
piehl
Beginner Joined: 07 Oct 08 Location: Germany Status: Offline Points: 5 |
Post Options
Thanks(0)
Posted: 22 Oct 08 at 8:38AM |
Hello Forum,
I m using the iSEDQuickPDF.dll 5.11 (file version 4.42.1.1) in a C# ASP WebApplication. A generated pdf can either be saved as a file or directly displayed into the web browser. To display a pdf into browser, I used a MemoryStream (no physical file needed!). Unfortunatly, the SaveToStream method is only available in Delphi, so I found the following workaround: First I invoke the method SaveToString, afterwards following the conversation from string to byte[] string sPdf = QuickPdfNativeMethods.SaveToString(); MemoryStream mem = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(sPdf)); This already works, provided that no Image is placed into the document! Using SelectImage(AddImageFromFile/String(...)); and DrawImage(); produces a corrupt stream rather a corrupt or early ending string via SaveToString(); Is this behaviour a already known? How can I get a String (Stream) from my active document containing a Image? Using latest version 6.02 Beta throws an exception when caling SaveToFile. Thanks for help Regard Torsten Piehl |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Torsten,
first a warm welcome here! SaveToFile is a really main function - so i don't think that it's a problem with the version 6.02 itself. Perhaps you want to publish the relevant piece of code here - so we can have a look? In the library section we have a dll-version 5.22, too. Perhaps you want to try it. Actually few members from this forum are working a lot on the library. Digital signing, aes-encryption and better rendering are main points. Soon we'll upload new compiled versions - so please stay tuned. Best regards, Ingo |
|
piehl
Beginner Joined: 07 Oct 08 Location: Germany Status: Offline Points: 5 |
Post Options
Thanks(0)
|
Hello Ingo,
hello Forum first of all, thanks for your fast reply. The following piece of code demonstrates the problem I have. The code is placed in a C# WebApplication and wil be invoked by clicking a LinkButton. int docId = QuickPdfNativeMethods.NewDocument(); QuickPdfNativeMethods.SetMeasurementUnits(MeasurementUnit.Millimeters); QuickPdfNativeMethods.SetOrigin(Origin.TopLeft); QuickPdfNativeMethods.SetPageSize("A4 Landscape"); QuickPdfNativeMethods.DrawText(10, 10, "Hello World:"); // ** optional including image int imgId = QuickPdfNativeMethods.AddImageFromFile(@"images\example.jpg", 0); QuickPdfNativeMethods.SelectImage(imgId); QuickPdfNativeMethods.DrawImage(50, 50, 113, 52); // ** QuickPdfNativeMethods.SaveToFile(@"C:\Temp\Test.pdf") string sPdf = QuickPdfNativeMethods.SaveToString(); Either generation without including a image Everything works fine. Output is a Test.pdf and a sPdf string for further Web operations Or generation with including a image v5.11: generates a correct Test.pdf file, but a incorrect string calling SaveToString() v5.22: generates a correct Test.pdf file, but a incorrect string calling SaveToString() v6.02: generates a correct Test.pdf file, throws an exception caling SaveToString() I compared the output string with an image, against the output string without an image (v511, v522) The following difference attract attention: string without image: "%PDF-1.4\n%âãÏÓ\n1 0 obj\n<<\n/Type /Pages\n/Count 1\n... ...\n>>\nstartxref\n818\n%%EOF\n" string with image: "%PDF-1.4\n%âãÏÓ\n1 0 obj\n<<\n/Type /Pages\n/Count 1\n... .../Image\n/Width 113\n/Height 52\n/ColorSpace /DeviceRGB\n/BitsPerComponent 8\n/Filter /DCTDecode\n>>\nstream\nÿØÿà" - the string without an image is longer than the one with an image. - the string with an image seems to be truncated. I hope I gave all necessary information to reproduce or to exclude the behaviour. Best regards Torsten |
|
DELBEKE
Debenu Quick PDF Library Expert Joined: 31 Oct 05 Location: France Status: Offline Points: 151 |
Post Options
Thanks(0)
|
I am not an expert in C, but it seem to remember that string in C stop with the first nul char. The data for an image file can contain null chars, perhaps it's the problem.
|
|
piehl
Beginner Joined: 07 Oct 08 Location: Germany Status: Offline Points: 5 |
Post Options
Thanks(0)
|
Hi DELBEKE,
you are right, that´s my assemption too. Thanks |
|
piehl
Beginner Joined: 07 Oct 08 Location: Germany Status: Offline Points: 5 |
Post Options
Thanks(0)
|
Thats what I found out:
Review, trying to get my PDF as a stream for displaying in C# Web Application. Using the SaveToString method to convert the given string into a stream. Problem, if the pdf contains an Image, the method SaveToString provides an truncated string. More precisely, it depends on the Image format! Irrespective of the mode how an Image was added, from file or from string, you get a different behaviour depending on the Image fomat being added. Using a bmp, - the pdf file works fine. - the pdf stream can be open, but the colors were decreased. Using a jpg - the pdf file works fine. - the SaveToString() returns a corrupt string. Conclusion, SaveToFile() works fine independend of the image format. SaveToString() can not handle jpgs and produces an unreadable pdf format. SaveToString() can handle bmps but influences the colors of the image. For more information, I ll be at your command, best regards, Torsten |
|
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