PDF related - chanandrew96/MyLearning GitHub Wiki

JavaScript (JS)

Show PDF on Web using JavaScript

For using embed block to show PDF, you could add parameters into the src url to customize the display

<embed id="embedPdf" src="url-to-your-pdf#page=1&scrollbar=0&toolbar=1&navpanes=0&zoom=300" class="h-100 w-100">

For detail of parameters, you can reference to Adobe Document - Parameters for Opening PDF Files

Make changes on PDF in C#

You may need to make use of Ghostscript

PDFSharp (C#)

Reference
Save changes to PDF with image changes on WinForm

PdfDocument newDocument = new PdfDocument();
PdfDocument document = PdfReader.Open(imageFilePath, PdfDocumentOpenMode.Import);

// Create an empty page or load existing
if (int.TryParse(txtPageNum.Text, out int pageNum))
{
  int pageNumber = 1;
  foreach (PdfPage pdfPage in document.Pages)
  {
    if (pageNumber == pageNum)
    {
      // Create an empty page
      PdfPage page = newDocument.AddPage();
      // Get an XGraphics object for drawing
      XGraphics gfx = XGraphics.FromPdfPage(page);
      MemoryStream ms = new MemoryStream();
      pictureBox.Image.Save(ms, ImageFormat.Jpeg);
      XImage image = XImage.FromStream(ms);
      int x = 0, y = 0;
      double height = page.Width / pictureBox.Image.Width * pictureBox.Image.Height;
      // Draw the image on PDF page
      gfx.DrawImage(image, x, y, page.Width, height);
    } else
    {
      // Create an empty page
      PdfPage page = newDocument.AddPage(pdfPage);
      // Get an XGraphics object for drawing
      //XGraphics gfx = XGraphics.FromPdfPage(page);
    }
    pageNumber += 1;
  }
  //newDocument.Pages.RemoveAt(pageNum);

  // Save and start View
  newDocument.Save(saveAsDialog.FileName);
  MessageBox.Show("PDF Saved!");
  document.Dispose();
}

Draw Highlight with PDFSharp (C#)

XPen border = new XPen(XColor.FromKnownColor(XKnownColor.Blue));
XSolidBrush brush = new XSolidBrush(XColor.FromArgb(64, 238, 255, 0));
PointF x = new PointF(x, y);
PointF y = new PointF(x, y);
float width = 100;
float height = 100;
XRect rect = new XRect(x, y, width, height);
g.DrawRectangle(border, brush, rect);