Как установить масштаб по умолчанию 100% с помощью iTextSharp 4.0.2? - PullRequest
3 голосов
/ 07 марта 2012

Я хочу, чтобы программа чтения PDF (Adobe Reader) открывала файл PDF с автоматическим увеличением масштаба 100%.

Спасибо!

1 Ответ

6 голосов
/ 07 марта 2012

Я нашел этот фрагмент кода при исследовании iTextSharp для себя и нашел 2 человек, ссылающихся на Open Actions. Я включил фрагмент из http://www.developerbarn.com/blogs/richyrich-33.htm ниже:

PdfWriter writer = PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);

//this creates a new destination to send the action to when the document is opened. The zoom in this instance is set to 0.75f (75%). Again I use doc.PageSize.Height to set the y coordinate to the top of the page. PdfDestination.XYZ is a specific PdfDestination Type that allows us to set the location and zoom.
PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 0.75f);

//open our document
doc.Open();

//here you put all the information you want to write to your PDF

//create a new action to send the document to our new destination.
PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);

//set the open action for our writer object
writer.SetOpenAction(action);

//finally, close our document
doc.Close();
...