iTextSharp - Neues Dokument als Byte erstellen []

Haben Sie eine kleine Methode, die in die Datenbank geht und ein PDF-Dokument aus einer Varbinary-Spalte abruft und dann Daten hinzufügt. Ich möchte Code hinzufügen, damit ein neues leeres Dokument erstellt und zurückgegeben wird, wenn dieses Dokument (Firmenbriefpapier) nicht gefunden wird. Die Methode könnte entweder ein Byte [] oder einen Stream zurückgeben.

Das Problem ist, dass die Variable "bytes" in der else-Klausel null ist.

Irgendwelche Ideen, was ist los?

private Byte[] GetBasePDF(Int32 AttachmentID)
{
    Byte[] bytes = null;
    DataTable dt =  ServiceFactory
        .GetService().Attachments_Get(AttachmentID, null, null);

    if (dt != null && dt.Rows.Count > 0)
    {
        bytes = (Byte[])dt.Rows[0]["Data"];
    }
    else
    {
        // Create a new blank PDF document and return it as Byte[]
        ITST.Document doc = 
           new ITST.Document(ITST.PageSize.A4, 50f, 50f, 25f, 25f);
        MemoryStream ms = new MemoryStream();

        PdfCopy copy = new PdfCopy(doc, ms);
        ms.Position = 0;

        bytes = ms.ToArray();

    }

    return bytes;
}

Antworten auf die Frage(2)

Ihre Antwort auf die Frage