itextsharp

Reading hyperlinks from pdf file

旧城冷巷雨未停 提交于 2019-11-27 06:19:13
问题 I'm trying to read a pdf file and get all hyperlinks from this file. I'm using iTextSharp for C# .net. PdfReader reader = new PdfReader("test.pdf"); List<PdfAnnotation.PdfImportedLink> list = reader.GetLinks(36); This method "GetLinks" return a list with a lot of information about the links, but this method does not return the value that I want, the hyperlink string and I exactly know that there are hyperlinks in 36th page 回答1: PdfReader.GetLinks() is only meant to be used with links internal

How to continue field output on a second page?

☆樱花仙子☆ 提交于 2019-11-27 05:39:36
I have generated a PDF from a template. The PDF has a field in the middle of it that is of variable length. I am trying to work it so that if the field's content overflows, then the program will use a second instance template as a second page and continue in the same field there. Is this possible? This will only work if you flatten the form. I've written a proof of concept where I have a PDF form src that has a field named "body" : public void manipulatePdf(String src, String dest) throws DocumentException, IOException { PdfReader reader = new PdfReader(src); Rectangle pagesize = reader

How can I flatten a XFA PDF Form using iTextSharp?

ε祈祈猫儿з 提交于 2019-11-27 05:38:56
I assume I need to flatten a XFA form in order to display properly on the UI of an application that uses Nuance's CSDK. When I process it now I get a generic message "Please Wait.... If this message is not eventually replaced..". Looking for some sample iTextSharp code to do this. You didn't insert a code sample to show how you are currently flattening the XFA form. I assume your code looks like this: var reader = new PdfReader(existingFileStream); var stamper = new PdfStamper(reader, newFileStream); var form = stamper.AcroFields; var fieldKeys = form.Fields.Keys; foreach (string fieldKey in

Editing Hyperlink and Anchors in PDF using ITextSharp

本秂侑毒 提交于 2019-11-27 05:30:01
I am using iTextSharp library and C#.Net for splitting my PDF file. Consider a PDF file named sample.pdf containing 72 pages. This sample.pdf contains pages that have hyperlink that navigate to other page. Eg: In the page 4 there are three hyperlinks which when clicked navigates to corresponding 24th,27th,28th page. As same as the 4th page there are nearly 12 pages that is having this hyperlinks with them. Now using iTextSharp library I had split this PDF pages into 72 separate file and saved with the name as 1.pdf,2.pdf....72.pdf. So in the 4.pdf when clicking that hyperlinks I need to make

Highlight words in a pdf using itextsharp, not displaying highlighted word in browser

此生再无相见时 提交于 2019-11-27 05:23:21
Highlighted words are not displaying in browser using itextsharp. Adobe Browser CODE List<iTextSharp.text.Rectangle> MatchesFound = strategy.GetTextLocations(splitText[i].Trim(), StringComparison.CurrentCultureIgnoreCase); foreach (Rectangle rect in MatchesFound) { float[] quad = { rect.Left - 3.0f, rect.Bottom, rect.Right, rect.Bottom, rect.Left - 3.0f, rect.Top + 1.0f, rect.Right, rect.Top + 1.0f }; //Create our hightlight PdfAnnotation highlight = PdfAnnotation.CreateMarkup(stamper.Writer, rect, null, PdfAnnotation.MARKUP_HIGHLIGHT, quad); //Set the color highlight.Color = BaseColor.YELLOW;

How to add a watermark to a PDF file?

强颜欢笑 提交于 2019-11-27 05:08:34
I'm using C# and iTextSharp to add a watermark to my PDF files: Document document = new Document(); PdfReader pdfReader = new PdfReader(strFileLocation); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(strFileLocationOut, FileMode.Create, FileAccess.Write, FileShare.None)); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(WatermarkLocation); img.SetAbsolutePosition(100, 300); PdfContentByte waterMark; // for (int pageIndex = 1; pageIndex <= pdfReader.NumberOfPages; pageIndex++) { waterMark = pdfStamper.GetOverContent(pageIndex); waterMark.AddImage(img); } //

“'System.StackOverflowException” in “OnEndPage” event handler

风格不统一 提交于 2019-11-27 04:57:33
问题 In the code below, you can see that I overrode OnEndPage event and tried to add a paragraph to the document. However, I get an "System.StackOverflowException" error when attempting to run the code. Does anyone have any idea why this is happening and how can I fix it? public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); Paragraph p = new Paragraph("Paragraph"); document.Add(p); } 回答1: It is forbidden to use document.Add() in a page event. The

Extract image from PDF using itextsharp

淺唱寂寞╮ 提交于 2019-11-27 04:52:03
I am trying to extract all the images from a pdf using itextsharp but can't seem to overcome this one hurdle. The error occures on the line System.Drawing.Image ImgPDF = System.Drawing.Image.FromStream(MS); giving an error of "Parameter is not valid". I think it works when the image is a bitmap but not of any other format. I have this following code - sorry for the length; private void Form1_Load(object sender, EventArgs e) { FileStream fs = File.OpenRead(@"reader.pdf"); byte[] data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); List<System.Drawing.Image> ImgList = new List<System

itextsharp modify existing pdf (no new source pdf) and add watermark

谁说我不能喝 提交于 2019-11-27 04:49:55
问题 I would like to modify a existing pdf document and add a watermark image. How can I do this without to create a new file? I think it's a stupid solution to create a temp pdf. Delete the source file and rename the temp pdf like the source file!? Here my example code but there I'm creating a new destination file. Regards private static void PdfApplication(String filePath) { PdfReader pdfReader = new PdfReader(filePath); Stream outputStream = new FileStream(newFilePath, FileMode.Open, FileAccess

Convert Pdf file pages to Images with itextsharp

萝らか妹 提交于 2019-11-27 04:48:23
I want to convert Pdf pages in Images using ItextSharp lib. Have any idea how to convert each page in image file Chris Haas iText/iTextSharp can generate and/or modify existing PDFs but they do not perform any rendering which is what you are looking for. I would recommend checking out Ghostscript or some other library that knows how to actually render a PDF. you can use ImageMagick convert pdf to image convert -density 300 "d:\1.pdf" -scale @1500000 "d:\a.jpg" and split pdf can use itextsharp here is the code from others. void SplitePDF(string filepath) { iTextSharp.text.pdf.PdfReader reader =