Logging into your account
Introduction
Premium users can log into their account by surfing to http://pdfmyurl.com and clicking the top right hand login button.
Once logged in you can keep track of the pdf's you've made with the "view history" link (top right).
Using pdfmyurl.com
Try using our bookmark feature, simply surf to pdfmyurl and drag the bookmarklet box to your bookmarks bar (works in Internet Explorer, FireFox, Safari And Chrome). Confused? Watch this video:
You can customize your preferences by clicking on the preferences bar, directly under the url submit textarea.
Why use pdfmyurl?
Creating a PDF from an existing Web page is only one use case for pdfmyurl.com. You could use it in *any* situation where you want to generate a PDF in some dynamic, automated way such as via PHP. Rather than try to figure out the PDF format, or the workings of some arcane library, you can generate a page of HTML (which you already know, and is well documented) and then convert that.
Generating PDFs for different uses using HTML as your templating system is a sound idea. The idea that your PDF templates can be in HTML and sit in your application alongside page templates, and basically be edited by the same people, is pretty attractive.
What's even more interesting is you do not need to worry or play with concurrency issues/ server load or configuration settings etc., this has already been solved and tested by millions of users, who's feedback is making things a better product for everyone!
Support email & links
Getting help
If you need help doing something, check out our support page.
Need email support? Simply send an email to pdfmyurl@opentracker.net and ask your question. PdfMyUrl tries to answer all questions within a working week.
If you have a problem doing something then please provide us a link of the problem demonstrated. We need an example in order to reproduce.
Priority Package
Need priority support or development time? PdfMyUrl now supplies a priority support/ development time package, pdfmyurl@opentracker.net us for pricing details.
Over usage (limited use)
Your ip or domain can be excluded if you overuse the service. You'll get a blocked message if you make a combination of:
- more than 120 pdfs in two hours with a single ip, and/ or
- the pdf's you make take more than 500 secs to process on our servers and/ or
- you try to circumvent these limits
We exclude ip's and/ or domains to safeguard from errors for the majority of users. An enterprise license is intended for large volume use.
The pool of cpu resources fluctuates throughout the day. You usually don't need to worry about the above rules, an individual will need to try very hard to get blocked.
The pdf making process can fail. Common reasons are:
- the pdf takes longer then 60 seconds to make. We automatically stop making the pdf, or
- the html of the site is large (e.g. lots of images > 1Mb), or
- the page will not load in a webkit browser (chrome/ safari). We use webkit to make pdf's, or
- there is a javascript error in the page from the pdf making software, try turning off javascript, or
- rarely there is a leeching organization/ individual sucking up resources and has not yet gotten automatically blocked.
An enterprise license is intended for helping you solve these types of problems.
Forum
Forum
If you want to join our forum, just click on the left hand tab labeled feedback when at http://pdfmyurl.com, or click on this link.
Bookmarklet
Introduction
The PDFmyURL bookmarklet is an a small script/application, that can be stored as the URL of a bookmark in a web browser or as a hyperlink on a web page. It is designed to add one-click functionality to a browser or web page. When clicked, the bookmarklet performs a function: PDF the current page of your browser.
Customization part 1: Creating a bookmarklet
The Default bookmarklet looks like this:
javascript:pdf_url=location.href;location.href='http://pdfmyurl.com?url='+escape(pdf_url)
This code can be customized by adding options to the javascript.
Click here for a complete list of options
For example: to make a portrait pdf with the bookmarklet you need to add (take a look at the advanced options on pdfmyurl itself to see all advanced options).
-O=Portrait
so that the bookmarklet code looks like this:
javascript:pdf_url=location.href;location.href='http://pdfmyurl.com?-O=Portrait&url='+escape(pdf_url)
Customization part 2: Creating a pdf button on a page
This piece of technology will let you place a "Make a PDF of this page" button on your website.
Making links on your page that can generate a pdf is easy. So if you would like to know if it is possible to generate a PDF automatically by a link study this page for some examples! A 'direct' link or function script than automatically generate a PDF according to the *current* content of a site is done as follows:
<a href="javascript:pdf_url=location.href;location.href='http://pdfmyurl.com?s=l&url='+escape(pdf_url)">A pdf button!</a>
If you look closely then you'll notice that the bold red bit corresponds to the bookmarklet example described above! So basically putting this nifty piece of html on your page, will allow users to click on your page, and make a pdf of the contents of just that page (just like a bookmarklet!). Go ahead and try it underneath:
A pdf button!
Chrome
A PDFmyURL chrome extention can be downloaded here
Firefox
A PDFmyURL Firefox extention can be found here
Joomla
A PDFmyURL Joomla CMS module can be downloaded here
Wordpress
Include the following line of code in an appropriate location inside your loop.
<a title="Download as PDF" href="http://pdfmyurl.com?url=<?php the_permalink() ?>">Download this post as PDF</a>
API
Introduction
Besides the web interface for converting webpages into pdf's we also have a API available.
The API is free to use and does not have any restrictions. See our terms and privacy policy for details.
Testing
Do the custom settings only work from the form on your site?
As I do testing if I put my url in the form on your site and the advanced features are set to Portrait then it generates the PDF Portrait, but if I do it in the URL, as my example below, then it generates the PDF Landscape.
When logged in to pdfmyurl.com, a cookie is set.
This cookie is meant to save your preferences.
If you want to remove these preferences, you will need to remove the .pdfmyurl.com cookie for testing.
Example Use
A simple http server call can be made to convert any url to a pdf
http://pdfmyurl.com?url={url}
where {url} is the (url encoded) location of webpage beginning with http://
The pdf is then generated by our servers and sent to the requesting machine.
Options
There are nummerous options available for customizing, manipulating or adding data to a pdf.
They can be used by adding parameters to the requested url
For example, if you want a landscaped pdf you add
--orientation=Landscape
and if you want to add a header with text aligned to the left you would use
--header-left=myHeader
You can also alter the default filename by providing a filename parameter
--filename=myfile.pdf
These three options combined in call would look like this:
http://pdfmyurl.com?url=mysite.com&-O=Landscape&--header-left=myHeader&--filename=myfile.pdf
List of optional parameters:
--html Don't pdf the url,but pdf the html posted content.
--png Don't make a pdf but make a png of the content.
--thumb Don't make a pdf but make a thumbnail of the content. With default height 100.
--thumb height Don't make a pdf but make a thumbnail of the content. With height as a parameter.
--original-url Set the --header-right parameter to be the url of
the created pdf page.
--filename <filename> Set the filename to download, default is a
filename made from the url.
-O, --orientation <orientation> Set orientation to Landscape or Portrait
-s, --page-size <size> Set paper size to: A4, Letter, etc.
-p, --proxy <proxy> Use a proxy
--username <username> HTTP Authentication username
--password <password> HTTP Authentication password
--custom-header <name> <value> Set an additional HTTP header (single)
-b, --book Set the standard options normally set when printing a book
--collate Collate when printing multiple copies
--cookie <name> <value> Set an additional cookie (repeatable)
--cookie-jar <path> Read and write cookies from and to the supplied cookie jar file
--copies <number> Number of copies to print into the pdf file (default 1)
--cover <url> Use html document as cover. It will be
inserted before the toc with no headers and footers
--custom-header <name> <value> Set an additional HTTP header (repeatable)
-H, --default-header Add a default header, with the name of the
page to the left, and the page number to
the right, this is short for:
--header-left='[webpage]'
--header-right='[page]/[toPage]' --top 2cm
--header-line
--disable-external-links Do not make links to remote web pages
--disable-internal-links Do not make local links
-n, --disable-javascript Do not allow web pages to run javascript
--disable-smart-shrinking Disable the pixel/dpi ratio intelligent shrinking strategy
-d, --dpi <dpi> Change the dpi explicitly
--encoding <encoding> Set the default text encoding, for input (default ISO-8859-1, see specs)
-g, --grayscale Generate PDF in grayscale
-l, --lowquality Generates lower quality pdf/ps. Useful to
shrink the result document space
-B, --margin-bottom <unitreal> Set the page bottom margin (default 10mm)
-L, --margin-left <unitreal> Set the page left margin (default 10mm)
-R, --margin-right <unitreal> Set the page right margin (default 10mm)
-T, --margin-top <unitreal> Set the page top margin (default 10mm)
--minimum-font-size <int> Minimum font size (default 5)
--no-background Do not print background
-O, --orientation <orientation> Set orientation to Landscape or Portrait
--page-height <unitreal> Page height (default unit millimeter)
--page-offset <offset> Set the starting page number (default 1)
-s, --page-size <size> Set paper size to: A4, Letter, etc.
--page-width <unitreal> Page width (default unit millimeter)
--password <password> HTTP Authentication password
--post <name> <value> Add an additional post field (repeatable)
--post-file <name> <path> Post an aditional file (repeatable)
--print-media-type Use print media-type instead of screen
-p, --proxy <proxy> Use a proxy
-q, --quiet Be less verbose
--redirect-delay <msec> Wait some milliseconds for js-redirects (default 200)
--replace <name> <value> Replace [name] with value in header and footer (repeatable)
--stop-slow-scripts Stop slow running javascripts
--title <text> Set the title of the generated pdf file (The
title of the first document is used if not specified)
-t, --toc Insert a table of contents in the beginning of the document
--user-style-sheet <url> Specify a user style sheet, to load with every page
--username <username> HTTP Authentication username
-V, --version Output version information an exit
--zoom <float> Use this zoom factor (default 1)
Raw HTML (beta):
--html <HTML code> Converts HTML code into a pdf
PNG (beta):
--png Converts the url to a PNG image file
--thumb Don't make a pdf but make a thumbnail of the content. With default height 100.
--thumb height Don't make a pdf but make a thumbnail of the content. With height as a parameter.
Headers And Footer Options:
--footer-center <text> Centered footer text
--footer-font-name <name> Set footer font name (default Arial)
--footer-font-size <size> Set footer font size (default 11)
--footer-html <url> Adds a html footer
--footer-left <text> Left aligned footer text
--footer-line Display line above the footer
--footer-right <text> Right aligned footer text
--footer-spacing <real> Spacing between footer and content in mm (default 0)
--header-center <text> Centered header text
--header-font-name <name> Set header font name (default Arial)
--header-font-size <size> Set header font size (default 11)
--header-html <url> Adds a html header
--header-left <text> Left aligned header text
--header-line Display line below the header
--header-right <text> Right aligned header text
--header-spacing <real> Spacing between header and content in mm
(default 0)
Table Of Content Options:
--toc-depth <level> Set the depth of the toc (default 3)
--toc-disable-back-links Do not link from section header to toc
--toc-disable-links Do not link from toc to sections
--toc-font-name <name> Set the font used for the toc (default
Arial)
--toc-header-font-name <name> The font of the toc header (if unset use --toc-font-name)
--toc-header-font-size <size> The font size of the toc header (default 15)
--toc-header-text <text> The header text of the toc (default Table Of Contents)
--toc-l1-font-size <size> Set the font size on level 1 of the toc (default 12)
--toc-l1-indentation <num> Set indentation on level 1 of the toc (default 0)
--toc-l2-font-size <size> Set the font size on level 2 of the toc (default 10)
--toc-l2-indentation <num> Set indentation on level 2 of the toc (default 20)
--toc-l3-font-size <size> Set the font size on level 3 of the toc (default 8)
--toc-l3-indentation <num> Set indentation on level 3 of the toc (default 40)
--toc-l4-font-size <size> Set the font size on level 4 of the toc (default 6)
--toc-l4-indentation <num> Set indentation on level 4 of the toc (default 60)
--toc-l5-font-size <size> Set the font size on level 5 of the toc (default 4)
--toc-l5-indentation <num> Set indentation on level 5 of the toc (default 80)
--toc-l6-font-size <size> Set the font size on level 6 of the toc (default 2)
--toc-l6-indentation <num> Set indentation on level 6 of the toc (default 100)
--toc-l7-font-size <size> Set the font size on level 7 of the toc (default 0)
--toc-l7-indentation <num> Set indentation on level 7 of the toc (default 120)
--toc-no-dots Do not use dots, in the toc
Outline Options:
--outline Put an outline into the pdf
--outline-depth <level> Set the depth of the outline (default 4)
Page sizes:
The default page size of the rendered document is A4, but using this
--page-size option. this can be changed to almost anything else, such as: A3,
Letter and Legal. For a full list of supported pages sizes please see
<http://doc.trolltech.com/4.6/qprinter.html#PageSize-enum>.
Paid features
Pdfmyurl.com offers two standard paid options, and one custom option:
Personal Features
- Customize or remove PDFmyURL logo for pdf's you make (personally)
- Set and save personal PDF'ing preferences!
- Orientation
- Paper size
- Background on/off
- Print-friendly
- Insert a table of contents
- Add title, url or coverpage to your PDFs
- Disable/enable links & javascript
- Access history of PDF's made
- Click here to surf to our pricing page
Business Features
- Place a "pdf this page" button on your website.
- Remove or customize the PDFmyURL watermark from all pdf's made from your domain
- All items of a personal account
- Manage how pdf's are made on your site
- Integration support via email
- Priority in development queue
- Click here to surf to our pricing page
Enterprise Features
- Private servers
- Priority email support
- Comply to PDF/A standards
- Click here to email us for pricing plans
Pdfmyurl is a service!
How can I implement pdfmyurl as a service?
It's easy if you know html. The following snippet of html shows how you can make a link of the url you want to pdf:
<a href="http://pdfmyurl.com?url=google.com">A pdf to download</a>
If you copy paste that into your website html editor, then you get (go ahead, try and click it!):
A pdf to download
How can I implement pdfmyurl so that it pdf's an array of urls, or Can your site simply put several webpages (on its own PDF page) into a a single PDF file?
You can also make a pdf of more than one url (an array of urls), just add a new url separated by a space (%20 in url encoding):
If you copy paste that into your website html editor, then you get:<a href="http://pdfmyurl.com?url=google.com%20cnn.com">A pdf to download</a>
A pdf to download with google and cnn
The next example demonstrates the png feature. Pdfmyurl can also make png's (too cool!):
<a href="http://pdfmyurl.com?url=google.com&--png">A png to download</a>
If you copy paste that into your website html editor, then you get (go ahead, try and click it!):
A png to download
If your into presenting thumbnails, then this example is for you:
<a href="http://pdfmyurl.com?url=google.com&--thumb">A thumb to download</a>
If you copy paste that into your website html editor, then you get (go ahead, try and click it!):
A thumb to download
You can also create the image:
The code for generating the image looks like this:
<img src="http://pdfmyurl.com?url=google.com&--thumb">
If you want to set the size of the thumbnail height (the default is 100 pixels, the ratio is preserved) then you can pass the height as a parameter.
<a href="http://pdfmyurl.com?url=google.com&--thumb=250">A thumb to download (at 250 pixels height) </a>
If you copy paste that into your website html editor, then you get (go ahead, try and click it!):
A thumb to download (at 250 pixels height)
More complicated urls (containing ampersands (&) and question marks (?)) need to be url encoded:
<a href="http://pdfmyurl.com?url=http%3A%2F%2Fwww.google.com%2Fsearch%3Frls%3Den%26q%3Dampersand%2Bin%2Burl%26ie%3DUTF-8%26oe%3DUTF-8&--filename=testencode.pdf"> An encoded url download</a>
The actual url (http://www.google.com/search?rls=en&q=url+encoding&ie=UTF-8&oe=UTF-8) was encoded at this site. Notice that a file name has been defined (see advanced options) with the &--filename=testencode.pdf option set. We added that to get the message across that you can still use all the advanced options. But the ampersands in the actual url needed to be pdf'd are encoded (%26). If you copy paste that into your website html editor, then you get (go ahead, try and click it!):
An encoded url to download
Sub-domains
Q: Does the Paid Business Features also allow me to pdf my sub-domains?
A: Yes, if the license is for mydomain.com, then the license will also work for subdomain.mydomain.com.
If you registered www.mydomain.com as the domain (i.e. with www as the subdomain), you will need to mail us for enabling the subdomains..
Vertical-text
Q: Can pdfmyurl make vertical text?
A: Yes. Please take a look at this site that shows how to make a cross browser vertical text
The following is an example page.
You can confirm that the following does make vertical text in a pdf:
http://pdfmyurl.com?url=http://www.cult-f.net/samples/vertical/sample.html
Private Server
For high volume or private PDF-ing we offer a hosted dedicated private server that can be configured to suit your needs. Please mail us for details.
CSS force Pagebreak
We need a page break option as used in MS word, is this possible?
Page breaks can be forced by CSS, see: http://www.w3.org/TR/CSS21/page.html and http://davidwalsh.name/css-page-breaks.
We've uploaded a test file to our server for testing:
http://pdfmyurl.com/test/test_pagebreak.html
For things to work the following option should be set: --print-media-type, used for print media-type instead of screen.
The following url demonstrates the working of this:
http://pdfmyurl.com/?url=http://pdfmyurl.com/test/test_pagebreak.html&--print-media-type
Is there a way to tell to not cut pictures in half without them starting a new page?
Add a css stylecreate a div with that class for each block of text/ image/ whatever you do not want to break up
.nobreak { page-break-inside: avoid; }
Font-size
Font size is handled by the media application (the browser, acrobat, etc) printing your page. So when defining fonts for different media applications a font can be too big or too small in the PDF generated.
If you wish constant font-size across media applications, then your best bet is to use pixels for the font-size.
In web media the font-size is usually defined in ems. You can read up on the open debate of using different metrics for defining font-sizes here at kyleschaeffer.com.
Pdfmyurl also has the --zoom parameter, which you can use to zoom in or out, making the fonts bigger/ or smaller.
You can also convert between different font-size metrics. The important thing to remember is that different devices will render font-size differently.
We've uploaded a test file to our server for testing. The following url demonstrates the working of this:
An example of using different font-size metrics when printing.
Fonts
The following html file defines some fonts. Notice the use of quotes in the style sheets, this is most important for things to work.
<html>
<head>
<title></title>
<style type="text/css">
.internal {
font-family: 'Comic Sans ms','cursive';
}
</style>
<link rel="stylesheet" type="text/css" media="screen, projection" href="http://pdfmyurl.com/test/external.css" />
</head>
<body>
<p style="font-family: 'Comic Sans ms','cursive';">Let's Test inline style sheet</p>
<p class="internal">Let's Test internal style sheet</p>
<p class="external">Let's Test external style sheet.</p>
<hr />
<code><style>font-family: 'Comic Sans MS', 'cursive';</style></code>
<p>Place <b>all</b> fonts within single quotes,
like 'Comic Sans MS'.
<p>Double-quotes work fine, too.</p>
</body>
</html>
A pdf with fonts to download
Please take a look at the following html list of fonts and the resulting pdf. Enterprise users can contact us to check if their font is supported.
Security
You can use the secure socket connection for creating a pdf at (notice the https protocol):
<a href="https://pdfmyurl.com/?url=google.com">A pdf to download</a>
If you copy paste that into your website html editor, then you get (go ahead, try and click it!):
A secure pdf to download
Note: this will not work for the domain www.pdfmyurl.com you must use pdfmyurl.com as the domain, or you will get a security certificate popup warning.
Numbering pages
How can I number the pages?
There is an advanced option to number pages:
--default-header: Add a default header, with the name of the page to the left, and the page number to the right, this is short for:
--header-left='[webpage]' --header-right='[page]/[toPage]' --margin-top 2cm --header-line
The following url demonstrates the working of this:
http://pdfmyurl.com/?url=http://pdfmyurl.com/test/test_pagebreak.html&--print-media-type&--default-header
Numbering pages, part 2
Ok, that's the top, how can I number the pages at the bottom of the document?
Use the advanced options to number the pages:--footer-left=[webpage] --footer-right=[page]/[toPage] --margin-bottom=2cm --footer-line
The following url demonstrates the working of this:
http://pdfmyurl.com/?url=http://pdfmyurl.com/test/test_pagebreak.html&--print-media-type&--footer-left=[webpage]&--footer-right=[page]/[toPage]&--margin-bottom=2cm&--footer-line
Footers And Headers:
How can I generate my own header and footer content, passing variables in the url?
Headers and footers can be added to the document by the --header-* and --footer* arguments respectfully. In header and footer text string supplied to e.g. --header-left, the following variables will be substituted.
* [page] Replaced by the number of the pages currently being printed * [frompage] Replaced by the number of the first page to be printed * [topage] Replaced by the number of the last page to be printed * [webpage] Replaced by the URL of the page being printed * [section] Replaced by the name of the current section * [subsection] Replaced by the name of the current subsection * [date] Replaced by the current date in system local format * [time] Replaced by the current time in system local format
As an example specifying --header-right "Page [page] of [toPage]", will result in the text "Page x of y" where x is the number of the current page and y is the number of the last page, to appear in the upper left corner in the document.
Headers and footers can also be supplied with HTML documents. As an example one could specify --header-html header.html, and use the following content in header.html:
<html>
<head>
<script>
function subst() {
var vars = {};
var x = document.location.search.substring(1).split('&');
for (var i in x) {
var z = x[i].split('=', 2);
vars[z[0]] = unescape(z[1]);
}
var x = ['date', 'time', 'name', 'frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection'];
for (var i in x) {
var y = document.getElementsByClassName(x[i]);
for (var j = 0; j < y.length; ++j) y[j].textContent = vars[x[i]];
}
}
</script>
</head>
<body style="border:0; margin: 0;" onload="subst()">
<!--
margin:25px 50px 75px 100px;
top margin is 25px
right margin is 50px
bottom margin is 75px
left margin is 100px
-->
<table style="border-bottom: 1px solid black; width: 100%;">
<tr>
<td style="text-align:left"><span class="name"></span> - <span class="section"></span> - <span class="date"></span></td>
<td style="text-align:right">
Page <span class="page"></span> of <span class="topage"></span>
</td>
</tr>
<tr>
<td style="text-align:left" colspan="2">A second line.</span>
</td>
</tr>
</table>
<br />
</body>
</html>
As can be seen from the example, the arguments can be sent to the header/footer html documents in get fashion.
The following url shows just the header (footer) part:
http://pdfmyurl.com/test/header.html?name=fooName§ion=fooSection
So, we've got that working, the nice thing is that most variables will be substituted automatically (page, date, time, etc...)
So we can now combine things, the following url demonstrates the working of this:
http://pdfmyurl.com/?url=http://pdfmyurl.com/test/alice.html&--margin-top=2cm&--header-html=http%3A%2F%2Fpdfmyurl.com%2Ftest%2Fheader.html%3Fname%3DAlice
Notice that the --header-html parameter has been url encoded (the / sign has become a %2F, etc.). This is complex, but is needed because the pdfmyurl server needs the complete url, and the & and ? characters will otherwise not be passed. You can read up on url encoding here.
HTML to PDF
If you want to convert HTML code to a PDF you can use the --html function.
Use this if your contents/page is not located online or behind a secured login area.
The following example also adds an image with base64 encoding (you can right click to copy the link into a text editor for further investigation)
Simply 'post' the content to our service like this:
http://pdfmyurl.com?--html=<h1>Hello,</h1><p>This is html content to be pdf'ed, and an image added:</p><img src="data:image/png;base64,iVBO...
If you have a business license, you can add your domain to the --license parameter, and the pdfmyurl logo will not show up.
http://pdfmyurl.com?--html=<h1>Hello,</h1><p>This is html content to be pdf'ed, and an image added:</p><img src="data:image/png;base64,iVBO...&--license=example.com
PHP example
The following php code snippet uses this as a principle:
<?php
// load the html file as a string:
$content = file_get_contents('test.html');
// the url that does the work
$url = "http://pdfmyurl.com";
//set the POST variables
$fields = array(
'--html'=>urlencode($content),
'--orientation'=>urlencode("portrait"),
'--licence'=>urlencode("domain.com") /* enter your domain for which you have a license here */
);
//url-ify the data for the POST
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
// get rid of trailing signs
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
// set the file to write to
$fp = fopen('/myfolder/to/save/to/test.pdf', 'wb');
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
// the file to put the results in
curl_setopt($ch, CURLOPT_FILE, $fp);
// the count the number of fields to post
curl_setopt($ch, CURLOPT_POST, count($fields));
// set up the fields to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
//execute post: and the work
$result = curl_exec($ch);
//close connection
curl_close($ch);
// returns 1 if success 0 if failed
echo $result;
?>
The php code is a proof of concept only, if you or someone you know is fluent in any other language, you should be able to translate the php code with reasonable effort.
If you have a business license, you can add your domain to the --license parameter, and the pdfmyurl logo will not show up.
Note: you must use pdfmyurl.com as the $url that does the work, this will not work for the domain www.pdfmyurl.com, or you will get a "301 Moved Permanently" header status response.
The basic flow is the same, if your use-case is the same:
- load the html file to be converted in a variable
- post the variable containing the html to our server, along with any other options
- get the pdf'ed version back and save it on your side for further processing
ASP example
The following asp code snippet shows how you can provide a link to pdf'ed content:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PDFGenerator._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
.errorMessage {
color: red;
font-family: Verdana;
font-size: small;
}
</style>
</head>
<body>
<form id="aForm" runat="server">
<asp:Label ID="labelErrorMessage" runat="server" CssClass="errorMessage" EnableViewState="false"></asp:Label>
<br />
<asp:HyperLink ID="pdfLink" runat="server">Get PDF</asp:HyperLink>
</form>
</body>
</html>
We can manipulate the HyperLink control in the Page_Load event which is triggered when a page loads:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections;
using System.Text;
using System.Net;
namespace PDFGenerator
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// this is where the html file is at:
string path = Server.MapPath(@"html\convertMe.htm");
// Check if the file is there.
if (File.Exists(path))
{
// The following shows how to generate the link (url) that when clicked is pdf'ed
string theHtmlToConvert = Server.UrlEncode( File.ReadAllText(path) );
string URL = "http://pdfmyurl.com?--html=" + theHtmlToConvert;
pdfLink.NavigateUrl = URL;
// The following is commented. Uncomment to download the pdf to the web server
//string DestinationPath = "C:\\AllThePdfs\\example.pdf";
//System.Net.WebClient Client = new WebClient();
//Client.DownloadFile(URL, DestinationPath);
}
else
{
labelErrorMessage.Text = "Unable to locate the html file for conversion.";
}
}
}
}
Running this example, the user now has a link which sends the html file to the pdfmyurl server ("html\convertME.htm").
Also take a look at the commented example code, which shows how you can download the pdf to the web server.
User quotes, questions and answers
FYI, I'm generating PDFs using your service in a unique way that you may be interested in. I'm processing the output of a PHP script directly to PDF (not displaying it on screen) by using a form to pass along all the details to your http://pdfmyurl.com site. For example, here's the code from a page, which automatically creates a PDF of the dynamic output of another page when a 'Save as PDF' form button is clicked:
$pdf_name=$underscore_name."_".$dash_start_date."_".$dash_end_date."_.pdf";
<form id="id" method="post" action="http://pdfmyurl.com?--filename=$pdf_name&--margin-top=5&--margin-bottom=5&--orientation=Portrait&--username=user&--password=pass">
<input id="url" name="url" type="hidden" value="https://mysite.com/jk/page.php?access=$access&company_id_search=$company_id_search&company_search=$company_search&client_since=$ client_since&start_date=$start_date&end_date=$end_date&tc_agreement=$tc_agreement&bu=$bu&hosting=$hosting">
<INPUT TYPE='SUBMIT' name="Submit" id="icon" value="Save as PDF">
</form>
I seriously love PDFmyURL It saved my butt again today:
The European Patent
Office doesn't automatically generate PDFs of patent application data like
the US Patent office does.
I used PDFmyURL to add the record to a patent
application's file. !!!