Relative Links in PDF - asp.net

Need some advice on what course of action to take next.
Have written an ASP.Net application. Part of the application deals with being able to view PDFs. The initial PDF viewed acts as an index to access other PDF documents. You click a link in the Index PDF and it jumps to another PDF file. Legal documents, agreements, etc.
This scenario works on some computers and on others it doesn't. I managed to figure out what the problem was. On some of the computers the initial Index PDF was being hosted within the browser and on some other computers it was actually jumping out of the browser and directly into Adobe Acrobat. As soon as the PDF jumps out of the browser and into Acrobat the relative links in the Index PDF stop working because it is hosted client side via Acrobat but the additional PDFs it is trying to access are on the server.
I figured out why some computers stay in browser and why some jump out. There is an option within Acrobat itself that determines this behavior. It is under Edit--> Preferences ----> Display PDF in Browser.
I am in a jam because I am not in control of the PDF documents themselves and how they are written, and I obviously have no control over the options selected in Acrobat on each and every computer. My problem is also compounded by the fact that our firm has just recently purchased a new PDF reader called Nuance that will be pushed out firm wide soon and I don't think it even has the option to have PDFs hosted in browser.
I can get what I need to work if I create the index in HTML, but the problem is I don't write the Indexes and the people who do are not trained in HTML. I can get the people who write the indexes to change from relative links to absolute links, but then I run into the problem of what if we change where we are hosting the PDF files? All the links will break again? I think we are stuck with relative URLs, but how can I make it work?
I am thinking about maybe hosting the PDFs within Silverlight?
Looking for any thoughts or ideas?
Thanks.

Silverlight isn't going to help you here.
The solution really is in finding a better way to create the index document. Just how sophisticated is the index document content anyway?
If you don't want to have to train the authors of these indexes in HTML then can you provide them with a simple tool that they can use to describe the content. You could then have code server side to generate the HTML (even PDF) dynamically.

What you need is a simple redirector ASPX page whose URLs you can use in the PDF documents. Put the paths of the PDFs in a database. Give an ID for each PDF. The ASPX page should accept the ID as a parameter, do a lookup on the database, and response.redirect to the current location of the PDF. You can use URLs based on this ASPX page in the PDFs. If you keep database up to date, then the links in the PDF documents will always lead to the correct location.
In the Database
http://someserver/somepath/abc.pdf
ttp://anotherserver/apath/sdf.pdf
Links in the PDF documents
http://yoursite.com/pdf_redirect.aspx?id=1
http://yoursite.com/pdf_redirect.aspx?id=2

Related

Reading a PDF back from an iFrame?

I have a PDF document that is getting generated on the fly, and rendered on the fly to an iFrame within a radwindow. Basically the document is already largely prepopulated, however the user will still have a chunk of information that they are required to enter. I've found a good amount of information about sending a pdf TO an iframe, but not much information about going the other way. I have a button within the radwindow that can access the iframe object, however I'm somewhat lost as to where to go from there.
EDIT: The PDF is an editable form. I'm trying to pull back the entire PDF document as is, after the client side makes their entries to the form.
I think you'll need to send the file to the user so they can edit it locally and instruct them to upload it.
The content-disposition header with value attachment can help with the first task and you can use RadAsyncUpload to upload it: http://demos.telerik.com/aspnet-ajax/asyncupload/examples/overview/defaultcs.aspx.
I am not aware of ways to tap into the PDF viewer plugin the browsers use to show the PDF. Perhaps there is API from Adobe or some other third party plugin but that would rely on them and is out of your control.
Perhaps the JS PDF viewer from FireFox has something: https://mozillalabs.com/en-US/pdfjs/ but I don't know how stable and usable it is.
As per what was described in the comments, I ended up using postbacks through the PDF's themselves along with 1 pixel fields to store data required to identify the documents. It's a little hacky, but functional. I'm leaving this as an actual answer as this is as close to a real solution to the problem I originally had. This has been up and running for close to 4 years in this manner, and thus far hasn't caused any issues.

Adjusting Print Page in ASP.NET

I have some printed form on paper and want to create a web page (result of a report) and put those pre-printed pages in printer and print web page for fill the blanks on paper.
What is the best way to adjust the location of contents in the web page to work with any printer correctly?
thnx for your help
If you're just generating a regular html webpage to print, you're going to have a very hard time getting it consistent across multiple computers (or browsers, or printers). There are lots of browser settings that affect how the webpage is printed...like margins, header/footer text, etc. and these aren't things you can control from the html page.
You would need to generate a formatted file so there is less room for interpretation by the computer/browser/printer. Something like a PDF where you can create more consistent output.
I had a similar requirement for an app a while back. The requirements for that project were such that we generated a MS Word document prefilled with content (text, tables, etc.), then the user opens that generated file and prints it or saves it. I would think a PDF would be desirable in most cases though.

Generating PDF documents in ASP.NET [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Directly convert .aspx to .pdf
Is there any way to generate PDF document from asp.net directly from the page output. My requirement is, when user visits a page on my website, there should be a provision to get the same page / report in PDF format. Using iTextSharp, we need to built layout logic agin to generate PDF. If there are any changes in page output in future, I again need to work on logic to generate PDF. Instead I want to generate PDF directly from the page output just by setting "Response.ContentType" property.
One strategy I use is to develop reports using SQL Server Reporting Services. SSRS reports support export to PDF out of the box.
If you use SSRS 2008, you can even assign arbitrary HTML to a text box and the reporting engine will interpret it fairly well. This allows you to retrieve a snippet of HTML from any page, and present it in a report that will export to PDF without having to manually generate PDF document elements with iTextSharp.
If you go the SSRS 2008 route, check out this thread: http://forums.asp.net/t/1443965.aspx
I hope this helps.
Happy Coding!
You can set a button on your page that, if clicked, starts rendering a HTML page to PDF - only that the page you're asking it to render is exactly the page the user has clicked the button on. Once you got the PDF you can just send it in the normal way.
This of course requires a program that can render arbitrary HTML pages to pdf. You might want to check out ABCpdf which has always worked for me like a charm, but it's not free.
http://princexml.com/
They offer an application that converts html to pdf.
We use ActivePDF WebGrabber - which is designed to do exactly what you described. http://www.activepdf.com/products/serverproducts/webgrabber/

ASP.net: Display PDF in a asp.net web page

User click on a link button and it will direct them to a url that is dynmaically generated which a pdf file. The browser will prompt the user to either save or open it.
I want to know if it is possible to downlaod the pdf file to the server then show the pdf file in the asp.net web page. When i google on this question, 99% of top link are some third party component. Is it a way to do this without purchase any 3rd party component?
thank
I use itextsharp, its a free open source c# port of the java itext library.
Makes generating dynamic pdfs in asp.net a breeze and there is lots of documentation/examples floating around.
I don't think that you'll have much luck without a 3rd party component. First, the issue isn't showing the PDF, it is generating it. For that, you'll need a library to help. Rolling one yourself would not be cheaper unless you have an enormous amount of unpaid time on your hands.
With respect to third-party controls, I recommend and use DynamicPDF from CeTe.
Yes there is a way to do this without a 3rd party tool, but it involves coding a PDF-to-html translator.
If this is something for a business, the RoI for the 3rd party control is that you don't have to spend hundreds of hours coding & testing this component, when you could buy one for just a few hundred dollars.
Now, an alternative is to code a page which displays the data in the same way which the PDF file generates it (this could actually be handled by RDLC). So that when the user clicks the link button, they are taken to this display page, from which they can download the PDF version if they want a local copy.
Regardless of how you generate the PDF, I have found a better user experience if you open the PDF in an IFRAME instead of the full browser window. You can give users instructions and maintain the browser navigation.
I think what you want to do is by going to: http://my_site.com/generate-pdf.aspx?=someId
this should in fact just show the PDF file?
What you need to do is change the Response type.
See here for how to do this with images.
Look up the Content-Disposition HTTP header. You can send back a value that requests the content be displayed inline instead of downloaded.

How do I show an embedded excel file in a WebPage?

I want to allow an Excel report to be viewed embedded in a WebPage... is there a way?
I don't want to use an ActiveX, or OWC (Office Web Components), I just want to open an existing file from the internet explorer application.
I don't want users to download and then open it.
Using an iframe wouldn't be a problem, but my preliminary tests weren't successful
Any ideas? Is it at all possible?
This has to do with the local person's browser set up and not really anything you can do on your end. If they click a link with the .xls(x) extension, the browser determines if it wants to open it itself or in a new window.
Here 2 microsoft pages on how to change these settings:
http://support.microsoft.com/.../how-to-configure-internet-explorer-to-open-office-documents-in-the-app
http://support.microsoft.com/.../embed-your-excel-workbook-on-your-web-page-or-blog-from-sharepoint-or-onedrive-for-business
You should try using the Excel Web App Embed feature that lets you embed tables and charts from Excel directly on your Web Page. You can even let users interact with the spreadsheet so that they can sort and filter data and use your spreadsheets formulas to calculate make their own calculations all without altering the source.
The Excel Web App and storage is all free from Microsoft. Any data you embed on your Web page can be viewed by all the major destkop and mobile browsers and when you update your spreadsheet the data on your web pages is automatically updated as well.
I think your best bet is going to be extracting the data out of the Excel file and displaying it in a regular HTML table. Excel isn't exactly safe to invoke from a web page and not everyone has it anyway.
Take a look at scribd iPaper Viewer - this is a Flash based Viewer of XLS (and other) docs.
MOSS 2007 has a nifty feature called Excel Services which might fit the bill...
Excel Web App allows embedding "live" interactive spreadsheets on a web page. For an example, see http://datawiz.wordpress.com/2011/01/10/how-to-embed-excel-on-a-web-page/
in your comments you say that the Excel file is on the client's filesystem, not on the webserver. i think the security model of sane browsers forbid this; but wouldn't be surprised if setting high permissions to your pages could allow this.
<iframe src="file:\\yourpath\yourfile.xls" width="100%" height="500"></iframe>
Well this is a bit crude but sort of fits the bill.
Select the area of the spreadsheet you wish to display.
Copy this area into MS Paint.
Select the area in Paint and use the Edit/Copy to/ function to save this as a bitmap.
Now load the bitmap as you would any other pic.

Resources