Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement PdfFileAttachmentAnnotation #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

julienrffr
Copy link

@julienrffr julienrffr commented Oct 13, 2023

Implements PDF 1.3's FileAttachment annotation according to specs.
Will display a clickable annotation that opens an attachment, displaying either as an predefined icon or as a custom appearance.

Usage is simple (2 possibilities):
`var path = @"C:\Users\userxxx\Downloads\avion2.jpg";

        var fileSpec = new PdfFileSpecification(document, new PdfEmbeddedFileStream(document, File.OpenRead(path)), "avion111.jpg");
        var rectangleBottomBased = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 30), new XSize(30, 30)));
        var annot1 = page.AddFileAttachmentAnnotation(new PdfRectangle(rectangleBottomBased), fileSpec);

        var rectangleBottomBased2 = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(300, 160), new XSize(250, 250)));
        var annot2 = page.AddFileAttachmentAnnotation(new PdfRectangle(rectangleBottomBased2), new PdfEmbeddedFileStream(document, File.OpenRead(path)), "avion222.jpg");
        annot2.CustomAppearanceHandler = new SignAppearenceHandler();
        annot2.RenderCustomAppearance();`

Either add an annotation from a known PdfFileSpecification (you can re-use it in other annotations), or directly from a PdfEmbeddedFileStream (PdfFileSpecification will be silently created).

image

HelloWorld-3BA27568D294498F9DB86F2E19A94AA2_tempfile.pdf

fileattachmentannotation.cs.txt

@julienrffr
Copy link
Author

NB: this feature is available in PDFsharp-extended nuget package

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