Click here to Skip to main content
15,885,767 members
Home / Discussions / C#
   

C#

 
AnswerRe: Using a proxy server in c# Pin
Bernhard Hiller23-Jul-14 20:23
Bernhard Hiller23-Jul-14 20:23 
GeneralRe: Using a proxy server in c# Pin
Member 1052179324-Jul-14 0:53
Member 1052179324-Jul-14 0:53 
GeneralRe: Using a proxy server in c# Pin
Bernhard Hiller24-Jul-14 2:58
Bernhard Hiller24-Jul-14 2:58 
QuestionKurti dev to uni code and uni code yo kurti dev convert by script Pin
Member 1096585923-Jul-14 1:36
Member 1096585923-Jul-14 1:36 
AnswerRe: Kurti dev to uni code and uni code yo kurti dev convert by script Pin
thatraja23-Jul-14 1:57
professionalthatraja23-Jul-14 1:57 
GeneralRe: Kurti dev to uni code and uni code yo kurti dev convert by script Pin
Member 1096585923-Jul-14 2:03
Member 1096585923-Jul-14 2:03 
GeneralRe: Kurti dev to uni code and uni code yo kurti dev convert by script Pin
thatraja23-Jul-14 21:07
professionalthatraja23-Jul-14 21:07 
QuestioniTextSharp PDF Overlay Pin
michPla1223-Jul-14 1:16
michPla1223-Jul-14 1:16 
Hello,

I am asking myself for a couple of hours how I can work around the following problem.

It seems that I need to create my PDF by using "Document" instead of PdfStamper to get the size and rotation. But there are two problems I have with this.
- The Opacity seems not to work (Docu //Overlay Transperency)
- I can't figure out how I can decide if the overlay is in background or foreground.
With
C#
PdfContentByte cb1 = outputWriter.DirectContent;
it seems always to be in the foreground. I can also create the PdfContentByte with
C#
PdfContentByte cb1 = outputWriter.DirectContentUnder;

but I can't figure out how I can do something like this ...
C#
if (<condition>)
  PdfContentByte cb1 = outputWriter.DirectContentUnder;
else
  PdfContentByte cb1 = outputWriter.DirectContent; 



This is my code.

C#
string TempFileName = "";

TempFileName = Path.GetTempFileName();

FilePdfReader = new PdfReader(FileMemoryStream);
Document inputDoc = new Document(FilePdfReader.GetPageSizeWithRotation(1));





using (FileStream fs = new FileStream(TempFileName, FileMode.Create))
{
    //Create the PDF Writer to create the new PDF Document
    PdfWriter outputWriter = PdfWriter.GetInstance(inputDoc,fs);

    inputDoc.Open();


    //Create the Content Byte to stamp to the writer
    PdfContentByte cb1 = outputWriter.DirectContent;

    //Get the PDF document to use as overlay
    PdfReader overlayReader = new PdfReader(OverlayMemoryStream);
    PdfImportedPage overLay = outputWriter.GetImportedPage(overlayReader, 1);

    PdfGState GState = new PdfGState();

    //Get the overlay page rotation
    int overlayRotation = overlayReader.GetPageRotation(1);

    int n = FilePdfReader.NumberOfPages;

    int i = 1;
    while (i <= n)
    {
        //Make sure the new page's page size macthes the original document
        inputDoc.SetPageSize(FilePdfReader.GetPageSizeWithRotation(i));
        inputDoc.NewPage();


        PdfImportedPage page = outputWriter.GetImportedPage(FilePdfReader, i);
        int rotation = FilePdfReader.GetPageRotation(i);


        //Overlay Transperency
        if ( (OverlayFillOpacity != 0f) || (OverlayStrokeOpacity != 0f) )
        {
            GState.FillOpacity = OverlayFillOpacity;
            GState.StrokeOpacity = OverlayStrokeOpacity;

            cb1.SaveState();
            cb1.SetGState(GState);
        }


        //Insert the overlay with correct rotation
        if (overlayRotation == 90 || overlayRotation == 270)
        {
            cb1.AddTemplate(overLay, 0, -1f, 1f, 0, 0,
                FilePdfReader.GetPageSizeWithRotation(i).Height);
        }
        else
        {
            cb1.AddTemplate(overLay, 1f, 0, 0, 1f, 0, 0);
        }

        //Insert the original PDF page with correct rotation
        if (rotation == 90 || rotation == 270)
        {
            cb1.AddTemplate(page, 0, -1f, 1f, 0, 0,
                FilePdfReader.GetPageSizeWithRotation(i).Height);
        }
        else
        {
            cb1.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }

        //Increment the page
        i++;
    }

    //Close the input file
    inputDoc.Close();
    //Close the reader for the overlay file
    overlayReader.Close();

Questionadd multiple passengers Pin
Jassim Rahma22-Jul-14 11:41
Jassim Rahma22-Jul-14 11:41 
GeneralRe: add multiple passengers Pin
PIEBALDconsult22-Jul-14 18:58
mvePIEBALDconsult22-Jul-14 18:58 
AnswerRe: add multiple passengers Pin
OriginalGriff22-Jul-14 19:47
mveOriginalGriff22-Jul-14 19:47 
QuestionHELP Pin
Member 1094467922-Jul-14 3:20
Member 1094467922-Jul-14 3:20 
AnswerRe: HELP Pin
Ravi Bhavnani22-Jul-14 3:57
professionalRavi Bhavnani22-Jul-14 3:57 
GeneralRe: HELP Pin
Member 1094467922-Jul-14 4:07
Member 1094467922-Jul-14 4:07 
GeneralRe: HELP Pin
Ravi Bhavnani22-Jul-14 4:16
professionalRavi Bhavnani22-Jul-14 4:16 
AnswerRe: HELP Pin
Ron Nicholson22-Jul-14 4:08
professionalRon Nicholson22-Jul-14 4:08 
GeneralRe: HELP Pin
Richard MacCutchan22-Jul-14 5:04
mveRichard MacCutchan22-Jul-14 5:04 
GeneralRe: HELP Pin
OriginalGriff22-Jul-14 6:19
mveOriginalGriff22-Jul-14 6:19 
AnswerRe: HELP Pin
Rob Philpott22-Jul-14 5:25
Rob Philpott22-Jul-14 5:25 
GeneralRe: HELP Pin
Eddy Vluggen22-Jul-14 5:53
professionalEddy Vluggen22-Jul-14 5:53 
Questionbitmap lockbits/unlockbits Pin
V.22-Jul-14 2:48
professionalV.22-Jul-14 2:48 
AnswerRe: bitmap lockbits/unlockbits Pin
Rob Philpott22-Jul-14 3:12
Rob Philpott22-Jul-14 3:12 
GeneralRe: bitmap lockbits/unlockbits Pin
V.22-Jul-14 3:32
professionalV.22-Jul-14 3:32 
AnswerRe: bitmap lockbits/unlockbits Pin
Kornfeld Eliyahu Peter22-Jul-14 3:45
professionalKornfeld Eliyahu Peter22-Jul-14 3:45 
GeneralRe: bitmap lockbits/unlockbits Pin
V.22-Jul-14 22:29
professionalV.22-Jul-14 22:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.