This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
nokturnal  
#1 Posted : Sunday, April 16, 2017 4:27:59 PM(UTC)
nokturnal

Rank: Member

Groups: Guest
Joined: 3/21/2016(UTC)
Posts: 23

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Hey,

I am trying to wrap my head around how to open a pdf with PDFReader (which is a template), add some text and some images, and then save it out as a new file using PDFWriter... Can someone point me in the right direction?

Thanks :)

Julia Khoptyan  
#2 Posted : Tuesday, April 18, 2017 11:42:19 PM(UTC)
Julia Khoptyan

Rank: Advanced Member

Groups: Guest
Joined: 8/19/2016(UTC)
Posts: 33

Was thanked: 1 time(s) in 1 post(s)
Hey Nokturnal,

Sorry for being late in answering you.

You can use the following code snippet:

Code:

var img = new Bitmap(@"image.jpg");
using (var reader = new PdfReader("in.pdf", dpi, dpi))
using (var frame = reader.Frames[0])
using (var container = frame.GetContent())
using (var writer = new PdfWriter("out.pdf"))
{
       writer.AddPage(pageWidth, pageHeight, dpi, dpi);
       using (var graphics = writer.GetGraphics())
       {
              graphics.DrawImage(frame.GetBitmap(), new System.Drawing.RectangleF(0, 0, frame.Width, frame.Height));
              graphics.DrawImage(img, new System.Drawing.RectangleF(0, 0, imgWidth, imgHeight));
              var plainText = new PlainText("Some text", graphics.CreateFont("Arial", 16), new System.Drawing.PointF(20, 30));
              graphics.DrawText(plainText);
       }
 }

Let me know, if you have any questions/concerns.

Kind regards,

Julia

Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.