PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 11:20 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: PDF Viewer Settings
PostPosted: Thu May 07, 2009 1:25 pm 
Offline

Joined: Mon May 04, 2009 2:12 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu May 07, 2009 2:17 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
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 ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 11, 2009 1:13 pm 
Offline

Joined: Mon May 04, 2009 2:12 pm
Posts: 2
Thank you for your information! I will try it soon and report my results here.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 11, 2009 1:43 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
I just saw that PdfDocument has members PageLayout and PageMode.
Code:
PdfDocument outputDocument = new PdfDocument();
outputDocument.PageLayout = PdfPageLayout.SinglePage;

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF Viewer Settings
PostPosted: Thu Nov 17, 2011 11:36 am 
Offline

Joined: Thu Nov 17, 2011 11:31 am
Posts: 2
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


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF Viewer Settings
PostPosted: Thu Nov 17, 2011 3:09 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
The current sample is here:
http://www.pdfsharp.net/wiki/WorkOnPdfO ... ample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF Viewer Settings
PostPosted: Fri Nov 18, 2011 11:03 am 
Offline

Joined: Thu Nov 17, 2011 11:31 am
Posts: 2
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);


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF Viewer Settings
PostPosted: Sun Dec 31, 2017 10:20 pm 
Offline

Joined: Sun Dec 31, 2017 10:10 pm
Posts: 1
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);


Top
 Profile  
Reply with quote  
 Post subject: Re: PDF Viewer Settings
PostPosted: Mon Dec 20, 2021 11:23 am 
Offline

Joined: Mon Dec 20, 2021 11:13 am
Posts: 1
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 127 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group