logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
zulsters  
#1 Posted : Thursday, March 31, 2016 9:40:05 AM(UTC)
zulsters

Rank: Newbie

Groups: Registered
Joined: 3/31/2016(UTC)
Posts: 1
United Kingdom
Location: London

Here is my code:

PdfCommon.Initialize();

var doc = PdfDocument.Load("ct600-2008.pdf");

PdfPageCollection pageCollection = doc.Pages;
int count = pageCollection.Count;

PdfPage pdfPage = pageCollection.ElementAt(0);

PdfPageObjectsCollection pageObjects = pdfPage.PageObjects;
count = pageObjects.Count;

PdfTextObject txtObj = PdfTextObject.Create();
txtObj.Location = new PointF(50, 50);

txtObj.TextAscii = "Hello";
pageObjects.InsertObject(txtObj);


when the line "txtObj.TextAscii = "Hello";" is executed I get a 'System.AccessViolationException" occurred in "Patagames.Pdf.dll".

Any help here would be appreciated as without this functionality the SDK is of no use to me.

P.S. same exception occurs when setting TextUnicode.
Paul Rayman  
#2 Posted : Friday, April 1, 2016 6:01:06 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 132 time(s) in 129 post(s)
Please look at following:

Code:

PdfCommon.Initialize();

var doc = PdfDocument.Load("ct600-2008.pdf");

PdfPageCollection pageCollection = doc.Pages;
int count = pageCollection.Count;

PdfPage pdfPage = pageCollection.ElementAt(0);

PdfPageObjectsCollection pageObjects = pdfPage.PageObjects;
count = pageObjects.Count;

PdfTextObject txtObj = PdfTextObject.Create();
//Firstly you need to set the font to this text object
txtObj.Font = PdfFont.CreateStock(doc, FontStockNames.Arial);
//Next you need to set the text's color
txtObj.StrokeColor = Color.Black;
//After that you need to set the text's size
txtObj.Transform(50, 0, 0, 50, 0, 0);
//and then you can set the location
txtObj.Location = new PointF(50, 50);

//Now this line will be executed without any errors
txtObj.TextAscii = "Hello";
pageObjects.InsertObject(txtObj);


if you use PdfViewer, finally you need to redraw the page.
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.