I am using pspdfkit to add few text annotations via the viewer. After adding the annotations I want to change their contents when the user clicks save button, and then save the pdf. I am not sure how to save the original pdf and also if I want to create a copy of it ?
This is how I get the doc and change the annotations text.
var doc = PdfView.Controller.GetPdfDocument();
var annots =await doc.GetAnnotationsAsync(0);
//I am assuming all my anotations are text (just for testing)
foreach (IAnnotation item in annots)
{
((Text)item).Contents = "Changed content";
}
I can export it using
await pdfView.Document.ExportAsync(dataWriter);
but how to create dataWriter from the doc.
Help will be appreciated.
thanks
Related
I'm using iTextSharp to fill my form fields on my template with values.
Some of this fields should be flattened so that the user can't edit it.
The rest of the fields should be filled by the user and my program can read out the data and insert it into the database.
My Solution works fine with Abobe Reader DC, but I have problems with Adobe Reader X. An update of the version on the clients isn't possible.
So I enabled usage rights in the PDF template. The problem is that with iTextSharp I have to enable append on the PdfStamper. If this is enabled, it's not possible to flatten a part of the form because of the Adobe signature on the document.
Now I have following idea:
I split my template into two documents. The first document is filled using my code and Formflattening is true.
Here's the Code:
MemoryStream outstream = new MemoryStream();
Document document = new Document();
PdfSmartCopy writer = new PdfSmartCopy(document, outstream);
document.Open();
//newFileStream is the flattend Form
pdfReader = new PdfReader(newFileStream.ToArray());
writer.AddDocument(pdfReader);
PdfReader reader = new PdfReader(Properties.Resources.PdfForm);
writer.AddDocument(reader);
reader.Close();
writer.Close();
document.Close();
return outstream.ToArray();
Now I merge the document with my second template and save it then I have the document that I want. The first page is 'readonly' and the second page has formfields.
My problem is now that the user can fill the document (checkboxes and textboxes) but if the user saves the document the filled checkboxes disappear. Hence, if the user sends me back the document there are no checkboxes in it.
I don't understand why only checkboxes disappear.
I use the following code to find a Picture Content Control using the tagname of this one and after I use the function Remove to remove it in the Word document :
System.IO.File.Copy(templatePath, outputPath, true);
using (WordprocessingDocument doc = WordprocessingDocument.Open(outputPath, true))
{
tagName = "portrait";
controlBlock = doc.MainDocumentPart.Document.Body.Descendants<SdtElement>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == tagName).SingleOrDefault();
if (controlBlock != null)
{
controlBlock.Remove();
}
doc.Close();
}
But when I open the created file in Word, the document need to be repaired by Word if not I can't open it. Word also give me this message in the detail of error :
<p> elements are required before every </tc>
When I inspect the word document with Open Xml before and after it been repaired, I don't see any difference
So what is the best way to remove a Picture Content Control in a Word document?
I resolved my problem easily, in fact the error message provided by Word is clear. So I get the parent element of my Picture Control Content and add a new empty paragraph and after I tried to delete the Picture Control Content and it was enough to resolved my problem.
Here is the code :
controlBlock.Parent.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
controlBlock.Remove();
SO i have a created a PDF template form with textbox which are editable fields. I am able to generate the pre-populated PDF with values from my database into the template through MVC 4.0 Application. Which works fine. Now i want to add a image from a folder into the PDF which will distinguished one form with another form. The image will depend on the user in-put. Image will go at the bottom of the PDF. I don't see any image-box or image container as a filed option. Only one i can see are text-box,checkbox,radio,list box etc but nothing like a iimage holder.
Dose any one know how to add image dynamically into PDF?
You can find the answer to your question in the official documentation, more specifically in chapter 8. In section 8.2.3, entitled "Pushbuttons", I explain that we usually use buttons as placeholders for images, because buttons can have an icon.
The ReplaceIcon example shows how you can replace the icon of an exising button. As you are using C#, you may want to take a look at ReplaceIcon.cs:
PdfReader reader = new PdfReader(aPdf);
using (MemoryStream ms = new MemoryStream()) {
using (PdfStamper stamper = new PdfStamper(reader, ms)) {
AcroFields form = stamper.AcroFields;
PushbuttonField ad = form.GetNewPushbuttonFromField("button_name");
ad.Layout = PushbuttonField.LAYOUT_ICON_ONLY;
ad.ProportionalIcon = true;
ad.Image = Image.GetInstance(yourImage);
form.ReplacePushbuttonField("button_name", ad.Field);
}
}
// ms will contain your PDF in memory
}
reader.Close();
Note that the line ad.ProportionalIcon = true; will scale your image so that it fits the button.
I'm using Aspose.Pdf for .NET.
What I'm trying to do is:
Make pdf with 1 layer (best solution would be if before generate pdf all used text and bacground image would be as picture and then generated pdf)
I need it for prohibit changing content in my pdf simple secure pdf file isn't enough, because even online pdf to doc converters enable to change content.
So is there a way to do this now?
Or is there any way for make image from content before put it on site of pdf?
I was able to generate pdf but with multiple layers (2 in my scenario).
I've use dll version 5.0.0 for .net 4.0 Client.
Thanks in advance:)
Using Aspose.Pdf, you can set several privileges on the PDF documents to control their use. Specify the security options as follows using Aspose.Pdf and the Pdf document you have generated will behave as a readonly document which could not be edited:
//Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Assign a security instance to Pdf object
pdf1.Security = new Aspose.Pdf.Generator.Security();
//Restrict annotation modification
pdf1.Security.IsAnnotationsModifyingAllowed = false;
//Restrict contents modification
pdf1.Security.IsContentsModifyingAllowed = false;
//Restrict copying the data
pdf1.Security.IsCopyingAllowed = false;
//Allow to print the document
pdf1.Security.IsPrintingAllowed = true;
//Restrict form filling
pdf1.Security.IsFormFillingAllowed = false;
//Add a section in the Pdf
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
//Create a text paragraph and set top margin
Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(sec1,"this is text content");
text1.Margin.Top = 30;
//Add image
Aspose.Pdf.Generator.Image img = new Aspose.Pdf.Generator.Image();
img.ImageInfo.File = "asposelogo.png";
img.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;
//Add the text paragraph and image to the section
sec1.Paragraphs.Add(text1);
sec1.Paragraphs.Add(img);
//Save the Pdf
pdf1.Save("test.pdf");
As far as creating the whole content of PDF as an embedded image, it is not directly supported in Aspose.Pdf. You can however use some way around or some other component to generate image with your content and then can use this image to create Pdf file using Aspose.Pdf as follows:
Generate PDF with your content (A multi layer PDF as you have created earlier)
Export the PDF to image as described in "Working with Images" section of Aspose.Pdf documentation.
Use exported image to create PDF as described in "Working with Images(Generator)" and distribute your document.
My name is Iqbal and I am developer evangelist at Aspose.
I want to create a fillable PDF using Open Office or something which is open source. With Open Office I created the fillable PDF and it works fine with Foxit Reader; we can also save it. Now the problem is I have an image in the PDF which should also be fillable, like the other fields. User should be able to put his/her image in the image box and save it.
Later I will be reading the PDF using iTextSharp to retrieve the field's values and save it in the database. Other than the image everything works fine. I tried to create the image box with Open Office but when I open it in the PDF reader I cannot change the picture and moreover how will I read the image using iTextSharp and display it on the picture box so that user can save all the data in the database in future?
I tried with this but its showing null value
string pdfTemplate = #"c:\Temp\PDF\Untitled 1.pdf";
var reader = new PdfReader(pdfTemplate);
var output = new MemoryStream();
var stamper = new PdfStamper(reader, output);
//textBox2.Text = stamper.AcroFields.GetField("f1_09(0)");
Bitmap bimg = new Bitmap(stamper.AcroFields.GetField("ImageControl"));
System.Drawing.Image tempimg = bimg;
pictureBox1.Image = tempimg;
stamper.FormFlattening = true;
stamper.Close();
reader.Close();
It is not possible to 'put an image into a fillable form'. The PDF specification only supports fillable text, not images...
Here is a list of the general types for interactive AcroForm elements which are available according to the PDF-1.7 ISO specification:
Button fields represent interactive controls on the screen that the user can manipulate with the mouse. They include pushbuttons, check boxes, and radio buttons.
Text fields are boxes or spaces in which the user can enter text from the keyboard.
Choice fields contain several text items, at most one of which may be selected as the field value. They include scrollable list boxes and combo boxes.
Signature fields represent digital signatures and optional data for authenticating the name of the signer and the document’s contents.
As you can see, there are no images in this list...