We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Writing to an existing PDF

Thread ID:

Created:

Updated:

Platform:

Replies:

88428 Jul 22,2009 11:20 AM Jul 23,2009 02:53 AM Windows Forms 1
loading
Tags: PDF
Jeff Dressing
Asked On July 22, 2009 11:20 AM

I am trying to just write to an existing PDF. I don''t want to send a formula to it, I just want to physically write the page number as I will be merging all the pages together and I am building a Table of Contents.

I have tried writing it to a fixed location and I have tried determining the page width & height, then putting it where I want it. Neither seem to work.

So I have 2 questions here:
* Am I using the right logic to determine the page height and width?
* What I am doing wrong that is not writing any text to the existing PDF?

Here is the code snippet that is simplified as an example:

Private WithEvents mobjPDFDoc As PdfLoadedDocument
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10.0F, PdfFontStyle.Regular)
Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)

mobjPDFDoc = New PdfLoadedDocument(strFile)

For intPage = 0 to mobjPDFDoc.Pages.Count - 1
dblHeight = mobjPDFDoc.Pages(intPage).Graphics.ClientSize.Height
dblWidth = mobjPDFDoc.Pages(intPage).Graphics.ClientSize.Width

'I have tried this... This is ultimately what I want to do, I want to put the page number at the bottom right corner of the page.
mobjPDFDoc.Pages(intPage).Graphics.DrawString( _
"Page " & CStr(intPage + 1), font, brush _
, New PointF(dblWidth - 220, dblHeight - 100))

'And I have tried this... and it doesn''t work either
mobjPDFDoc.Pages(intPage).Graphics.DrawString( _
"Page " & CStr(intPage + 1), font, brush _
, New PointF(20, 20))

Next

mobjPDFDoc.Save()
mobjPDFDoc.Close(True)

All of the samples that come with Syncfusion are with NEW documents which are using the PDFDocument object ...I need it to work with an existing PDF that came from somewhere else. I need to use PdfLoadedDocument for an existing PDF. Is this assumption correct? I did not see a way to load an existing PDF to the PDFDocument object.

I cannot get the graphics.Drawstring to write correctly on the PDFLoadedDocument object.
Reply

Thanks,
Jeff

Thiruvenkadam E [Syncfusion]
Replied On July 23, 2009 02:53 AM

Hi Jeff,

Thanks you for your interest in Syncfusion products.

Here is the answers for your questions,

1. Am I using the right logic to determine the page height and width?

Ans:
Yes ,You have used the correct logic to determine the page height and width.

We can also determine the page height and width by using document.Pages[0].Size.Height and document.Pages[0].Size.Width properties.

Kindly refer the below code snippet which helps another way to determine the page height and width.



//Load the existing document.
Dim PDFDoc As PdfLoadedDocument =New PdfLoadedDocument(@"..\..\Data\Template.pdf");

//Gets the height of the page.
Dim height As Single = document.Pages[0].Size.Height;

//Gets the width of the page.
Dim width As Single = document.Pages[0].Size..Width;




2. What I am doing wrong that is not writing any text to the existing PDF?

Ans:
I am afraid that I was not able reproduce the mentioned issue "Write text to existing PDF is not showing up".

Please do find the sample from the below specified location which demonstrates how to write the text in to the existing PDF.

http://files.syncfusion.com/support/pdf.Windows/F88428/DrawText.zip


Please have a look at the above sample and if still the issue exists,

Could you please try to reproducing it in the above samples or send us pdf documents so that we could sort out the cause of the issue and provide you a solution?


3. Usage of the PdfDocument and PdfLoadedDocument classes ?

Ans:
PdfDocument Class:

Essential PDF''S PdfDocument class is used to create a new pdf documents.

PdfLoadedDocument Class:

Essential PDF''S PdfLoadedDocument class is represents a logic to handle the existing pdf documents.

Could you please refer the following link if you need more information about the PdfDocument and PdfLoadedDocument classes.

http://help.syncfusion.com/ug_73/pdf/DocumentObjectModel.html

http://help.syncfusion.com/ug_73/pdf/LoadDocument.html

Regards,
Thiru

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;