We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Make PDF Read-Only when saving Word Doc to PDF

Is it possible to make the PDF read-only when saving it from Word to PDF?

And taking this even further is it possible to make it so you can’t event copy the text in the PDF document?

Thanks,
Adam

Hi Adam,

Thanks for your inquiry.

You can achieve this using Aspose.Pdf.Kit. You can first save the document as PDF into a MemoryStream and load that into Pdf.Kit and set document privileges using that. Please see here for details.

Thanks,

Thanks!

One more question - How can I make it so that when the PDF is created from the word document that text like "http://www.Aspose.com" is just text and isnt automatically converted into a hyperlink in the PDF.

Thanks,
Adam

Hi

Thanks for your inquiry. I think information provided in the following thread could be useful for you in case of converting hyperlink to text:
https://docs.aspose.com/words/net/updating-and-removing-a-field/

Hope this helps.

Best regards,

Link is not working for me??

Hi

Thanks for your inquiry. Sorry for inconvenience. Please try using the following code:

var doc = new Document(@"C:\Temp\yourDoc.doc");
var unlinkHyperlink = new UnlinkHyperlink();
doc.Accept(unlinkHyperlink);
doc.Save(@"C:\Temp\out.doc");
class UnlinkHyperlink : DocumentVisitor
{
    /// 
    /// Called when a FieldStart node is encountered in the document.
    /// 
    public override VisitorAction VisitFieldStart(FieldStart fieldStart)
    {
        //If current field start is start of HYPERLINK fields we should remove them
        if (fieldStart.FieldType == FieldType.FieldHyperlink)
        {
            //Set flag that indicates that following runs are field code and need to be removed
            mIsFieldCode = true;
            fieldStart.Remove();
        }
        return VisitorAction.Continue;
    }

    /// 
    /// Called when a FieldSeparator node is encountered in the document.
    /// 
    public override VisitorAction VisitFieldSeparator(FieldSeparator fieldSeparator)
    {
        //If current field Separator is Separator of HYPERLINK fields we should remove them
        if (fieldSeparator.FieldType == FieldType.FieldHyperlink)
        {
            mIsFieldCode = false;
            fieldSeparator.Remove();
        }
        return VisitorAction.Continue;
    }

    /// 
    /// Called when a FieldEnd node is encountered in the document.
    /// 
    public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd)
    {
        //If current field End is End of HYPERLINK fields we should remove them
        if (fieldEnd.FieldType == FieldType.FieldHyperlink)
        {
            mIsFieldCode = false;
            fieldEnd.Remove();
        }
        return VisitorAction.Continue;
    }

    /// 
    /// Called when a Run node is encountered in the document.
    /// 
    public override VisitorAction VisitRun(Run run)
    {
        if (run.Font.StyleIdentifier == StyleIdentifier.Hyperlink)
        {
            run.Font.StyleName = run.Font.Style.BaseStyleName;
            RestoreFormating(run);
        }
        if (mIsFieldCode)
        {
            mFieldCodeFont = run.Font;
            run.Remove();
        }
        return VisitorAction.Continue;
    }

    private void RestoreFormating(Run run)
    {
        run.Font.Color = mFieldCodeFont.Color;
        run.Font.Underline = mFieldCodeFont.Underline;
    }

    private bool mIsFieldCode = false;
    private Font mFieldCodeFont;
}

Best regards,

I thnk you misunderstood what I am trying to do.

In the word document I have just text. It is not a hyperlink in the word document.

But since it starts with "http://www." when I save the word document as a PDF that conversion process automatically converts the text into a hyperlink in the final PDF produced.

Is there anyway I can avoid that?

Thanks,
Adam

Hi Adam,

Thanks for your inquiry.

Aspose.Words should not convert any URL looking text into an hyperlink. Can you test if this is happening without the post processing using Aspose.Pdf.Kit as most likely the issue is coming from there.

Thanks,

you can do a simple test. - Create a word document with the following text:
http://www.ThisIsATest.com

Then run the following code:

Document Template = new Document("C:\Temp\temp.doc");
Template.Save("C:\Temp\temp.pdf", SaveFormat.Pdf);

Even though it is just text in the word document itself, this process converts it into a Hyperlink in the produced PDF.

Adam

So yes it is in the PDF save process, if I just saved the word document it would be fine still in the word document.

So back to the original question is there anything I can do to stop this?

Maybe *** see through text box over the text?? Any suggestions??

Hi Adam,

Thanks for this additional information.

I was able to reproduce the behavour you were talking about. This doesn’t appear to be any issue with Aspose.Words. The same thing happens when saving as PDF using MS Word.

The reason for this is most likely because of an option in preferences, under the general tab. The checkbox “Create links from URL” or “Automatically detect URLs from text” in earlier versions needs to be unchecked.

Thanks,

thanks.

The problem this is good in some cases but just not in all.

Can you think of any hacks I could use to make it so it doesn’t always happen…I’m thinking something with layers - like throwing a text box over the text that I don’t want to be hyperlinks…any thoughts??

Hi Adam,

I have done a few quick tests. It appears the detection of the URL links by the application is pretty robust so it is hard to avoid it. Inserting shapes and hidden text don’t affect it so I can only suggest to insert one or two characters of garbage text inbetween the www and make the size of the text very small. Of course this is not an optomial solution because if the link is copied and pasted this text will most likely appear with it.

If you are able to find any appropriate work around please post it here.

Thanks,

The best solution I found was to do this.

Throughout the link put in blank spaces between like "http://" "www." etc.

Then make those blank spaces have a font size of 1 - so basically you can’t even tell they are there.

That did the trick!!

Adam

Hi Adam,

Thanks for sharing your work around with us. It may be useful to another customer sometime in the future.

Thanks,