Skip to content

Conversation

pamapa
Copy link
Contributor

@pamapa pamapa commented May 31, 2022

Ported sub-feature from this pull request: https://github.com/empira/PDFsharp/pull/11/files
Part of #237

Usage:

private static void AttachFile()
{
    string text = "AttachFile.pdf";
    XFont font = new XFont("Verdana", 10.0, XFontStyle.Regular);
    PdfDocument pdfDocument = new PdfDocument();
    PdfPage pdfPage = pdfDocument.AddPage();
    XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage);
    xGraphics.DrawString("Open with Adobe Acrobat Reader and click on the icon", font, XBrushes.Black, new XRect(10.0, 100.0, 300.0, 10.0), XStringFormats.TopLeft);
    pdfPage.Annotations.Add(new PdfFileAttachmentAnnotation(pdfDocument)
    {
        Rectangle = new PdfRectangle(new XRect(10.0, pdfPage.Height - 100.0, 10.0, 10.0)),
        File = new PdfFileSpecification(pdfDocument, "logo.jpg", new PdfEmbeddedFile(pdfDocument, File.ReadAllBytes("..\\..\\resources\\logo.jpg"), null))
    });
    pdfDocument.Save(text);
    Process.Start(text);
}

@ststeiger ststeiger merged commit 4c3bcbb into ststeiger:master May 31, 2022
@ststeiger
Copy link
Owner

Merged.

@pamapa pamapa deleted the attachment-annotations branch May 31, 2022 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants