Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone!

I have an issue with printing PDF need your help. I used the below code to print a PDF file:


C#
using PdfDocument = Spire.Pdf.PdfDocument;
static void Main(string[] args)
{

    PdfDocument doc = new PdfDocument();
    doc.LoadFromFile("SampleDocument.pdf");

    //Use the default printer to print all the pages
    //doc.PrintDocument.Print();

    //Set the printer and select the pages you want to print
    PrintDialog dialogPrint = new PrintDialog();
    dialogPrint.AllowPrintToFile = true;
    dialogPrint.AllowSomePages = true;
    dialogPrint.PrinterSettings.MinimumPage = 1;
    dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
    dialogPrint.PrinterSettings.FromPage = 1;
    dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

    if (dialogPrint.ShowDialog() == DialogResult.OK)
    {
        //Set the pagenumber which you choose as the start page to print
        doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
        //Set the pagenumber which you choose as the final page to print
        doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
        //Set the name of the printer which is to print the PDF
        doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

        PrintDocument printDoc = doc.PrintDocument;
        dialogPrint.Document = printDoc;
        printDoc.Print();
    }
    
}


The below code is from
Office Print PDF file in C# sample in C# for Visual Studio 2010[^]

All of the fields (except REPORT) are generated by the way that I use Acrobat Pro to create Form Field. 3 first fields have font style 3 OF 9 BARCODE and the others are Arial. In my project, I used itextsharp to add text for them. That means I created a template and then add content for it. I would like to print it but the line betweens 2 columns and the barcodes are missing
(Please see the file
SAMPLEDOCUMENT.PDF at link: Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.[^]
The requirement is silently printing the Pdf file (DO NOT OPEN ANY THING WHEN PRINTING). So that I can not use the some approaches like:
C#
Process p = new Process( );
p.StartInfo = new ProcessStartInfo( )
{
    CreateNoWindow = true,
    Verb = "print",
    FileName = path //put the correct path here
};
p.Start( );


because it always open Acrobat when printing. Although I can have a good result after printing by using this way, the problem is how to prevent Acrobat opening...

Thank you in advance!

Hong Phuc
Posted
Updated 21-Jan-16 23:13pm
v3
Comments
Member 9967950 22-Jan-16 2:23am    
Sorry about less experience in asking because of my first question here. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900