PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:09 pm

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 
Offline

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:

Code:
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:

Code:
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:

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


What am I doing wrong?


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

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Answered on SO:
https://stackoverflow.com/a/65726643/162529

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


Top
 Profile  
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: No registered users and 112 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