2

I am using PDfiumViewer winform control to display pdfs. And, I have added some annotations to the pdf, but those do not show up in the pdfviewer control.So, how can achieve this?

V K
  • 1,645
  • 3
  • 26
  • 57

3 Answers3

4

In PDFium there is an FPDF_ANNOT flag that can be passed to the various FPDF_RenderPage* methods. It's possible the PDFiumViewer code provides the same flag somewhere.

dj2
  • 9,534
  • 4
  • 29
  • 52
1

In 'public Image Render' method under the PdfDocument.cs class use below code

enter image description here

user2767633
  • 57
  • 1
  • 1
  • 7
  • I am unable to show annotations when using Render(... , PdfRenderFlags.Annotations). Any ideas on why the flag is seemingly ignored? – NinjaLlama Jun 04 '23 at 21:51
  • It works. replacing FROM: (flags & PdfRenderFlags.Annotations) != 0 TO: (flags & PdfRenderFlags.Annotations) == 0. Pdf show up correctly. Now may have other way to do it but I was unable find. – busymind Jun 22 '23 at 16:27
0

I was able to solve the problem using the following code:

doc = PDDocument.load(FilePath);
PDPage page = (PDPage)doc.getDocumentCatalog().getAllPages().get(pageNum);
int rotPD = page.findRotation();
PDRectangle pageBound = page.findCropBox();
PDRectangle rect = ModifyRectAccordingToRotation(rectangle, rotPD, pageBound);
PDAnnotationLink txtLink = new PDAnnotationLink();
    PDBorderStyleDictionary borderULine = new PDBorderStyleDictionary();
                    borderULine.setStyle(PDBorderStyleDictionary.STYLE_UNDERLINE);
borderULine.setWidth(0);
txtLink.setBorderStyle(borderULine);
PDActionRemoteGoTo remoteGoto = new PDActionRemoteGoTo();
PDComplexFileSpecification fileDesc = new PDComplexFileSpecification();
fileDesc.setFile(System.IO.Path.GetFileName(path));
remoteGoto.setOpenInNewWindow(true);
remoteGoto.setFile(fileDesc);
txtLink.setAction(remoteGoto);
txtLink.setRectangle(rect);
page.getAnnotations().add(txtLink);
V K
  • 1,645
  • 3
  • 26
  • 57
  • I do not see the PDAnnotationLink. Where is that from? I am unable to show annotations using PdfRenderFlags.Annotations. – NinjaLlama Jun 04 '23 at 21:49