c# - Create an Image or PdfTemplate from a PDF file -


When using the itextsharp library for PDF generation, I came to this method: -
   

ITextSharp.text.Image img = iTextSharp.text.Image.GetInstance (Itextsharp.text.pdf.PdfTemplate);

Where, we can get an example of the image from a PDF template. But, I do not know how to create a PDF template and no manufacturer is taking a PDF file name or stream.

Why do I want to: I want to create an image from a PDF file and then use this image in any other PDF file.

How can any PDF template create an object?

PDF template is unfortunately not okay which you think it is. IText and iTextSharp are PDF generators, but there are no PDF renderers, which will require you to convert a PDF to an image.

He said, you can still fulfill your goal, on which you are seeing

one of the more common uses of PdfTemplate The subclass is pdfImportedPage . If you create from a image to a PDF-designated page , then you do not make a JPG or PNG or anything, then you will actually have the full version of your page An image object means that you can implement the conversion as ScaleAbsolute () or whatever you want, but when you add it to PDF output If so, any text is still true text (and thus selection) Will happen. This is the part where quality comes. If you start scaling up Image , then this (mathematical) will do the whole scaling, but unintentionally it can present something incorrectly like Adobe Reader. If you zoom in, then it will be fine, but many screen programs do not present in small forms as well, whether it is an issue for you or not, I do not know.

However, the code below is a fully functional sample to target iTextSharp 5.1.1.0. It reads a page from an existing PDF, scales it up to 50% and adds it to an output PDF.

  using the system; Using System.ComponentModel; Using System.Text; Using System.Windows.Forms; Using System.IO; Using ITextSharp.text.pdf; Using ITextSharp.text; Namespace WindowsFormsApplication1 {Public Partial Category Form 1: Form {Public Form 1 () {InitializeComponent (); } Private Zero Form 1_load (Object Sender, EventAgds E) {// String InputFile = PDF file for dragging the first page from the path. Cobain (environment. Gatefolder path (environment specialfolder. Desktop), "input pdf"); // PDF file output string outputFile = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Desktop), "Output PDF"); Using our PDF file to write {filestream fs = new filestream (output file, filemod ..creative, filex.doc.Open), using (using PDFDriver w = PdfWriter.GetInstance (Doctor, FS)) ; // We need a reader to pull pages from PDF Reader R = new PDF Reader (Input File); // Get the first page of our source pdf. Imported page imported page = w.GetImportedPage (r, 1) ; // We Ray output pdf doc. Enter a new page in the new page; // Create an image from imported page iTextSharp.text.Image Img = iTextSharp.text.Image.GetInstance (imported page); // just to use an image , To show that the image is scaled in the Image scaleExolute (imported page with / 2, imported page.high / 2) at the width and height of the original page of 50% // page in doc.Add (Img) Add image; // Close our output PDF document (close);}}} This.Close ();}}}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -