Creating from Byte Array

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v3 and older)  /  Creating from Byte Array

DynamicPDF Generator for .NET (v3 and older) Forum

 Oct 21 2010 3:53 PM
Hello,
Just downloaded the program to test it out.  Looks very thorough and powerful.  Looking forwward to playing with it. 

Im trying to solve a specific problem.  I am writing a console app (not web) in C# that takes in a byte array and I need to create a pdf from that.  I thought I read that dynamicpdf can do this, but I havent seen anything exactly through my searches.  Is this possible?

Thanks
 Oct 21 2010 4:35 PM
Posted by a ceTe Software moderator
Hello,

You can use the PdfDocument Class to read the byte array and create a PDF. If you look at the class constructor you will see that one of them takes a byte array as a parameter.

Thanks,
ceTe Software Support Team.
 Oct 21 2010 5:24 PM
Thanks for the reply.  I did discover the pdfdocument class through my searches here, but didnt see that it was in the merge namespace.  good to know.  im really close but getting an error that i see has been discussed before, but no solid resolution has been discussed.

Invalid PDF File. Cross-reference table not found.

snipets of my code:

string path = @"c:\temp\MyTest.pdf";
PdfDocument doc = new PdfDocument(docData);   <-- crashes here
MergeDocument merge = new MergeDocument(doc);
merge.Draw(path);

im using ceTe.DynamicPDF.35 reference and my docdata array does have values in it.
 Oct 22 2010 8:37 AM
Posted by a ceTe Software moderator
Hello,

In order to merge the PDF document which is in the form of byte array you will have to use the PdfDocument class constructor which takes the PDF byte data as argument. You can also use the physical file path of the PDF document. Further you will have to use this PdfDocument object to build the MergeDocument object for merging. Below is the code for it.

            Byte[] bytedata = File.ReadAllBytes(@"Path for the PDF document");
            PdfDocument pdfdoc = new PdfDocument(bytedata);
            MergeDocument document = new MergeDocument(pdfdoc);
            document.Draw(@"Path to save the PDF document");

If you continue getting the error then kindly send over the input PDF document with which you are having trouble in merging to our support team at: Support Team so that they can look into it further.


Thanks,
ceTe Software Support Team
 Oct 22 2010 10:13 AM
it was bad data, everything is working fine now thanks!
 Jan 19 2015 4:48 AM

byte[] filedata;
documnetPathWithFilename="c:\test.pdf";
using (FileStream fs = new FileStream(documnetPathWithFilename, FileMode.Create))
                {
                    fs.Write(filedata, 0, filedata.Length);
                }

All times are US Eastern Standard time. The time now is 12:52 PM.