In a UWP program, I am trying to fill a pre-made PDF form using Syncfusion's PDF library.
I fill text fields using the following line:
(form.Fields["Date"] as PdfLoadedTextBoxField).Text = date; //date is a string
This works so far.
The rest of the text in the PDF has a custom letter-spacing, which I would like to match in the date as well. In order to accommodate Rich Text, I have enabled this option when preparing the form in Acrobat Pro DC.
The format I would use is the following:
<?xml version="1.0"?>
<body xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<p dir="ltr" style="letter-spacing: -0.04cm; margin-top:0pt;margin-bottom:8pt;line-height:12.95pt;font-family:Calibri;font-size:11pt">Sample text</p>
</body>
In case I fill in this code to Acrobat Pro DC as the Default text, the formatting works just fine. As soon as I enter this code manually to the form, it just shows the code; the same happens when I use the C# code above.
What is the proper way of filling this code to the PDF?
Is there a way to switch an HTML page to "print" mode?
When I print, a #media print style-sheet gets applied to the page.
I want to use the page with that print style applied to export to PDF as well. Ideally, if I could get the HTML that gets sent to the printer when I use window.print() I could export it to PDF. I use a server side library and C# to export to PDF.
Any ideas on how I can do this?
Thank you!
As per W3C standars there is no distinctive print mode for web pages except that you can define different CSS rules for #screen and #print media.
If you want to render a page as it is shown in print view somewhere it is show in screen view; use #print CSS for #screen also.
I want to display the report(pdf) which was available in the webpath assume (http://myservre/reports/myrepoft.pdf). Currently, It was being displayed via IFrame like this.
strReportPDFFile = "`http://myservre/reports/myrepoft.pdf`"
<IFRAME frameborder="1" onload="onchangestate()" src="" id="ifrmShowReport" frameborder="0" height="100%" width="100%" marginwidth="0" align="top" style="overflow: none;overflow-x: auto;display:none"></IFRAME>
document.getElementById("formContainer").style.display = "block";
document.getElementById("ifrmShowReport").style.display = "block";
document.getElementById("ifrmShowReport").src = strReportPDFFile;
The URL was displaying in the address bar which I want to hide URL. Is it possible ? If not, please suggest some better alternative.
I argue that the main reason of your question (hiding the URL of the PDF file) is for security issues.
E.g. you have some PDF files on your server that have to be sent and read only from intended audience and not from everybody.
I give you some basic hints on how to realize this intent:
place the PDF files out of the public root of your webserver
realize a server side script that:
check is the user is authenticated and have the grant to get the file
get some parmeters to retrieve the correct file
serve the file with this server side script content-disposition (as attachment, sending the correct Mime-Type and a "ficticious" URL)
Since you put C# in your question tags i address you on
Add a content-disposition to the header with C#:
Response.AddHeader("content-disposition", #"attachment;filename=""MyFile.pdf""");
Then you can display your pdf wherever u wish: blank page, iframe ...
It is sure you'll not find a solution just working with HTML/Javascript, not one of those easly to avoid for a medium level internet user.
I am doing asp.net project using C#.I want to display the contents that are being typed in HtmlEditor control onto a A4 size as preview and i also want to save this content to a file(.doc or .txt).
How do i do it??
Please help
You can bind html editor content in variable and then display variable in client side.
server side:
Private static string abc=string.empty;
abc=htmlcontrolname.content;
databind();
on client side:
<%= abc%>
Set page size
There is no way with JavaScript, HTML, CSS currently to set the page size for printing. It is in the CSS spec, but there is very limited support for it.
Save file
There is no IO in JavaScript. The best bet is to send the content to the server and return headers that force a downoad of the file.
Here are the requirements, the users needs to be able to view uploaded PDFs in the browser. They need to be able to add notes to the PDF and save the updated PDF to the server without having to save it to their machine and open it outside the browser.
Any ideas on how to achieve this are welcomed.
by the way I am working with an asp.net website (in C#).
I have no control over what the pdf looks like. It is uploaded client-side then other users need to view and an notes on top of the pdf.
The solution that I was thinking is to render the PDF to a jpeg and use javascript to plot coordinates of where the note should go.
here is a quick example of the html and javascript that create the json of note (using jQuery.)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<style type="text/css">
*
{
margin:0;
padding:0;
}
#PDF
{
position:absolute;
top:0;
bottom:0;
width:600px;
height:800px;
background:url(assets/images/gray.png) repeat;
float:left;
}
#results
{
float:right;
}
.comment
{
position:absolute;
border:none;
background-color:Transparent;
height:300px;
width:100px;
overflow:auto;
float:left;
top:0;
right:0;
font-family: Arial;
font-size:12px;
}
div.comment
{
padding-top:-20px;
}
.comment a.button
{
display:block;
padding-top:-20px;
}
</style>
</head>
<body>
<div>
<div id="PDF"></div>
<div id="results">
</div>
</div>
</body>
</html>
<script type="text/javascript" src="script/jquery.js"></script>
<script type="text/javascript">
var points = [];
$("#PDF").click(function(e) {
if ($("textarea.comment").length == 0) {
var that = this;
var txt = $("<textarea class='comment'></textarea>").css({ top: e.pageY, left: e.pageX }).blur(function() { $(this).remove(); }).keypress(function(e2) {
if (e2.keyCode == 13 && !e.shiftKey) {
var that2 = this;
$("#PDF").append($("<div class='comment'>").html(that2.value.replace(/\r/gi, "<br>")).css({ top: e.pageY, left: e.pageX }));
$(this).remove();
points.push({ "x": e.pageX, "y": e.pageY, "text": that2.value })
$("#results").append('{ "x": ' + e.pageX + ', "y": ' + e.pageY + ', "text": "' + that2.value + '" }<br/>');
}
});
$(this).append(txt);
txt.each(function() { this.focus(); })
}
});
</script>
So now I need to figure out how to:
Render a pdf to jpeg.
Recreate the PDF putting the annotations on top on it.
You can use GhostScript to render a PDF to JPEG.
Command line example:
gswin32c.exe -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r300 -sOutputFile=output.jpg input.pdf
You need to call GhostScript via the command line version (as above) or use a wrapper.
A Google search turned up this blog post:
A Simple C# Wrapper for Ghostscript
For creating a new PDF you have two main alternatives:
Modify the JPEG and convert the JPEG into PDF (you can use GhsotScript for the conversion)
Use A PDF library that imports your original PDF and add data on top of that
For PDF libraries see this SO question:
Building PDF Files with C#
My company, Atalasoft, provides components that let you view document images, including PDFs and annotate them and save the annotations back into the PDF. In our product suite, you would need dotImage document imaging and the PDF Reader add-on. You would be using dotAnnotate through our AJAX web controls. Here is a link to our online demo - the document displayed is a TIFF, but you could use a PDF too.
I don't think you will be able to have a user load a pdf in their browser, edit it, then save it to the server without them saving it to their machine and then uploading it to the server.
What you can do is setup a webform with a database backend that can represent the pdf, and when they edit it you can regenerate the PDF using itextsharp and loading the information from the database, that way when the user goes back to edit the PDF you can prepopulate the form with what already exists.
itextsharp is extremely easy to use, here is an example:
string sourceFile = "path/to/pdfTemplate.pdf";
PdfReader reader = new PdfReader(sourceFile);
PdfStamper stamper = new PdfStamper(reader, new FileStream("path/to/store/pdf/filename.pdf", FileMode.Create));
AcroFields fields = stamper.AcroFields;
//now assign fields in the form to values from your form
fields.SetField("input1", input1.Text);
fields.SetField("input2", input2.Text);
//close the pdf after filling out fields
stamper.SetFullCompression();
stamper.FormFlattening = true;
stamper.Close();
then if you wanted to show the actual PDF you could easily
Response.Redirect("path/to/store/pdf/filename.pdf");
We do this using lowagie on a Spring/Java platform.
Users are presented with pre-generated sales tax returns and can add certain manual adjustments in a few fields. We then recompute totals fields based on their manual input and save the whole thing back to our DB.
You can use either PDFSharp or itextsharp to create annotations. Haven't tried PDFSharp annotation but iTextSharp does work. You'll have to handle the editing on the server side. probably copy the file to a temp folder edit it and save it back.
You'll find itextsharp at http://itextsharp.sourceforge.net, annotation example: bottom at the page http://itextsharp.sourceforge.net/tutorial/ch03.html
pdfsharp: http://www.pdfsharp.net
If you are able to buy a third party library I'd pretty much recommend TxTextControl. http://www.textcontrol.com/en_US/
With this control you can write an editor, that lets you use your pdf as a template and allows the user make changes and save them. All within the browser, without the need to manually select a tempfile on the computer. Acessing is pretty much like using the TextProperty of a normal TextBox.
You did not specify what technology limitations you have. If you can consider a Silverlight solution, and you have client computers that support Silverlight, you can easily do this.
Take a look at how Microsoft Sketchflow works, it permits the user to annotate documents in the web browser and the annotations are persisted back to the server.
Here is a company with a commercial control to annotate PDF (and other formats).
Microsoft does this in their Sketchflow player. Here is a video. Of course you would not be using sketchflow but rather implimenting something similar that meets your needs.
As an added bonus Silverlight 4 supports the clipboard as well as drag and drop so that end users could paste something onto the PDF immage as well as drag any file onto it ehich you would then be able to upload to your server.