Rectangle 27 5

Quick answer - no and it is quite unlikely you will find a cross-browser solution. It is very unlikely that you will find a PDF-perfect solution. Better to think about having the users edit HTML and generate the PDF at the server.

Why - the PDF format is both brilliant and fiendish at the same time. Brilliant because of its portability, but fiendish because of the internal structure and storage mechanisms. There is no friendly 'DOM' like with HTML. If we were starting out afresh to develop a portable document format it would not be PDF that we would choose. But PDF currently has too much momentum to be thrown away, period.

Younger viewers might be wondering how the hell this manic format got into its market leading position and where it came from. Well, when the founding fathers of PDF were laying down the design, before XML, JSON, HTML and even the Internet, they weren't working with today's document sharing in mind. They were working on a better way to encode printing instructions - the PostScript printer driver concept. These were never expected to be edited before the printer consumed them, and they were worthless for any other purpose. Then someone noticed the you could interpret the PostScript drawing instructions to a screen, and subsequently someone spotted the fantastic potential to employ this as a transportable, cross device display concept. And here we are.

Back to the question - to edit a PDF in any meaningful GUI way, you would need to unpack the PDF and render the components (images, formatted text, pages) to the display device; then allow folks to mess with the layout; then re-pack the PDF. You would have to do this perfectly in line with the PDF standards otherwise you may find the downstream consumers of your edited PDF file crash or are unable to render it. You would have to cater for the various Acrobat standard levels, and the shortcuts and bloats that the editing package (Word, Illustrator, InDesign) vendors chuck into the PDF file; layers, thumbnails, etc.

Then we come to colors. Have a read of the PDF spec and you will see that there are an array of colorspace options that the original PDF producer can decide to use. You would have to interpret these to a reasonable device color on the screen and back, etc.

And then fonts. Fonts might be embedded subset, or not. To keep fidelity with the PDF you will need to realise the glyphs as vector graphics on your drawing surface at the scale defined in the PDF. This mostly means utilising some kind of platform-dependant type library - tricky cross-platform. Plus the fact that you will need to licence the fonts for appropriate use which can be pricey for the fonts most people want to use to look hip and professional.

Given the layering, scaling and rotating features in PDF, you would likely be looking at an html canvas as the drawing surface. Anyone who knows will tell you that in the world of canvas you are pretty much on your own for word-processing type functions.

Components that render PDF to a display are largely acting as print drivers, slavishly obeying the PDF drawing instructions, and usually generating a raster or sometimes an SVG graphic. This is a one-way street - they read and draw, but there is no sense of 'handles' to the objects drawn. No handles means no manipulation, and these guys certainly have little intention of letting you modify and write back.

You will find many 'save to pdf' products. When client-side they will be leaning toward grabbing a set of pixels and dumping a raster graphic into a file with the thinnest veneer of 'PDF' definition wrapped around it. Where they are server based then they can be quite powerful - there are plenty of tools like Aspose, and ABCPDF that truly offer some PDF wrangling server side - but this is not what you are looking for in your OP.

Summary - very complicated subject. If anything ever emerges as a potential it will likely have many constraints in terms of the PDF features covered and thus restrictions on what it can safely edit.

If you are looking for online editing of documents that are ultimately exported as PDF, then a way forward is to keep an html version of the document source and have the user edit this with TinyMCE, CKEditor, etc, then use one of the server-side tools to take the saved source HTML and render out to PDF. Tools like ABCPDF render HTML faithfully let you add images, headers and footers, page numbers, etc.

This is a pragmatic answer to your (assumed) need, though it still has some trade-offs in terms of the font (licencing) issues, clunkiness of browser-based editors, all-round weirdness of the HTML laid down by some HTML editing components, etc. But it IS viable.

Final thoughts - rethink the scope of what you need. If HTML editing and convert to PDF at server is usable for you it is a well-trodden path and you will find both free and commercial components for client and server to support it.

Edit: If you need to annotate the PDF then things are much easier. On the server, you need to generate images of the pages of the document, send those to the client, display them to the user, let the user mark them up, capture the co-ordinates of the annotations back to the server and use a server-side PDF library to render the annotations into the PDF. It is achievable, though requires various skillsets for server-side PDF to image manipulation and client side presentation and annotation capture.

Basically what is needed is for users to open up a previously uploaded PDF, highlight or circle sections, and then save those annotations to the PDF back on the server. Due to the setup of the application, there's really nothing server side I can do besides send and receive the file's base64.My hopes were to take the PDF and draw an image of the highlights onto it. No text editing or manipulation of the document contant needs to happen.

Howdy! With regards to obtaining the coordinates of an 'annotation' box drawn 'over' a PDF (likely in a separate overlaying canvas), do you have any suggestions on how to accurately determine the PDF X,Y coords of the start of a drawn box (top left) along with the height/width of said box? I don't need to rewrite these to the PDF, just need to be able to get them and store them. Thanks in advance! :)

@VanquishedWombat - So, we don't need to actually add an "annotation" per se, we more so need to know the coords of a box drawn over a PDF, and I had read a bunch of posts claiming that the X,Y system was different in PDF than in a browser - but I'm just getting to develop that part of the app so it'll be interesting to find out! Basically, we're displaying a user uploaded PDF in the browser, and using Fabric.js, allowing the user to draw boxes over the PDF - with those coords/dimensions, we will later snip images out of the PDF. I'll post back if I run into specific issues. Thanks again!

javascript - Edit *existing* PDF in a browser - Stack Overflow

javascript pdf html5-canvas pdf.js
Rectangle 27 2

If printing the PDF using conventional means (e.g. Adobe Reader), the PDF MUST be downloaded to the browser's cache to be opened and printed. There is no way around that.

Now you can probably prevent the average Joe from saving the PDF locally via the following technique, but any savvy user will be able to inspect your HTML's source and download the PDF directly.

  • Output your PDF in iText such that when the PDF is opened, a print action automatically occurs
  • Put an invisible IFRAME on your HTML page which loads this PDF, but is not visible in the browser to your user

When the user loads your HTML page, the PDF will be loaded in the IFRAME and sent to the users printer (presuming that Adobe Reader is installed in the browser). Yes, the PDF will end up in the browser cache, but the user would have to be savvy enough to both recognize this and then hunt it down in their browser's cache.

If this is not acceptable, you're going to have to look at converting the PDF to another file type (e.g. pages are rendered to images displayed in the browser or perhaps a Flash / Java object that sends each page in the document to the printer directly)

Hi - thanks for this answer - one problem I'm having is that the PDF print dialog is coming up REALLY slow, even when I have a simple "Hello, World" PDF. Any thoughts on how to speed it up?

java - Create a "print-only" PDF with itext - Stack Overflow

java pdf itext
Rectangle 27 2

The printing depends on how you are letting the browser display the PDF. If you are letting the browser display them "normally" either a plugin (Adobe, FoxIT) or its native display of PDFs, then there is not much you can do, since you can't use JavaScript to access those.

You could use pdf.js which renders the PDF using JavaScript on a canvas which you can print, see for example Printing PDF using pdf.js

javascript - HTML2PDF automatic printing - Stack Overflow

javascript php jquery html2pdf
Rectangle 27 8

For printing I don't set any width and remove any obstacles which keep your print layout from having a dynamic width. Meaning if you make your browser window smaller and smaller, no content is cut/hidden but the document just gets longer. Like this, you can be sure that the rest will be handled by the printer/pdf-creator.

What about elements with a fixed width such as images or tables?

  • scale images down in your print CSS to a width which you can assume will fit in any case, use pt not px (but print will need more points/unit anyways, so this should hardly be a problem)
  • use landscape if you really have tables with loads of information
  • extract content, print it as paragraphs

But what about elements with a fixed width such as images and tables?

css - Safe Width in Pixel for Printing Web Pages? - Stack Overflow

css design printing
Rectangle 27 1

In theory yes, through CSS and by using a print stylesheet.

In practice no, for example because browsers tend to add (and reserve space for) their own headers and footers.

Generating a PDF would be a way, way more reliable way for label printing.

If you still want to do it in HTML, these will help:

javascript - "avery" type templates in the browser - Stack Overflow

javascript html printing
Rectangle 27 23

I ended up bailing on Adobe Acrobat here and going with FoxIt Reader (Free pdf reader) to do my pdf printing. This is the code I'm using to print via FoxIt in C#:

Process pdfProcess = new Process();
pdfProcess.StartInfo.FileName = @"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe";
pdfProcess.StartInfo.Arguments = string.Format(@"-p {0}", fileNameToSave);
pdfProcess.Start();

The above code prints to the default printer but there are command line parameters you can use to specify file and printer. You can use the following syntax:

Apparently earlier versions of acrobat do not have the problem outlined above either. If you use a much older version (4.x or something similar) it does not exhibit this problem.

Some printers do support native pdf printing as well so it's possible to send the raw pdf data to the printer and it might print it. See https://support.microsoft.com/en-us/kb/322091 for sending raw data to the printer.

In later versions of our software we ended up using a paid product:

This saves my life! I've tried so many things to print PDFs silenty ... the Adobe Reader via command line, a windows service invoking the Adobe Reader, some WinAPI trickery. With any approach either the Adobe Reader window came up or it simply didnt print. Thanks a lot for this hint!

I'm pretty sure with the latest version of FoxIt this is no longer supported. I think they've integrated it into the paid version at this point.

c# - Printing a PDF Silently with Adobe Acrobat - Stack Overflow

c# acrobat
Rectangle 27 11

Apache PDFBox. It is currently in incubation, but the PDF printing functionality has been around before that. Internally, it uses the Java Print Services to create a print job, and it also supports silent printing.

Do note that it requires Fontbox as well, and the current (upcoming 0.8.0 release) has included graceful fallback for documents with Type 0 fonts. Type 1 fonts are printed correctly; however in 0.7.3, attempts to print documents with Type 0 fonts will result in an exception being thrown.

I tried this, but the pdf's printed at least mainly blank (sometimes completely blank pages, sometimes just a section).

Well, the command line (PrintPDF) seems to work and print everything (even if it makes a mess of my transparent PNG image)

That's a bit strange, considering that command line printing seems to have worked (except for the PNG image). I'll check how PNGs are represented in the PDFBox model. By the way, are you trying this with 0.7.3 or a later release?

It was a few older generated pdf's in particular... perhaps it was due to using a prior version of flying saucer to generate the pdf. Newly generated pdf's are fine. BTW +1 - it's working now...

Version 0.8.0. As for +1, I would vote, but apparently I already have, and too long ago too :(. I hope it was already an up vote.

Silent Printing of PDF From Within Java - Stack Overflow

java pdf printing pdf-generation
Rectangle 27 25

I ended up bailing on Adobe Acrobat here and going with FoxIt Reader (Free pdf reader) to do my pdf printing. This is the code I'm using to print via FoxIt in C#:

Process pdfProcess = new Process();
pdfProcess.StartInfo.FileName = @"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe";
pdfProcess.StartInfo.Arguments = string.Format(@"-p {0}", fileNameToSave);
pdfProcess.Start();

The above code prints to the default printer but there are command line parameters you can use to specify file and printer. You can use the following syntax:

Apparently earlier versions of acrobat do not have the problem outlined above either. If you use a much older version (4.x or something similar) it does not exhibit this problem.

Some printers do support native pdf printing as well so it's possible to send the raw pdf data to the printer and it might print it. See https://support.microsoft.com/en-us/kb/322091 for sending raw data to the printer.

In later versions of our software we ended up using a paid product:

This saves my life! I've tried so many things to print PDFs silenty ... the Adobe Reader via command line, a windows service invoking the Adobe Reader, some WinAPI trickery. With any approach either the Adobe Reader window came up or it simply didnt print. Thanks a lot for this hint!

I'm pretty sure with the latest version of FoxIt this is no longer supported. I think they've integrated it into the paid version at this point.

c# - Printing a PDF Silently with Adobe Acrobat - Stack Overflow

c# acrobat
Rectangle 27 2

I've tried both Adobe Reader and Foxit without luck. The current versions of both are very fond of popping up windows and leaving processes running. Ended up using Sumatra PDF which is very unobtrusive. Here's the code I use. Not a trace of any windows and process exits nicely when it's done printing.

public static void SumatraPrint(string pdfFile, string printer)
    {
        var exePath = Registry.LocalMachine.OpenSubKey(
            @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
            @"\App Paths\SumatraPDF.exe").GetValue("").ToString();

        var args = $"-print-to \"{printer}\" {pdfFile}";

        var process = Process.Start(exePath, args);
        process.WaitForExit();
    }

c# - Printing a PDF Silently with Adobe Acrobat - Stack Overflow

c# acrobat
Rectangle 27 3

I've tried both Adobe Reader and Foxit without luck. The current versions of both are very fond of popping up windows and leaving processes running. Ended up using Sumatra PDF which is very unobtrusive. Here's the code I use. Not a trace of any windows and process exits nicely when it's done printing.

public static void SumatraPrint(string pdfFile, string printer)
    {
        var exePath = Registry.LocalMachine.OpenSubKey(
            @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
            @"\App Paths\SumatraPDF.exe").GetValue("").ToString();

        var args = $"-print-to \"{printer}\" {pdfFile}";

        var process = Process.Start(exePath, args);
        process.WaitForExit();
    }

c# - Printing a PDF Silently with Adobe Acrobat - Stack Overflow

c# acrobat
Rectangle 27 3

To answer your first question, this can be fairly straight forward depending on the data. We have a variety of Service-based applications that do exactly what you are asking. Typically, we parse the incoming file and wrap our own Postscript or PCL around it. If you layout is fairly simple, then there are some very basic PCL codes you can wrap it with to provide the font/print layup you want (I'd be more then happy to give you some guidance here offline).

One you have a print ready file you can send it to a UNC printer that is shared, directly to a locally installed printer, or even to the IP of the device (RAW or LPR type data).

If, however, you are going down the PDF path, the simplest method is to send the PDF output to a printer that supports direct PDF printing (many do now). In this case you just send the PDF to the device and away it prints.

The other option is to launch Ghostscript which should be free for your needs (check the licensing as they have a few different version, some GNU, some GPL etc.) and either use it's built in print function or simply convert to Postscript and send to the device. I've used Ghostscript many times in Service apps but not a huge fan as you will basically be shelling out and executing a command line app to do the conversion. That being said, it's a stable app that does tend to fail gracefully

c# - Printing from a .NET Service - Stack Overflow

c# .net windows-services printing
Rectangle 27 1

I know this is an old question, but I just had to remove the registration/bleed marks on a 155 page PDF file, and figured I'd share my solution. This is in Acrobat Pro 10.1

Since the document was meant for 8.5 x 11 paper, I went

As long as the registration marks are accurate for the size of the paper you're "printing" to, the result should be a new PDF with pages that fall within the registration marks, effectively cropping them all off.

editing - Removing printer marks from a PDF file - Stack Overflow

pdf editing
Rectangle 27 0

You can do that with FOP if you wish and if you install the PDF Images Plug-In for FOP

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="a3" margin-right="0mm" margin-left="0mm" margin-bottom="0mm" margin-top="0mm" page-width="42cm" page-height="29.7cm">
            <fo:region-body margin-left="0mm" margin-top="0mm" margin-bottom="0mm" margin-right="0mm"/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="a3n">
            <fo:repeatable-page-master-alternatives>
                <fo:conditional-page-master-reference master-reference="a3" page-position="any"/>
            </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="a3n">
        <fo:flow flow-name="xsl-region-body">
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="0mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=2"/>
                </fo:block>
            </fo:block-container>
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="209mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=3"/>
                </fo:block>
            </fo:block-container>
            <fo:block-container>
                <fo:block font-size="0.1pt" page-break-after="always" break-after="page"></fo:block>
            </fo:block-container>
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="0mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=4"/>
                </fo:block>
            </fo:block-container>
            <fo:block-container height="29.7cm" width="20.9cm" top="0mm" left="209mm" position="absolute">
                <fo:block>
                    <fo:external-graphic content-height="29.7cm" content-width="21cm" height="29.7cm" width="21cm" src="yourpathdoc.pdf#page=1"/>
                </fo:block>
            </fo:block-container>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

In case you want it portrait for easier printing, simply switch the page-width and page-height of the simple-page-master and replace the four block-container lines containing the position="absolute" with

<fo:block-container height="29.7cm" width="21cm" top="0mm" left="0mm" position="absolute" reference-orientation="270">
...
            <fo:block-container height="29.7cm" width="21cm" top="210mm" left="0mm" position="absolute"  reference-orientation="270">
...
            <fo:block-container height="29.7cm" width="21cm" top="0mm" left="0mm" position="absolute" reference-orientation="270">
...
            <fo:block-container height="29.7cm" width="21cm" top="210mm" left="0mm" position="absolute"  reference-orientation="270">

and if you have more than two pages don't forget to insert the

<fo:block-container>
                <fo:block font-size="0.1pt" page-break-after="always" break-after="page"> </fo:block>
            </fo:block-container>

@MikeTaylor, any success with it? Saying "Thanks" in SO means to check the mark to accept an answer :-)

xslt - Using FOP to pull pages from an A4 PDF and create a A3 PDF - St...

pdf xslt pdfbox fop
Rectangle 27 0

It looks like a Flash-based solution would work best for you in this situation, such as Adobe FlashPaper. There is no dependency on the browser having a PDF plug-in that displays the document in the browser, such as Adobe Reader or Foxit Reader. It supports zooming, searching, printing, full-screen mode, and text selection, and you don't have to rely on a third-party hosted solution like Scribd.

Displaying a PDF Document in ASP.net page - Stack Overflow

asp.net pdf
Rectangle 27 0

Regarding your comment and as a partial answer, always use only free fonts. For example Times New Roman isn't (and as a linux user I don't have it) and should be preferred Liberation Serif (just like Arial should be replaced by Liberation Sans Narrow).

To have more stylistic freedom regarding the fonts, you could use Google Fonts.

Note also that both in browser display and in print, you can't really have exactly identical inputs in your form.

When I want to have a printing version exactly accorded to your need (including regarding pagination), I add a link building a PDF version of my page.

css - Is there a way to print a website the same across every browser?...

css firefox printing explorer
Rectangle 27 0

I think we are going to go the third party route. I like the XSL -> HTML -> PDF -> Printer flow... Winnovative's HTML to PDF looks good for the first part, but I'm running into a block finding a good PDF printing solution... any suggestions? Ideally the license would be on a developer basis, not on a deployed runtime basis.

c# - Printing from a .NET Service - Stack Overflow

c# .net windows-services printing
Rectangle 27 0

You may try Aspose.Pdf.kit to print the PDF file to either physical or virtual printer while hiding the print dialog. In order to hide the print dialog, you only need to set PrintPageDialog property to false.

c# - Printing a PDF File silently from .NET application - Stack Overfl...

c# asp.net pdf
Rectangle 27 0

I've used Foxit to do this in the past. Check out my question/solution here: Printing a PDF Silently with Adobe Acrobat

This is what i ended up using. It completes the printout completely silenty which is exactly what i wanted

c# - Printing a PDF File silently from .NET application - Stack Overfl...

c# asp.net pdf
Rectangle 27 0

It is also possible to do it with an embedded web browser, note however that since this might be a local file, and also because it is not actually the browser directly and there is no DOM so there is no ready state.

Here is the code for the approach I worked out on a win form web browser control:

private void button1_Click(object sender, EventArgs e)
    {
        webBrowser1.Navigate(@"path\to\file");
    }  

    private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    {   
        //Progress Changed fires multiple times, however after the Navigated event it is fired only once,
        //and at this point it is ready to print
        webBrowser1.ProgressChanged += (o, args) => 
        {
            webBrowser1.Print();//Note this does not print only brings up the print preview dialog
            //Should be on a separate task to ensure the main thread 
            //can fully initialize the print dialog 
            Task.Factory.StartNew(() => 
            {
                Thread.Sleep(1000);//We need to wait before we can send enter
                //This assumes that the print preview is still in focus
                Action g = () =>
                {
                    SendKeys.SendWait("{ENTER}");
                };
                this.Invoke(g);
            });
        };
    }

.net - Print Pdf in C# - Stack Overflow

c# .net pdf printing
Rectangle 27 0

1) I think only the first two are actually stored in the PDF, but the third value (print size) is directly related to resolution (538x375) and pixel density (72ppi aka 72dpi), so it can easily be calculated anyway.

2) It seems like you're going about this a little backward. There are plenty of applications that are perfectly suited to controlling image layout and printing. Adobe Illustrator is one of the most common and there are some free ones, too. But these are going to involve loading the images, visually arranging them on the page and adjusting the print sizes visually, rather than programmatically.

2) If you did want to do this programmatically, though, I think you're going to have a hard time finding software to solve that problem. GIMP and Photoshop both have some batching capability, and I know GIMP has a fairly robust CLI, so you might be able to use that.

3) Yes, you'll start with the print size you want, divide the number of pixels by the number of inches to get ppi/dpi.

NOTE: Keep in mind that dpi goes both directions. If you have a 200 x 300 image and a 400 x 400 image, and you want them both to print 10 inches square, then you're going to distort the 200 x 300 image, stretching it horizontally. The 200 x 300 image will also look poorer quality than the 400 x 400, because you have fewer pixels to work with.

For these and other reasons, I highly recommend a visual approach, rather than a coding approach.

I continued to read about imagemagick. It's tool convert is quite powerful in even batch processing pages in multiple pdf documents. It comes along with a "resize" and "density" option, where density means resolution. When I apply them to the documents and investigate the output then I find that in both cases the produced pdf still has 72dpi and the geometry has changed. Is there any way to change the density/ resolution factor to something different than 72 without touching the image itself? Why is it 72 anyways? :)

In short, yes there is a way. And 72dpi is a standard for printing. I think it's worth noting that you're not really working with images. PDFs are specifically designed to be a document print medium. I find it plausible that PDFs don't support anything other than 72dpi. Or they make it hard not to use 72dpi, specifically because 72dpi is a standard resolution for print media. But that's just a guess... That being said, PDFs are really little more than JPGs with some extra features, so it'd be relatively easy to change the DPI in GIMP without changing the geo. Not sure about batching, tho....

printing - How to change the dpi of differently sized images within a ...

pdf printing imagemagick dpi imagemagick-convert