Problem creating document

Problem creating document

Forum member · Aug 31, 2006
Using community edition with .Net Framework 2.0 and Visual Studio 2005... Dim myFileStream As FileStream = New FileStream("C:\test.pdf", FileMode.Open, FileAccess.Read) Dim fileArray()() As Byte = New Byte(1)() {} fileArray(0) = New Byte(myFileStream.Length - 1) {} myFileStream.Read(fileArray(0), 0, CType(myFileStream.Length - 1, Integer)) Dim MyDocument As ceTe.DynamicPDF.Document = New ceTe.DynamicPDF.Document() Dim MyPage As ceTe.DynamicPDF.Page = New ceTe.DynamicPDF.Page() Try MyPage.Elements.Add(New ceTe.DynamicPDF.PageElements.Image(ceTe.DynamicPDF.Imaging.ImageData.GetImage(fileArray(0)), 0, 0)) MyDocument.Pages.Add(MyPage) MyDocument.DrawToWeb() Catch ex As Exception ex = ex 'Breakpoint End Try Why does the PageElements.Add method throw the following exception? ex.Message: Parameter is not valid. ex.StackTrace: at System.Drawing.Bitmap..ctor(Stream stream) at ceTe.DynamicPDF.Imaging.BitmapImageData..ctor(Stream stream) at ceTe.DynamicPDF.Imaging.ImageData.GetImage(Byte[] data) at _Default.Button1_Click(Object sender, EventArgs e) in D:\Visual Studio 2005\WebSites\SRSBooksDEV\Default.aspx.vb:line 228

Re: Problem creating document

Support · Aug 31, 2006
Hello, The reason you are getting the error is because you are passing a PDF page to the GetImage method. You will have to pass an image to the GetImage method. If you want to add page from one PDF document to another PDF, you have to use ImportedPageData class which will get the entire page data from one PDF and you can add that to another page like adding any other page element. The following sample code will show how to use ImportedPageData. Dim MyDocument As Document = New Document Dim MyPage As Page = New Page MyDocument.Pages.Add(MyPage) Dim MyData As ImportedPageData = New ImportedPageData("C:\DocumentA.pdf", 1, 0, 0, 1) MyPage.Elements.Add(MyData) MyDocument.DrawToWeb() Thanks, ceTe Software Support Team

Re: Problem creating document

Forum member · Aug 31, 2006
Thanks, but I should have been more forthcoming. My real intent is to DrawToWeb a Byte Array containing a PDF document extracted from base 64 encoded XML element innertext pulled from an external web service. I presented the FileStream coding just for simplification. Here's the real code: Dim myElement As System.Xml.XmlNodeList = myXmlDoc.DocumentElement.GetElementsByTagName("DeliveryConfirmationLabel") Dim myByteArray() As Byte = System.Convert.FromBase64String(myElement(0).InnerText) Dim myMemStream As System.IO.MemoryStream = New System.IO.MemoryStream() myMemStream.Write(myByteArray, 0, myByteArray.Length) Dim MyDocument As ceTe.DynamicPDF.Document = New ceTe.DynamicPDF.Document() Dim MyPage As ceTe.DynamicPDF.Page = New ceTe.DynamicPDF.Page() Try MyPage.Elements.Add(New ceTe.DynamicPDF.PageElements.Image(ceTe.DynamicPDF.Imaging.ImageData.GetImage(myByteArray), 0, 0)) MyDocument.Pages.Add(MyPage) MyDocument.DrawToWeb() Catch ex As Exception ex = ex 'Breakpoint End Try I get the same exception I reported in my first posting. If I correctly understand your response, the byte array actually contains a binary representation a PDF document, not a binary representation of the image of a PDF document. Is there some way to DrawToWeb as is? If not, how can I convert the byte array to an image so the GetImage method will work?

Re: Problem creating document

Support · Aug 31, 2006
Hello, You can take the byte array and pass it to the PdfDocument object constructor and pass the PdfDocument object to the overloaded MergeDocument object constructor and use the DrawToWeb method of the MergeDocument object and that will work for you and not require any conversion of byte array containing the binary representation of PDF into image. Sample Code: Dim myElement As System.Xml.XmlNodeList = myXmlDoc.DocumentElement.GetElementsByTagName("DeliveryConfirmationLabel") Dim myByteArray() As Byte = System.Convert.FromBase64String(myElement(0).InnerText) Dim myMemStream As System.IO.MemoryStream = New System.IO.MemoryStream() myMemStream.Write(myByteArray, 0, myByteArray.Length) Dim MyPdfDocument As PdfDocument = new PdfDocument9myByteArray) Dim MyDocument As MergeDocument = new MergeDocument(MyPdfDocument) Mydocument.DrawToWeb() Thanks, ceTe Software Support Team

Re: Problem creating document

Forum member · Aug 31, 2006
Thanks. I'm only inches away from success and now Acrobat Reader plugin displays a dialog saying "the file is damaged and could not be repaired". Same error occurs with the byte array, and, the test.pdf filestream. The latter opens fine in the Acrobat Reader application. Any ideas?

Re: Problem creating document

Forum member · Aug 31, 2006
Never mind. I found the solution in faq article A1006.

Re: Problem creating document

Forum member · Mar 18, 2007
This sounds good, but what exactly is the namespace for the PdfDocument object? I cannot seem to find this object anywhere, the closest being ceTe.DynamicPDF.Document which doesn't have a constructor taking a byte array parameter.

Re: Problem creating document

Support · Mar 19, 2007
Hello, The namespace for the PdfDocument object is ceTe.DynamicPDF.Merger.PdfDocument. You will need to use the Merger product in order to use the PdfDocument object. Thanks, ceTe Software Support Team