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.
Related
I am using Itext 7 to watermark existing documents. My document is:
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFile), new PdfWriter(destinationPath));
Then I am looping thro the pages:
var numberOfPages = pdfDoc.GetNumberOfPages();
for (var i = 1; i <= numberOfPages; i++)
{
page = pdfDoc.GetPage(i);
...watermark building...
page.AddAnnotation(watermark);
page?.Flush();
pdfDoc.Close();
}
While that I would like to save this page as an image into this document or to a new pdf document.
I know that there is the pdfRender available now for Java, but not for C#. Is there a way to save the text based pdf to image based with one leyer? Basically I need to flatten PDF to get all layers to one. So watermark could not be removed as a separate layer with a watermark removal software.
SOLUTION::UPDATE
I have the solution now. I found that iText cant do what I want(PDFRender is available in Java right now). So I used Apitron instead to generate images from pages. And then I am using iText again to add images to my new PDF document.
Here is an example how to add images with Itext 7: https://www.tutorialspoint.com/itext/itext_adding_image_to_pdf.htm (using Image = iText.Layout.Element.Image;)
Here is an Apitron example for making images from PDF pages: https://github.com/apitron/Apitron.PDF.Rasterizer.Samples/tree/master/ConvertPDFtoBitmap
NOTE: As comments below are saying, the quality is bad with .png. So maybe it is good to use TIFF format.
I use PdfSharp to create a PdfDocument object:
private readonly PdfDocument _pdf = new PdfDocument();
Along with the other methods for actually adding the text, setting font styles etc. I then write the pdf file to a temporary location on disk:
var tempPdf = string.Concat(Path.GetTempPath(), Guid.NewGuid().ToString(), ".pdf");
_pdf.Save(tempPdf);
Which I then use in System.Windows.Clipboard class to copy the content to the clipboard:
Clipboard.SetFileDropList(new StringCollection {tempPdf});
When the user pastes the Clipboard content into a Word document for example, the pdf content appears in the document as desired.
The problem I have is that when the user double-clicks on the embedded PDF it launches the PDF in a viewer such as Adobe Reader, also as expected. The (unanticipated) problem I have is that I need to prevent this pop-up from happening given that this content will be inserted into a legal document.
Can any suggest any approaches or strategies for helping me to achieve something like this? To summarise - allowing them to paste [pdf] content stored in the clipboard to a Word document, but without it opening on double-clicking.
The answer was in my question ;)
And credit to Nyerguds for helping me out of my cocoon - I was fixated on using PDF files to copy to the clipboard.
The solution is to replace the usages of PdfSharp for pdf generation with System.Drawing.Graphics / System.Drawing.Bitmap to create jpg images of that which we want to copy.
And once the clipboard contents have been pasted to the Word document, we no longer have that problem of the image being openable on double-clicking.
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 need to display PdfPage of a PDF Document in a WPF form. I am using Docotic.pdf.dll and want to stick to it. The PdfPage.Thumbnail is also giving me null with all PDFs.
Just confirmed from Bit Miracle, this feature has been added in Docotic.Pdf 3.4 (available on their site) and currently it is in beta phase .
Below is the code that will save the image from the Pdf.
using (PdfDocument pdf = new PdfDocument("your_file.pdf"))
{
PdfDrawOptions options = PdfDrawOptions.CreateZoom(150);
options.BackgroundColor = new PdfRgbColor(255, 255, 255); // white background, transparent by default
options.Format = PdfDrawFormat.Jpeg;
pdf.Pages[0].Save("result.jpg", options);
}
There is also Draw and print PDF group of samples that might worth to look into.
As far as I know Docotic.Pdf cannot display PDF files (at least the current version), it can only create them. The PdfPage.Thumbnail refers to the page thumbnail embedded in the PDF file, which usually is missing, this is why the property returns null.
I want to read a PDF file having lots of text, images, tables in it. I want to read the entire file content by content page by page, from top to bottom.
For example:
The top of the page contains the Heading
Then on left hand side the contents and on the right hand side images
So I first want to get the heading then the contents then the images.
Is there any open source for reading the PDF or any coding reference for .net 2.0 or greater version?
Edit
Hi Konamiman, I make use of iTextSharp but unable to read the document. For clarification, this is the code I am using in case of iTextSharp
iTextSharp.text.pdf.PdfReader documentReader = new PdfReader(#"C:\Documents and Settings\admin\My Documents\Visual Studio 2008\Projects\pdfClownPDFReader\pdfClownPDFReader\Hongkong Buffet.pdf");
//MessageBox.Show(documentReader.NumberOfPages.ToString());
PdfStamper PDFS = new PdfStamper(documentReader, m);
PdfDictionary dictonary = documentReader.GetPageN(1);
PdfObject obj = dictonary.Get(PdfName.TEXT);
I also tried PDFSharp.
There is for example iTextSharp.