PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PDF Viewer Settings
https://forum.pdfsharp.net/viewtopic.php?f=2&t=723
Page 1 of 1

Author:  hanappol [ Thu May 07, 2009 1:25 pm ]
Post subject:  PDF Viewer Settings

Hi!

AmI able to configure the pdf file I generate in the way that the pdf viewer will start maximized, showing the whole first page ?

hanappol

Author:  Thomas Hoevel [ Thu May 07, 2009 2:17 pm ]
Post subject: 

I dunno if this is implemented in current versions of PDFsharp ...

... but this old sample should still work:
http://www.pdfsharp.de/PDFsharp/index.p ... &Itemid=32

Look here for other options beside "/FitV":
http://partners.adobe.com/public/develo ... meters.pdf

I guess "/Fit" is the one.

No idea about Maximize ...

Author:  hanappol [ Mon May 11, 2009 1:13 pm ]
Post subject: 

Thank you for your information! I will try it soon and report my results here.

Author:  Thomas Hoevel [ Mon May 11, 2009 1:43 pm ]
Post subject: 

I just saw that PdfDocument has members PageLayout and PageMode.
Code:
PdfDocument outputDocument = new PdfDocument();
outputDocument.PageLayout = PdfPageLayout.SinglePage;

Author:  ploink [ Thu Nov 17, 2011 11:36 am ]
Post subject:  Re: PDF Viewer Settings

Hello

I tried to get the example shown her to work:
http://www.pdfsharp.de/PDFsharp/index.p ... &Itemid=32

I want to set a default zoom level of 100% in the pdf files i create..

However the example on the above URL does not seem to work..

For instance the PdfInternals.GetXRef method does not seem to exist?
And which namespace is PdfXRef in?

Is there a new and improved way of doing this or?

Any help would be greatly appreciated!

Thanks

Author:  Thomas Hoevel [ Thu Nov 17, 2011 3:09 pm ]
Post subject:  Re: PDF Viewer Settings

The current sample is here:
http://www.pdfsharp.net/wiki/WorkOnPdfO ... ample.ashx

Author:  ploink [ Fri Nov 18, 2011 11:03 am ]
Post subject:  Re: PDF Viewer Settings

Thanks for the fast reply!

So.. I tried to follow the example and looked at the specification pdf to look for the right action.
Seems like there is a zoom property

zoom=scale
zoom=scale,left,top
Sets the zoom and scroll factors, using float or integer values.
For example, a scale value of 100 indicates a zoom value of 100%.
Scroll values left and top are in a coordinate system where 0,0 represents the top left corner of the visible page, regardless of document rotation.

But when i try to use it i just get an unknown destination type error the same happens when i try the example below

Here is the code:

PdfDocument pdf = new PdfDocument();
PdfPage page = pdf.AddPage();
PdfDictionary dict = new PdfDictionary(pdf);
dict.Elements["/S"] = new PdfName("/GoTo");
PdfArray array = new PdfArray(pdf);
dict.Elements["/D"] = array;
PdfReference iref = PdfInternals.GetReference(pdf.Pages[0]);
array.Elements.Add(iref);
array.Elements.Add(new PdfName("/XYZ 0 0 100"));
pdf.Internals.AddObject(dict);
pdf.Internals.Catalog.Elements["/OpenAction"] = PdfInternals.GetReference(dict);

pdf.Save(path + pdf_name + ".pdf");

Based on this thread:
viewtopic.php?f=2&t=1586&hilit=zoom+level

Any ideas?

Edit:
When i try this approach the pdf changes the zoom, only it changes it to 6400% instead of the 100% i want it to be..

array.Elements.Add(new PdfName("/XYZ"));
array.Elements.Add(new PdfInteger(0));
array.Elements.Add(new PdfInteger(0));
array.Elements.Add(new PdfInteger(100));

Solved:
So zoom here is not the zoom level in percent but the zoom factor, changing from 100 to 1 did the trick :)
PdfDictionary dict = new PdfDictionary(pdf);
dict.Elements["/S"] = new PdfName("/GoTo");
PdfArray array = new PdfArray(pdf);
dict.Elements["/D"] = array;
PdfReference iref = PdfInternals.GetReference(pdf.Pages[0]);
array.Elements.Add(iref);
array.Elements.Add(new PdfName("/XYZ"));
array.Elements.Add(new PdfInteger(0));
array.Elements.Add(new PdfInteger(0));
array.Elements.Add(new PdfInteger(1));
pdf.Internals.AddObject(dict);
pdf.Internals.Catalog.Elements["/OpenAction"] = PdfInternals.GetReference(dict);

Author:  Yaron Dames [ Sun Dec 31, 2017 10:20 pm ]
Post subject:  Re: PDF Viewer Settings

using your final code got me 100% zoom, but page 2 is displayed.
Combining your solution and this example:

http://www.pdfsharp.net/wiki/WorkOnPdfObjects-sample.ashx

I came to this solution:

PdfDictionary dict = new PdfDictionary(pdf);
dict.Elements["/S"] = new PdfName("/GoTo");
PdfArray array = new PdfArray(pdf);
dict.Elements["/D"] = array;
PdfReference iref = PdfInternals.GetReference(pdf.Pages[0]);
array.Elements.Add(iref);
array.Elements.Add(new PdfName("/XYZ"));
array.Elements.Add(new PdfInteger(-32768));
array.Elements.Add(new PdfInteger(-32768));
array.Elements.Add(new PdfInteger(1));
pdf.Internals.AddObject(dict);
pdf.Internals.Catalog.Elements["/OpenAction"] = PdfInternals.GetReference(dict);

Author:  dylanpivo [ Mon Dec 20, 2021 11:23 am ]
Post subject:  Re: PDF Viewer Settings

Could you possibly help me with why my code to zoom is not working? I have basically copied your code verbatim, but when the code gets carried out, nothing happens to the document whatsoever. I'm not getting any errors or anything, just nothing happens. Here is my code:

Dim ActiveDoc As Integer = ViewState("ActiveDoc")

Dim Path As String = GetDocSortingDocsFilePath(ActiveDoc) & ".pdf"

Dim Pdf = PdfReader.Open(Path)

Dim Dict As PdfDictionary = New PdfDictionary(Pdf)
Dict.Elements("/S") = New PdfName("/GoTo")
Dim Array As PdfArray = New PdfArray(Pdf)
Dict.Elements("/D") = Array
Dim iref As PdfReference = PdfInternals.GetReference(Pdf.Pages.Item(0))
Array.Elements.Add(iref)
Array.Elements.Add(New PdfName("/XYZ"))
Array.Elements.Add(New PdfInteger(-32768))
Array.Elements.Add(New PdfInteger(-32768))
Array.Elements.Add(New PdfInteger(200))
Pdf.Internals.AddObject(Dict)
Pdf.Internals.Catalog.Elements("/OpenAction") = PdfInternals.GetReference(Dict)

Pdf.Save(Path)

I then display the PDF on the client side with an embed that looks like this:

Private Sub EmbedPDF(PDFPath As String)
Dim embed As String = "<embed src=""{0}#toolbar=0"" width=""500px"" height=""800px""></embed>"
ltEmbed.Text = String.Format(embed, PDFPath)
End Sub

Thanks

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/