PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 26, 2021 5:30 am

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Jan 15, 2021 11:53 am 

Joined: Fri Jan 15, 2021 11:21 am
Posts: 1
I want to fill an existing PDF file in my web application (developed in ASP.NET MVC 5). The PDF file has a field named "Text1". In this field I want to write the value "abc". I am currently trying to use PdfSharp for this purpose.

This is how I am currently trying to set a value in a field in the PDF:

var rDoc = PdfReader.Open(ControllerContext.HttpContext.Server.MapPath(@"~/Documents/test.pdf"), PdfDocumentOpenMode.Modify);
rDoc.AcroForm.Elements.SetValue("/NeedsAppearances", new PdfBoolean(true));
rDoc.AcroForm.Elements.SetValue("/Text1", new PdfString("abc"));

This is how I return the PDF to the client:

var bytesOfDoc = new byte[0];
using(var ms = new MemoryStream())
    rDoc.Save(ms, true);
    bytesOfDoc = ms.ToArray();
return File(bytesOfDoc, "application/pdf", "test.pdf");

But the field "Text1" is always empty. I have already tried various ways. Like for example also this one:

rDoc.AcroForm.Elements["/Text1"] =  new PdfString("abc");

What am I doing wrong?

Reply with quote  
PostPosted: Mon Jan 18, 2021 7:15 am 
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 655
Location: CCAA
Answered on SO:

Best regards
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 39 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group