Getting a binary file from resource in C#

Posted by Jesse Knott on Stack Overflow See other posts from Stack Overflow or by Jesse Knott
Published on 2010-04-03T23:55:11Z Indexed on 2010/04/04 0:03 UTC
Read the original article Hit count: 546

Filed under:
|
|

Hello, I am having a bit of a problem, I am trying to get a PDF as a resource in my application. At this point I have a fillable PDF that I have been able to store as a file next to the binary, but now I am trying to embed the PDF as a resource in the binary.

byte[] buffer;
                try
                {
                    s = typeof(BattleTracker).Assembly.GetManifestResourceStream("libReports.Resources.DAForm1594.pdf");
                    buffer = new byte[s.Length];
                    int read = 0;
                    do
                    {
                        read = s.Read(buffer, read, 32768);

                    } while (read > 0);                        
                }
                catch (Exception e)
                {
                    throw new Exception("Error: could not import report:", e);
                }

                // read existing PDF document
                PdfReader r = new PdfReader(
                    // optimize memory usage
                    buffer, null
                );

Every time I run the code I get an error saying "Rebuild trailer not found. Original Error: PDF startxref not found" When I was just opening the file via a path to the static file in my directory it worked fine. I have tried using different encodings UTF-8, UTF-32, UTF-7, ASCII, etc etc.... As a side note I had the same problem with getting a Powerpoint file as a resource, I was finally able to fix that problem by converting the Powerpoint to xml and using that. I have considered doing the same for the PDF but I am referencing elements by field name which does not seem to work with XML PDFs.

Can anyone help me out with this?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about c#

Related posts about pdf