---
title: "Write Raster And Vector Graphics To PDF"
canonical: https://www.graphicsmill.com/samples/Codecs/Pdf/WriteRasterAndVectorGraphicsToPdf_cs
product: "Graphics Mill"
source: "Codecs/Pdf/WriteRasterAndVectorGraphicsToPdf.cs"
---

# Write Raster And Vector Graphics To PDF

Saves raster and vector graphics to PDF format.

## Instruction

Write a C# program that saves both raster and vector graphics to a PDF file, with compression applied to reduce file size.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var writer = new PdfWriter("WriteRasterAndVectorGraphicsToPdf.pdf"))
{
    // Reduce output file size
    writer.Compression = CompressionType.Jpeg;
    writer.Quality = 80;

    writer.AddPage(800, 650, RgbColor.White);

    using (var graphics = writer.GetGraphics())
    {
        // Draw bitmap
        using (var bitmap = new Bitmap("Chicago.jpg"))
        {
            graphics.DrawImage(bitmap, 100f, 100f);
        }

        // Draw rectangle
        graphics.DrawRectangle(new Pen(RgbColor.Gray, 4f), 50f, 50f, 700f, 550f);

        // Draw text
        var font = graphics.CreateFont("Arial", 56f);
        var text = new PlainText("Confidential", font, new SolidBrush(RgbColor.OrangeRed), 400f, 340f, TextAlignment.Center);

        graphics.DrawText(text);
    }
}
```

## Explanation

Below is a C# code sample that demonstrates how to save both raster (bitmap) and vector graphics (rectangle and text) to a PDF file, with file size reduction using JPEG compression:

This code creates a PDF document with both raster and vector elements. It draws a bitmap image, a rectangle, and some text, applying compression to reduce the output file size.

## Tags

- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [PDF](<https://www.graphicsmill.com/samples/tags/pdf_md>): Importing and exporting PDF documents
- [Text](<https://www.graphicsmill.com/samples/tags/text_md>): Rendering and formatting text
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Input

- [Chicago.jpg](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Chicago_jpg>) (preview)

## Output

- [WriteRasterAndVectorGraphicsToPdf.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/WriteRasterAndVectorGraphicsToPdf_pdf>) (download)
- [WriteRasterAndVectorGraphicsToPdf.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/WriteRasterAndVectorGraphicsToPdf_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.CompressionType](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_CompressionType.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.AddPage(Single,Single,Color)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_AddPage_3_edd08af9.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.Compression](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_PdfWriter_Compression.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.Quality](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_PdfWriter_Quality.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_CreateFont_2_1dbfa9fa.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawImage(Bitmap,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage_3_b9413d4f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawRectangle(Pen,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawRectangle_5_b3708ac1.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Pen.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_PlainText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TextAlignment](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_TextAlignment.htm.md>)
