Print using GDI+ and plain PrintDocument object to a pdf file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pamela fluente

    Print using GDI+ and plain PrintDocument object to a pdf file

    hi,

    What is the cleanest and effective way to use the PrintDocument object
    to print
    directly to a pdf file "myfile.pdf " (with no prompt to the user: just
    print to file and make pdf) ?

    Does anyone have a simple code snippet? Either VB or C# will be
    perfect.

    -Pam

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Print using GDI+ and plain PrintDocument object to a pdf file

    Pam,

    This is dependent on the print driver that you are using. Have you
    tried setting the PrintFileName property on the PrinterSettings instance
    used with your PrintDocument?

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "pamela fluente" <pamelafluente@ libero.itwrote in message
    news:1176365405 .410921.275680@ o5g2000hsb.goog legroups.com...
    hi,
    >
    What is the cleanest and effective way to use the PrintDocument object
    to print
    directly to a pdf file "myfile.pdf " (with no prompt to the user: just
    print to file and make pdf) ?
    >
    Does anyone have a simple code snippet? Either VB or C# will be
    perfect.
    >
    -Pam
    >

    Comment

    • pamela fluente

      #3
      Re: Print using GDI+ and plain PrintDocument object to a pdf file

      On 12 Apr, 18:10, "Nicholas Paldino [.NET/C# MVP]"
      <m...@spam.guar d.caspershouse. comwrote:
      Pam,
      >
      This is dependent on the print driver that you are using. Have you
      tried setting the PrintFileName property on the PrinterSettings instance
      used with your PrintDocument?
      Hi Nicholas ,

      thanks for you reply. I am afraid I do not get what you mean.

      Let's make a simple example. Assume I simply want to send into a new
      pdf file (MyFile.PDF) a string, for instance

      Private Sub PrintDocument1_ PrintPage1(ByVa l sender As Object,
      ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
      PrintDocument1. PrintPage
      e.Graphics.Draw String("How are you?", New
      Font(FontFamily .GenericSansSer if, 18, FontStyle.Bold,
      GraphicsUnit.Pi xel), Brushes.Green, Point.Empty)
      End Sub

      without prompting the user. What would your suggestion be in this
      case ?

      -P

      >
      Hope this helps.
      - Mostra testo tra virgolette -

      Comment

      • Rick

        #4
        Re: Print using GDI+ and plain PrintDocument object to a pdf file

        Pamela,

        Are you tring to create a PDF by printing to it using the PrintDoc?

        If so, no way. PrintDoc can draw on a canvas like a bitmap or printer
        canvas, but it cannot create a PDF.

        If you want to create a PDF you can check iTextSharp a free and very good
        dll for creating PDF's.

        Rick


        "pamela fluente" <pamelafluente@ libero.itwrote in message
        news:1176365405 .410921.275680@ o5g2000hsb.goog legroups.com...
        hi,
        >
        What is the cleanest and effective way to use the PrintDocument object
        to print
        directly to a pdf file "myfile.pdf " (with no prompt to the user: just
        print to file and make pdf) ?
        >
        Does anyone have a simple code snippet? Either VB or C# will be
        perfect.
        >
        -Pam
        >

        Comment

        • pamela fluente

          #5
          Re: Print using GDI+ and plain PrintDocument object to a pdf file

          On 12 Apr, 23:30, "Rick" <R...@LakeValle ySeed.comwrote:
          Pamela,
          >
          Are you tring to create a PDF by printing to it using the PrintDoc?
          >
          If so, no way. PrintDoc can draw on a canvas like a bitmap or printer
          canvas, but it cannot create a PDF.
          >
          If you want to create a PDF you can check iTextSharp a free and very good
          dll for creating PDF's.
          >
          Thanks Rick,

          I have downloaded it and tried the examples.
          The documents I need to print are by far too complicated, I think, for
          that library.
          I have thousands of objects and a lot of overlapping pictures with
          alpha transparency
          an so on. And all the (complex) logic is already implemented as
          drawing on a graphics.

          Let's try another direction. Is there a product or some api which
          allows me to print normally
          to a file and then convert the print file to PDF. Similar to what
          Adobe Distiller does?
          Or, more specifically, is there a kind of DLL version of Distiller (or
          similar program ) which allows
          creating directly a PDF from a plain print output file, *without*
          prompting the user ?

          -P


          Comment

          • Rick

            #6
            Re: Print using GDI+ and plain PrintDocument object to a pdf file

            You can check PDFCreator. If you know how to create what you want in some
            other program, then you can use PDFCreator as the print driver to output to
            PDF.

            The problem is then that you have to have this installed as a print driver
            on all client machines.

            Yes, your project sounds complicated, however I think iTextSharp could do it
            since I think it can do anything that PDF can implement. The problem is the
            overhead in learning how. There is a very good book and very active ng, but
            then YOU still need to learn it.

            Sorry, I don't have other suggestions.

            Rick


            "pamela fluente" <pamelafluente@ libero.itwrote in message
            news:1176417370 .638566.245940@ p77g2000hsh.goo glegroups.com.. .
            On 12 Apr, 23:30, "Rick" <R...@LakeValle ySeed.comwrote:
            >Pamela,
            >>
            >Are you tring to create a PDF by printing to it using the PrintDoc?
            >>
            >If so, no way. PrintDoc can draw on a canvas like a bitmap or printer
            >canvas, but it cannot create a PDF.
            >>
            >If you want to create a PDF you can check iTextSharp a free and very good
            >dll for creating PDF's.
            >>
            Thanks Rick,
            >
            I have downloaded it and tried the examples.
            The documents I need to print are by far too complicated, I think, for
            that library.
            I have thousands of objects and a lot of overlapping pictures with
            alpha transparency
            an so on. And all the (complex) logic is already implemented as
            drawing on a graphics.
            >
            Let's try another direction. Is there a product or some api which
            allows me to print normally
            to a file and then convert the print file to PDF. Similar to what
            Adobe Distiller does?
            Or, more specifically, is there a kind of DLL version of Distiller (or
            similar program ) which allows
            creating directly a PDF from a plain print output file, *without*
            prompting the user ?
            >
            -P
            >
            >

            Comment

            • pamela fluente

              #7
              Re: Print using GDI+ and plain PrintDocument object to a pdf file

              On 13 Apr, 11:03, "Rick" <R...@LakeValle ySeed.comwrote:
              You can check PDFCreator. If you know how to create what you want in some
              other program, then you can use PDFCreator as the print driver to output to
              PDF.
              >
              The problem is then that you have to have this installed as a print driver
              on all client machines.
              >
              Yes, your project sounds complicated, however I think iTextSharp could do it
              since I think it can do anything that PDF can implement. The problem is the
              overhead in learning how. There is a very good book and very active ng, but
              then YOU still need to learn it.
              >
              Sorry, I don't have other suggestions.
              >
              Rick
              >
              thanks Rick,

              I will try that.

              Thank you for the advice.

              -P


              Comment

              • =?Utf-8?B?SmhvbiBEb2U=?=

                #8
                Re: Print using GDI+ and plain PrintDocument object to a pdf file

                Hi Rick

                Im using iTextSharp tool to create a PDF. My requirement is that I need to
                print each page from the PDF to different trays in a printer. Im using
                PrintDocument to switch betweeen trays. Now that, I need to send the PDF
                content of a single page to print using Graphics.DrawIm age. Is there any way
                of doing this?

                "Rick" wrote:
                Pamela,
                >
                Are you tring to create a PDF by printing to it using the PrintDoc?
                >
                If so, no way. PrintDoc can draw on a canvas like a bitmap or printer
                canvas, but it cannot create a PDF.
                >
                If you want to create a PDF you can check iTextSharp a free and very good
                dll for creating PDF's.
                >
                Rick
                >
                >
                "pamela fluente" <pamelafluente@ libero.itwrote in message
                news:1176365405 .410921.275680@ o5g2000hsb.goog legroups.com...
                hi,

                What is the cleanest and effective way to use the PrintDocument object
                to print
                directly to a pdf file "myfile.pdf " (with no prompt to the user: just
                print to file and make pdf) ?

                Does anyone have a simple code snippet? Either VB or C# will be
                perfect.

                -Pam
                >
                >
                >

                Comment

                Working...