Getting a binary file from a resource in C #

I have a problem, I'm trying to get PDF as a resource in my application. At the moment, I have a fillable PDF file that I could save as a file next to the binary file, but now I'm trying to embed the PDF as a resource in binary format.

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
);

Each time I run the code, I get the error message "Rebuild trailer not found. Original Error: PDF startxref not found".

, . UTF-8, UTF-32, UTF-7, ASCII .. ..... Powerpoint , , , , Powerpoint xml . PDF, , , , XML- PDF.

- ?

+3
1

try :

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

, Build Action Embedded Resource.

+2

Source: https://habr.com/ru/post/1739727/


All Articles